-
[OPIK-6993] [BE] Capture Claude Agent SDK / Claude Code content in Opik OTEL traces (#7319)
发布于
2026-07-09 13:03:07 +00:00 - [OPIK-6993] [BE] Map Claude Code span content into input/output
Claude Code / Claude Agent SDK spans carry content on attributes and a
tool.output event that no mapping rule routed to input/output, so it all
fell into the input attribute-bag. Add ClaudeCodeMappingRules to surface
user_prompt -> input, tool_input -> input, response.model_output -> output,
and map the tool.output span event to the tool span output.Docs: document the minimal env-var set (including the detailed-tracing beta
required for assistant output) that captures full trace visibility in Opik.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Fold duplicated tool.output tests into a parameterized test
Addresses PR review: the output/content tool.output cases only differed by
attribute key and value. Merge into one @ParameterizedTest/@CsvSource.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Reorganize Claude Code span content mapping
Scope the Claude Code rules to the com.anthropic.claude_code.tracing
integration and flip the default bucket for its unmapped attributes from
input to metadata, so input/output/usage carry only real content instead
of a session/config attribute-bag.- session.id -> thread_id (groups interaction turns into one thread)
- input_tokens/output_tokens/cache_* -> usage (was polluting input/output)
- new_context dropped (verbatim duplicate of prompt / tool result)
- user_prompt/tool_input -> input, response.model_output -> output kept
- everything else -> metadata by default
extractUsageField now handles exact-match usage rules (not just prefixes).
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Promote hook and llm request content into span input
The default-to-metadata rule left hook and llm_request spans with near-empty
input. Promote the operation content to input: hook_event/hook_name/
hook_definitions (hook), model/system_prompt_preview (llm; tools already map
to input globally). Identity, timings, ids and counters stay in metadata.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Map new_context to llm_request input (latest LLM message)
On claude_code.llm_request spans, new_context is the latest message fed to
the model - surface it as input. On interaction/tool spans it duplicates the
prompt / tool result, so it stays dropped. Handled span-aware in the mapper.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Keep new_context in metadata instead of dropping it
Never discard span attributes: on non-llm_request spans new_context now goes
to metadata rather than being dropped (still input on llm_request spans).Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Normalize Claude Code cache-token names for cost calc
Claude Code emits cache_read_tokens / cache_creation_tokens, but the Anthropic
cache-cost path in SpanCostCalculator only recognizes cache_read_input_tokens /
cache_creation_input_tokens, so cache pricing was silently skipped. Normalize
the short names to the long ones in USAGE_KEYS_MAPPING.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Map llm response fields (stop_reason, has_tool_call) to output
On claude_code.llm_request spans, stop_reason and response.has_tool_call
describe the model's response, so put them in output alongside
response.model_output. Call identifiers, latency and status stay in metadata.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Address code review: docs, javadoc, test hardening
- docs: clarify assistant output needs the beta (interactive claude is gated;
SDK / claude -p only) and that the beta exporter reuses OTEL_EXPORTER_OTLP_HEADERS - javadoc the new 5-arg enrichSpanWithAttributes overload; move usageKey helper
so extractUsageField's javadoc is attached to it - tests: use OpenTelemetryMappingRuleFactory.CLAUDE_CODE_INSTRUMENTATION instead
of a duplicated literal; tighten .contains to exact-value assertions
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6993] [BE] Fix Claude Code cost/span-type mapping and per-span integration detection
model/provider were routed to Outcome.INPUT/left unset so every Claude Code
span priced at $0 and persisted as SpanType.general; fixed by mapping model
to Outcome.MODEL and setting provider=anthropic directly. Also switched
Claude Code detection from the batch-wide OTEL integration name to a
per-span name check, since a single OTLP batch can mix scopes from more
than one integration and misroute spans either way.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
- fix(otel): drop raw attribute value from unmapped-key debug log
Co-Authored-By: Claude Fable 5 noreply@anthropic.com
下载附件