I pointed Claude Code’s OpenTelemetry tracing at a collector on my laptop, with every content flag off: no prompts, no responses, no tool details. Then I ran one small session and opened the raw export.
My email address was on every span. It wasn’t one resource attribute saying who sent the batch. It was repeated on each span, next to two account IDs. A later session with four model calls put user.email in the export 64 times.
That’s worth knowing before you point this at a shared backend, and it’s fixable in the collector. The traces themselves earn the setup. They showed which single request ate 79% of a 15-cent session, and that the token count you’d reach for first is off by four orders of magnitude.
SkipAlready know this? Jump to The collector configWhat’s on a span by default
Everything here is from Claude Code 2.1.304, run with claude -p on macOS. Tracing is still labelled beta.
With only the flags that turn tracing on, every span carried these attributes:
user.email,user.account_uuidanduser.account_idorganization.id,session.idanduser.idterminal.type
The monitoring docs do say user.email and user.account_uuid “are included when authenticated”. They don’t say it’s on every span. user.id is a random anonymous ID, so that one’s fine.
What wasn’t there is the content. Prompts showed up as <REDACTED>, with only user_prompt_length and response_length left. Content is opt-in, one flag per kind:
| Flag | What it adds |
|---|---|
OTEL_LOG_USER_PROMPTS |
Prompt text |
OTEL_LOG_ASSISTANT_RESPONSES |
Response text (follows the prompts flag when unset) |
OTEL_LOG_TOOL_DETAILS |
Commands, absolute file paths, tool input |
OTEL_LOG_TOOL_CONTENT |
Tool output, as a tool.output span event |
OTEL_LOG_RAW_API_BODIES |
The full conversation history |
One session ran with OTEL_LOG_TOOL_DETAILS=1. It added full_command, file_path, tool_parameters (including the model’s own description of each command) and tool_input. That last one had the contents of a file the agent wrote, "content":"draft", right there on the span. I didn’t test OTEL_LOG_TOOL_CONTENT or the raw-bodies flag.
Two things make this safer than it sounds. A repo’s .claude/settings.json can’t turn telemetry on or choose where it goes; the most it can do is set an exporter to none. And the OTEL_* variables aren’t passed down to Bash, hooks or MCP servers.
A collector that scrubs first
The setup is a collector and Jaeger in Docker, with Tempo added for queries later:
services: jaeger: image: jaegertracing/jaeger:2.11.0 ports: ["16686:16686"] collector: image: otel/opentelemetry-collector-contrib:0.137.0 command: ["--config=/etc/otelcol/config.yaml"] volumes: - ./collector.yaml:/etc/otelcol/config.yaml:ro - ./out:/out ports: ["4317:4317", "4318:4318"] depends_on: [jaeger] tempo: image: grafana/tempo:2.8.2 command: ["-config.file=/etc/tempo.yaml"] volumes: ["./tempo.yaml:/etc/tempo.yaml:ro"] ports: ["3200:3200"]Those are the tested image tags, not the newest ones, and nothing here needs a newer feature.
The collector runs two pipelines off one receiver. The raw one writes to a local file and nowhere else. The shipped one deletes the identity keys, scrubs paths out of free text, and only then exports.
receivers: otlp: protocols: grpc: { endpoint: 0.0.0.0:4317 } http: { endpoint: 0.0.0.0:4318 }processors: batch: {} attributes/redact: actions: - { key: user.email, action: delete } - { key: user.account_uuid, action: delete } - { key: user.account_id, action: delete } - { key: full_command, action: delete } - { key: file_path, action: hash } - { key: tool_parameters, action: delete } - { key: tool_input, action: delete } transform/scrub: trace_statements: - replace_pattern(span.attributes["error"], "/[^ ]+", "<path>") - replace_pattern(span.status.message, "/[^ ]+", "<path>") log_statements: - replace_pattern(log.attributes["error"], "/[^ ]+", "<path>")exporters: otlp/jaeger: endpoint: jaeger:4317 tls: { insecure: true } otlp/tempo: endpoint: tempo:4317 tls: { insecure: true } file/raw: path: /out/raw.jsonl file/redacted: path: /out/redacted.jsonlservice: pipelines: traces/raw: { receivers: [otlp], processors: [batch], exporters: [file/raw] } logs/raw: { receivers: [otlp], processors: [batch], exporters: [file/raw] } metrics/raw: { receivers: [otlp], processors: [batch], exporters: [file/raw] } traces/shipped: { receivers: [otlp], processors: [attributes/redact, transform/scrub, batch], exporters: [otlp/jaeger, otlp/tempo, file/redacted], } logs/shipped: { receivers: [otlp], processors: [attributes/redact, transform/scrub, batch], exporters: [file/redacted], }Hashing file_path instead of deleting it keeps “was this file touched again?” answerable without saying which file. Metrics only go to the raw file here, so that path is untested. If you ship them, add the same processors and check the output yourself.
Then one session with telemetry on:
env CLAUDE_CODE_ENABLE_TELEMETRY=1 CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1 \ OTEL_TRACES_EXPORTER=otlp OTEL_LOGS_EXPORTER=otlp OTEL_METRICS_EXPORTER=otlp \ OTEL_EXPORTER_OTLP_PROTOCOL=grpc OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \ OTEL_METRIC_EXPORT_INTERVAL=5000 \ claude -p "Create a file hello.txt containing 'hi', then run 'ls' and 'cat hello.txt'. Then try running 'curl -s https://example.com'. Report briefly." \ --allowedTools "Write" "Bash(ls:*)" "Bash(cat:*)" --max-turns 8CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1 and OTEL_TRACES_EXPORTER=otlp are what get you spans. OTEL_EXPORTER_OTLP_PROTOCOL has no default, so leave it out and nothing arrives. Jaeger at localhost:16686 then shows a claude-code service with one trace per prompt.
Here’s what the two exports held for that later session, the one with the details flag on:
| Field | Raw file | Shipped file |
|---|---|---|
user.email |
64 | 0 |
user.account_uuid |
64 | 0 |
full_command |
2 | 0 |
tool_parameters |
1 | 0 |
file_path |
4 | 2, as SHA-256 hashes |
The first version of this config didn’t have transform/scrub, and three path strings still got through. A Read on a missing file failed, and with the details flag on, the span’s error attribute and its status message both had the full absolute working directory in them. Deleting keys doesn’t touch free text. Adding the replace_pattern lines took that count to zero. Without the details flag, the same failure’s status message was just TelemetrySafeError.
The config leaves organization.id, session.id and user.id alone. session.id is what ties one session’s spans together, so it stays. If your org ID counts as sensitive, it’s one more delete line. That one’s untested.
Reading one trace
That session took 23.2 seconds and three model calls. Here’s that trace. Open any span to see its attributes, and flip the toggle to see what the collector removes. The identity values are placeholders, you@example.com and a zeroed UUID, not my real ones:
claude_code.interaction23,170 ms
- gen_ai.operation.namesemconv
- invoke_agent
- gen_ai.provider.namesemconv
- anthropic
- user_prompt
- <REDACTED>
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
claude_code.llm_request10,291 ms
- gen_ai.request.modelsemconv
- claude-opus-5-5[1m]
- gen_ai.systemsemconv
- anthropic
- input_tokens
- 2
- output_tokens
- 101
- cache_read_tokens
- 9209
- cache_creation_tokens
- 14095
- ttft_ms
- 3069
- stop_reason
- tool_use
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
claude_code.tool2,289 ms
- gen_ai.operation.namesemconv
- execute_tool
- gen_ai.tool.namesemconv
- Bash
- bash_argv0
- echo
- bash_command_class
- shell_builtin
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
tool.blocked_on_user900 ms
- decision
- accept
- source
- config
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
tool.execution1,386 ms
- success
- true
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
claude_code.llm_request3,255 ms
- cache_read_tokens
- 23304
- cache_creation_tokens
- 138
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
claude_code.tool1,034 ms
- gen_ai.operation.namesemconv
- execute_tool
- gen_ai.tool.namesemconv
- Bash
- bash_argv0
- curl
- bash_command_class
- network
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
tool.blocked_on_user303 ms
- decision
- accept
- source
- config
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
tool.execution725 ms
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
claude_code.llm_request5,525 ms
- cache_read_tokens
- 23442
- cache_creation_tokens
- 1881
- stop_reason
- end_turn
- user.email
- you@example.comdeleted
- user.account_uuid
- 00000000-0000-…deleted
Four things stood out.
The first call pays for the cache. It wrote 14,095 tokens to the prompt cache, and it cost $0.117 of the session’s $0.147, 79%. The two calls after it mostly read that cache back. Every write was a 1-hour cache write (cache_creation_1h_tokens on the log event). If you’re measuring what agent sessions cost, that first cache write is where to look.
input_tokens was 2. On every call. The first one clearly sent over 23,000 tokens of prompt, but Anthropic’s input_tokens counts only the uncached part. Sum input_tokens as “prompt size” and you’re off by four orders of magnitude. The real input is input_tokens + cache_read_tokens + cache_creation_tokens, which is exactly the correction the GenAI Anthropic conventions spell out.
One tool span isn’t one step. I asked for four things. The model did them in one Bash call, which is why the first tool span says bash_argv0=echo and not ls or cat. If you want a tidy demo trace, ask for separate tool calls.
blocked_on_user isn’t a person. Both tools were allowed by config, and still spent 900 ms and 303 ms in tool.blocked_on_user. I couldn’t confirm what that time measures, so don’t read it as the agent waiting on you.
GenAI attributes on Claude Code’s own spans
The OpenTelemetry GenAI conventions moved. The old opentelemetry.io/docs/specs/semconv/gen-ai/ pages now only say so. The conventions live in semantic-conventions-genai, which had no tagged release when I read it at commit 547934a (October 18, 2026). Every GenAI document there is Status: Development. None of these names are stable yet.
Claude Code 2.1.300 added “OpenTelemetry GenAI semantic-convention attributes to trace spans”. That’s accurate, and it’s narrower than “Claude Code emits GenAI spans”. The spans keep their own claude_code.* names, and some GenAI attributes ride along on them:
| The spec says | Claude Code sends |
|---|---|
Agent span named invoke_agent |
claude_code.interaction, with gen_ai.operation.name=invoke_agent |
Inference span named chat {model}, kind CLIENT |
claude_code.llm_request, kind INTERNAL, no gen_ai.operation.name |
Tool span named execute_tool {tool} |
claude_code.tool, with gen_ai.operation.name=execute_tool |
gen_ai.usage.input_tokens (cache included) |
input_tokens (cache excluded), cache_read_tokens, cache_creation_tokens |
gen_ai.provider.name |
Sent, along with gen_ai.system, which the spec has removed |
Also present: gen_ai.conversation.id, gen_ai.tool.name, gen_ai.tool.call.id, gen_ai.request.model, gen_ai.response.id, gen_ai.response.finish_reasons and error.type. Every span came through as INTERNAL.
The attributes are the part that matters. Backends that understand GenAI telemetry tend to key on gen_ai.operation.name and friends, not span names, so a tool that groups by those will make sense of the agent and tool spans and less of the model calls. With the whole spec still in Development, treat any mismatch as a moving target, not a bug.
One thing only the CLI can do: the conventions repo has its own scenario for the Claude Agent SDK, and its README says execute_tool happens inside the CLI subprocess, where a wrapper can’t observe it. If you want tool spans, they have to come from Claude Code itself.
What you can ask it
The shipped pipeline also feeds Tempo 2.8.2, and these TraceQL queries worked against it:
# every tool call that failed{ span.error.type != nil } | select(span.error.type, status)
# every tool call that was denied{ span.decision = "reject" } | select(span.source)
# slowest tools{ span.gen_ai.operation.name = "execute_tool" } | select(span.gen_ai.tool.name, span.bash_argv0)
# model calls that wrote a lot of cache{ name = "claude_code.llm_request" && span.cache_creation_tokens > 5000 }The token attributes are real integers, so numeric comparisons work. Two kinds of query didn’t. Direct-child queries with > mostly came back empty, so I stuck to plain span filters and >> from the root span. And TraceQL metrics like quantile_over_time need Tempo’s metrics-generator, which the config above doesn’t turn on, so those are untested.
For the first two queries, I ran a second session with --permission-mode default, a Read on a missing file and a rm that wasn’t allowed. The failed Read set error.type=tool_error and an ERROR status on its execution span. The denied rm set no error at all:
claude_code.tool gen_ai.tool.name=Bash bash_argv0=rm bash_command_class=fs_mutation└─ tool.blocked_on_user decision=reject source=configNo tool.execution child, no error.type, no error status. The tool never ran, so nothing failed.
The span only says decision and source. My default permission mode is auto, and in the first session curl ran because auto mode’s classifier allowed it. The span said decision=accept source=config. The tool_decision log event said more: classifier_verdict=allow and permission_mode=auto. Those two fields arrived in 2.1.301 and exist only on the log event.
Cost lives in logs and metrics
No span has a dollar amount on it. Cost is on the api_request log event as cost_usd, and in the claude_code.cost.usage metric. So “what did this task cost” isn’t a trace query in Jaeger or Tempo. I summed cost_usd from the collector’s file export, grouped by prompt.id:
run 1 3 requests $0.1467run 2 4 requests $0.1633run 4 4 requests $0.1610In a real setup you’d chart the metric in Prometheus or query the log events in something like Loki. I didn’t test either.
If you do join logs and metrics, check the labels first. For the same calls, the metric said query_source: main and the event said query_source: sdk. The metric’s model was claude-opus-5-5[1m] and the event’s was claude-opus-5-5. A dashboard that joins on model name will quietly drop rows.
What I didn’t get to
Subagent spans, claude_code.hook spans, interactive sessions (everything here was claude -p) and retries. Every model call I saw was attempt 1. Context propagation and sampling belong in the observability part of my System Design series, which is still coming.
If you’re rolling this out to a team, the order I’d go in: run the collector with the scrub pipeline before anyone turns tracing on, keep the raw file on the machine that made it, and diff the raw and shipped exports once by hand. Count user.email in both.
The trace told me where my 15 cents went. It also told anyone with backend access who I was. Now the collector deletes that part first.

