[BUG] Claude Code OTel spans should emit standard gen_ai.usage.* token attributes
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Follow-up to #50776, which was closed as stale/not planned. The closing bot comment says to open a new issue if the problem is still relevant.
Summary
Claude Code telemetry currently emits token usage on claude_code.llm_request spans using flat, non-standard attributes such as:
input_tokensoutput_tokenscache_read_tokenscache_creation_tokens
But OpenTelemetry GenAI semantic conventions expect usage data under the standard gen_ai.usage.* namespace, for example:
gen_ai.usage.input_tokensgen_ai.usage.output_tokens- cached-token fields according to the current GenAI/Anthropic semantic convention guidance
The original issue reported that downstream OTel-native observability tools such as Langfuse, Datadog, and Honeycomb render zero tokens/cost for Claude Code spans because they read the standard attributes and do not recognize the flat Claude Code-specific keys.
What Should Happen?
Requested change
Please emit the standard OpenTelemetry GenAI usage attributes alongside the existing flat attributes, so the change is additive and backwards-compatible:
gen_ai.usage.input_tokensgen_ai.usage.output_tokens- appropriate cached-token attributes according to the current OTel GenAI semantic conventions
Keeping the current input_tokens, output_tokens, and cache_*_tokens fields in parallel would avoid breaking existing consumers.
Error Messages/Logs
Steps to Reproduce
Using the settings.json
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "none",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317",
"OTEL_METRIC_EXPORT_INTERVAL": "5000",
"OTEL_LOGS_EXPORT_INTERVAL": "5000",
"CLAUDE_CODE_ENHANCED_TELEMETRY_BETA": "1",
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_LOG_TOOL_DETAILS": "1",
"OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "delta",
"OTEL_RESOURCE_ATTRIBUTES": "service.name=claude-code",
"OTEL_METRICS_INCLUDE_VERSION": "true",
"OTEL_METRICS_INCLUDE_ENTRYPOINT": "true",
"OTEL_LOG_LEVEL": "debug"
}
}
Claude Model
None
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
Claude 1.11187.4 (584005) 2026-06-05T20:15:04.000Z
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
Reference
Original issue: #50776
Related comment in the original issue:
https://github.com/anthropics/claude-code/issues/50776#issuecomment-4276300754
The stale close comment:
https://github.com/anthropics/claude-code/issues/50776#issuecomment-4554065190
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗