Skip to content
Beta
All articles

Claude Code's request spans adopt GenAI attributes: check token totals first

Claude Code 2.1.331 adds OpenTelemetry GenAI usage attributes to its request spans. Its new input token count includes cache tokens; its old one doesn't.

By The SpanDock team

4 min read

A diagram of one Claude Code request span carrying two input token counts: the older input_tokens attribute counts only uncached input, while the new gen_ai.usage.input_tokens also includes tokens read from and written to the prompt cache

Claude Code 2.1.331, released on 23 November 2026, adds OpenTelemetry's standard GenAI usage attributes to the trace span it records for every model request. That makes Claude Code traces easier to read in tools built around the GenAI conventions. It also puts two input token counts with different meanings on the same span. If you build cost or usage dashboards from Claude Code traces, check which one each panel sums before the new attributes reach your fleet.

What changed

The Claude Code changelog entry for 2.1.331 says it "Added gen_ai.usage.*, gen_ai.response.model and gen_ai.operation.name to claude_code.llm_request trace spans; gen_ai.usage.input_tokens includes prompt cache tokens".

Some context on the span. Claude Code's tracing is a beta feature and is off by default. The monitoring documentation says to enable it with CLAUDE_CODE_ENABLE_TELEMETRY=1 and CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1, and to choose an exporter with OTEL_TRACES_EXPORTER. Each prompt starts a claude_code.interaction span; each model request is a claude_code.llm_request span beneath it, and subagents' requests nest under the tool span that started them.

That request span already carried Claude Code's own token attributes. The documentation defines input_tokens as the input count from the API usage block, which "Excludes tokens read from or written to the prompt cache", with those reported separately in cache_read_tokens and cache_creation_tokens. It also already carried a few GenAI-convention names, such as gen_ai.system, gen_ai.request.model and gen_ai.response.id.

Two input counts on one span

The OpenTelemetry convention defines input tokens the other way round. In the GenAI attribute registry, gen_ai.usage.input_tokens "SHOULD include cached tokens and input tokens of all modalities", and the cache read and cache write counts "SHOULD be included" in it. Claude Code's changelog says it follows that rule.

So, for a single request, expect:

  • input_tokens: uncached input only.
  • gen_ai.usage.input_tokens: uncached input plus cache reads plus cache writes.

For a coding agent, which resends a long conversation on almost every turn, the difference can be large. When the cache is warm, much of a turn's input is read from it, so the GenAI figure can be several times the older one. Neither is wrong. They answer different questions: the older attribute is close to the uncached input you pay the full rate for, while the GenAI total is the size of the input the model processed.

Three ways this goes wrong in practice:

  • Double counting. A panel that adds input_tokens and cache_read_tokens is correct. The same panel switched to gen_ai.usage.input_tokens and still adding cache reads counts them twice.
  • Wrong prices. Cache reads are priced well below uncached input. Multiplying the GenAI total by the uncached input price overstates cost. We covered how much caching moves a bill in prompt caching and AI coding costs.
  • Mixed versions. Computers on 2.1.330 or earlier don't send the new attributes. A dashboard built on them will show gaps, or lower totals, until every computer has updated.

What the documentation doesn't say yet

As of 24 November, the monitoring page's attribute table for claude_code.llm_request doesn't list the new attributes; the changelog is the only description. It doesn't name the individual gen_ai.usage.* attributes, and that matters because the conventions themselves just changed.

On 21 November the GenAI conventions had their first standalone release, v0.1.0, after moving out of OpenTelemetry's main semantic conventions repository. Among its breaking changes, it renames gen_ai.usage.cache_creation.input_tokens to gen_ai.usage.cache_write.input_tokens. Until the documentation lists the attribute names, check which cache write name your traces carry before you query for it. The span's existing gen_ai.system attribute is also the older name: OpenTelemetry's main registry marks it deprecated in favour of gen_ai.provider.name.

The GenAI attributes in the v0.1.0 registry are still marked "Development", not stable. Expect more renames. Our earlier piece on October's GenAI metric changes describes how quickly these conventions have been moving.

What it means for engineering and security leaders

Standard attribute names are good news for anyone running more than one AI tool. A dashboard that sums gen_ai.usage.input_tokens across tools only means something if every tool counts the same way, and the convention now says clearly that the total includes cached tokens. Claude Code moving to it makes cross-tool comparisons more honest.

The cost is a transition period. For a while your traces will carry two vocabularies, from computers on different versions, against a convention still in development. Treat token dashboards as code: write down which attribute each panel uses and what it includes, and review them when a tool or the conventions change. For totals, OpenTelemetry's own advice is to prefer metrics to summed span attributes: the conventions' token metrics page notes that metrics "aren't affected by trace sampling".

Practical takeaways

  • List every query that reads input_tokens or gen_ai.usage.input_tokens from Claude Code spans, and note which it is.
  • Never add cache counts to gen_ai.usage.input_tokens; they are already inside it.
  • Price cache reads, cache writes and uncached input separately, using the separate attributes.
  • Check one real span from 2.1.331 for the exact cache attribute names before you build on them.
  • Pin or track versions so you know which computers send which attributes, and expect gaps until the fleet is on 2.1.331 or later.

SpanDock receives OpenTelemetry from Claude Code and other tools and forwards it to the destinations you add with the original bytes the tool sent, keeping a copy in its local store for the dashboard. Your backend therefore sees the same attributes Claude Code emitted, both token counts included, so the checks above still apply there. Forwarding to more than one destination is on the Standard plan and above.

Sources

  1. Claude Code changelog: 2.1.331
  2. Claude Code release v2.1.331 on GitHub (23 November 2026)
  3. Claude Code documentation: Monitoring (traces, span attributes)
  4. OpenTelemetry GenAI semantic conventions v0.1.0 release (21 November 2026)
  5. OpenTelemetry GenAI semantic conventions v0.1.0: gen_ai attribute registry
  6. OpenTelemetry GenAI semantic conventions v0.1.0: token metrics
  7. OpenTelemetry semantic conventions v1.45.0: deprecated gen_ai attributes
Cookie categories

Details: Cookie Policy.