Skip to content

feat(telemetry): emit gen_ai.usage.cached_tokens across all providers#1497

Merged
joshua-mo-143 merged 1 commit into0xPlaygrounds:mainfrom
alwayys-afk:feat/cached-tokens-telemetry
Mar 16, 2026
Merged

feat(telemetry): emit gen_ai.usage.cached_tokens across all providers#1497
joshua-mo-143 merged 1 commit into0xPlaygrounds:mainfrom
alwayys-afk:feat/cached-tokens-telemetry

Conversation

@alwayys-afk
Copy link
Contributor

@alwayys-afk alwayys-afk commented Mar 10, 2026

Summary

  • Adds gen_ai.usage.cached_tokens to tracing spans across all providers and agent-level spans
  • Updates record_token_usage in SpanCombinator to automatically emit cached_input_tokens for providers using the telemetry trait
  • Manually records cached tokens in providers that record usage directly on spans (OpenAI, DeepSeek, Groq, xAI)

Cached input tokens are billed at reduced rates (typically 50-90% cheaper) and processed faster. Emitting them in telemetry spans enables accurate cost tracking, cache hit rate monitoring, and latency correlation.

This PR was generated with assistance from Claude.

Test plan

  • cargo check -p rig-core passes
  • cargo clippy -p rig-core --all-targets --all-features passes
  • cargo fmt -- --check passes

Cached input tokens are billed at reduced rates and processed faster,
but this data was not being surfaced in telemetry spans. This adds
gen_ai.usage.cached_tokens to every provider's tracing spans for
cost tracking and cache hit rate observability.

- Update record_token_usage in SpanCombinator to emit cached_input_tokens
- Add gen_ai.usage.cached_tokens field to all span declarations
- Record cached tokens in manual recording sites (OpenAI, DeepSeek, Groq, xAI)
- Record cached tokens in agent-level spans (prompt_request)
@joshua-mo-143
Copy link
Collaborator

This seems mostly ready? I think? Are there any blockers here? @alwayys-afk

@alwayys-afk alwayys-afk marked this pull request as ready for review March 11, 2026 13:15
@alwayys-afk
Copy link
Contributor Author

Yeah should be good

Copy link
Collaborator

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Mar 16, 2026
Merged via the queue into 0xPlaygrounds:main with commit 165cce6 Mar 16, 2026
6 checks passed
@github-actions github-actions bot mentioned this pull request Mar 16, 2026
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.

2 participants