[BUG] Claude Code OTel spans should emit standard gen_ai.usage.* token attributes

Status Open
Maintainer reply None cached
Activity 6 comments · opened Jun 16, 2026

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_tokens
  • output_tokens
  • cache_read_tokens
  • cache_creation_tokens

But OpenTelemetry GenAI semantic conventions expect usage data under the standard gen_ai.usage.* namespace, for example:

  • gen_ai.usage.input_tokens
  • gen_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_tokens
  • gen_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

View original on GitHub ↗

5 Comments

github-actions[bot] · 2 months ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/50776

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

tk · 2 months ago

As it stated in the original issue, the problem is still persisting and it should be fixed. So this is the ticket for it.

Necmttn · 2 months ago

A migration window can avoid breaking existing dashboards while aligning with semantic conventions.

Dual-emit the current flat token fields and gen_ai.usage.* attributes for one release window, then document collector transforms for both. That gives Prometheus/OTel users a stable path to standard token accounting without losing current Claude Code panels.

---

_Generated with ax._

oxcafedead · 1 month ago

Is this planned, or will it be auto-closed like several other issues on this matter? Any enterprise-level observability de facto requires proper OTel support, which is, by the way, available in GitHub Copilot but not in Claude currently.

Showing cached comments. Read the full discussion on GitHub ↗