# My agent's traces had my email on every span

- Published: 2026-11-02
- Updated: 2026-11-26
- Tags: AI Agents, Observability, Tooling
- URL: https://devtrillo.com/writing/tracing-claude-code-with-otel/

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](/writing/tracer-bullets-with-llms/) 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.

_Already know this? Jump to [The collector config](https://devtrillo.com/writing/tracing-claude-code-with-otel/#a-collector-that-scrubs-first)._

## What'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_uuid` and `user.account_id`
- `organization.id`, `session.id` and `user.id`
- `terminal.type`

The [monitoring docs](https://code.claude.com/docs/en/monitoring-usage) 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:

```yaml title="compose.yaml"
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.

**One receiver, two pipelines.** Claude Code sends OTLP to the collector's one receiver. From there the traces split. The raw pipeline only batches them and writes raw.jsonl, which stays on the laptop with user.email intact. The shipped pipeline runs the redact and scrub processors first, then exports to Jaeger, Tempo and redacted.jsonl.

```yaml title="collector.yaml"
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.jsonl
service:
  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:

```sh title="one traced session"
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 8
```

`CLAUDE_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 trace: one interaction, three model calls, two Bash tool calls** (23,170 ms in total). Each span, nested under its parent, with its start offset and attributes (keys from the GenAI semantic conventions are marked *semconv*):

- `claude_code.interaction`: 23,170 ms, starting at 0 ms. `gen_ai.operation.name` (semconv): invoke_agent; `gen_ai.provider.name` (semconv): anthropic; `user_prompt`: <REDACTED>
  - `claude_code.llm_request`: 10,291 ms, starting at 0 ms. `gen_ai.request.model` (semconv): claude-opus-5-5[1m]; `gen_ai.system` (semconv): anthropic; `input_tokens`: 2; `output_tokens`: 101; `cache_read_tokens`: 9209; `cache_creation_tokens`: 14095; `ttft_ms`: 3069; `stop_reason`: tool_use
  - `claude_code.tool`: 2,289 ms, starting at 10,291 ms. `gen_ai.operation.name` (semconv): execute_tool; `gen_ai.tool.name` (semconv): Bash; `bash_argv0`: echo; `bash_command_class`: shell_builtin
    - `tool.blocked_on_user`: 900 ms, starting at 10,291 ms. `decision`: accept; `source`: config
    - `tool.execution`: 1,386 ms, starting at 11,191 ms. `success`: true
  - `claude_code.llm_request`: 3,255 ms, starting at 12,580 ms. `cache_read_tokens`: 23304; `cache_creation_tokens`: 138
  - `claude_code.tool`: 1,034 ms, starting at 15,835 ms. `gen_ai.operation.name` (semconv): execute_tool; `gen_ai.tool.name` (semconv): Bash; `bash_argv0`: curl; `bash_command_class`: network
    - `tool.blocked_on_user`: 303 ms, starting at 15,835 ms. `decision`: accept; `source`: config
    - `tool.execution`: 725 ms, starting at 16,138 ms.
  - `claude_code.llm_request`: 5,525 ms, starting at 16,869 ms. `cache_read_tokens`: 23442; `cache_creation_tokens`: 1881; `stop_reason`: end_turn

Identity attributes on every span: `user.email` (you@example.com) and `user.account_uuid` (00000000-0000-…), as Claude Code sends them; after the collector, both are deleted.

Durations are from the real trace. Bars are laid end to end, so the small gaps between spans aren't drawn. Identity values are placeholders.

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](/writing/continuous-delivery-6-measuring-cd/) 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](https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/anthropic.md) spell out.

**Quiz:** Your dashboard charts the sum of input_tokens per session to find the sessions with the biggest prompts. A 40-turn session shows up near the bottom. Why?

- Long sessions get their spans truncated at 60 KB
- Most of its prompt was served from the cache, and input_tokens leaves cached tokens out
- Prompt redaction zeroes the count

**Answer:** Most of its prompt was served from the cache, and input_tokens leaves cached tokens out — A long session re-reads its history from the cache every turn, so input_tokens stays tiny. Add cache_read_tokens and cache_creation_tokens.

- Not "Long sessions get their spans truncated at 60 KB": The 60 KB cap is for content strings like prompts. Token counts are integers and aren't capped.
- Not "Prompt redaction zeroes the count": Redaction hides prompt text. The token counters are still there.

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](https://github.com/open-telemetry/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](https://code.claude.com/docs/en/changelog) "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:

```text title="TraceQL"
# 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:

```text title="the denied rm, as spans"
claude_code.tool           gen_ai.tool.name=Bash  bash_argv0=rm  bash_command_class=fs_mutation
└─ tool.blocked_on_user    decision=reject  source=config
```

No `tool.execution` child, no `error.type`, no error status. The tool never ran, so nothing failed.

**Quiz:** Security asks for a weekly list of every tool call your team's agents were not allowed to run. Which query do you hand them?

- { span.error.type != nil }
- { span.decision = "reject" }
- { span.gen_ai.operation.name = "execute_tool" && status = error }

**Answer:** { span.decision = "reject" } — Denials show up as decision=reject on tool.blocked_on_user, and on the tool_decision log event.

- Not "{ span.error.type != nil }": That finds tools that ran and failed. A denied call never runs, so it has no error.type.
- Not "{ span.gen_ai.operation.name = "execute_tool" && status = error }": The parent tool span of the denied rm had no error status either.

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`:

```text title="cost per prompt, from api_request events"
run 1   3 requests   $0.1467
run 2   4 requests   $0.1633
run 4   4 requests   $0.1610
```

In 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.

> **Tip:** Before you trust the scrub, make it fail once. Run a session with
> `OTEL_LOG_TOOL_DETAILS=1` that reads a file that doesn't exist. Then grep the
> shipped export for your home directory, and expect zero hits.

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.
