Skip to content

fix(tracing): Align cache token attributes with Sentry conventions#403

Open
sergical wants to merge 1 commit into
mainfrom
fix/align-cache-token-attributes-with-sentry-conventions
Open

fix(tracing): Align cache token attributes with Sentry conventions#403
sergical wants to merge 1 commit into
mainfrom
fix/align-cache-token-attributes-with-sentry-conventions

Conversation

@sergical
Copy link
Copy Markdown
Member

Summary

  • Renames gen_ai.usage.cache_read.input_tokensgen_ai.usage.input_tokens.cached and gen_ai.usage.cache_creation.input_tokensgen_ai.usage.input_tokens.cache_write to match the attribute names the Sentry AI Monitoring product reads.
  • Adds gen_ai.usage.total_tokens which the agents traces table queries via sum(gen_ai.usage.total_tokens).
  • Updates tracing spec and semantics map to reflect the Sentry convention names.

Context

Junior was emitting cache token span attributes using the OpenTelemetry spec names (gen_ai.usage.cache_read.input_tokens / gen_ai.usage.cache_creation.input_tokens), but the Sentry product stack reads different attribute names:

  • Sentry backend (EAP attributes.py): gen_ai.usage.input_tokens.cached
  • Sentry frontend (AI Insights): GEN_AI_USAGE_INPUT_TOKENS_CACHED = 'gen_ai.usage.input_tokens.cached'
  • Sentry JS SDK (gen-ai-attributes.ts): GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE = 'gen_ai.usage.input_tokens.cached'

The Sentry JS SDK's Vercel AI integration normalizes attributes to the Sentry convention names, but Junior uses pi-ai's streamSimple directly (bypassing the Vercel AI SDK), so the SDK normalization never runs.

This made cache token data invisible in the AI Monitoring UI — the data was being sent but the product never looked for those attribute names.

Test plan

  • Unit test updated and passing (extract-gen-ai-usage-summary.test.ts)
  • Typecheck passes
  • Verify cache token data appears in Sentry AI Monitoring after deploy

🤖 Generated with Claude Code

The Sentry AI Monitoring product reads `gen_ai.usage.input_tokens.cached`
and `gen_ai.usage.input_tokens.cache_write`, but Junior was emitting the
OTel-style names (`gen_ai.usage.cache_read.input_tokens` and
`gen_ai.usage.cache_creation.input_tokens`). This made cache token data
invisible in the AI Monitoring UI.

Also adds `gen_ai.usage.total_tokens` which the agents traces table uses.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment May 22, 2026 6:45pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant