Skip to content

fix(go-sdk): emit cache and reasoning token counts under the keys Python and the UI read - #1987

Open
basil-k-aji-dev wants to merge 1 commit into
openlit:mainfrom
basil-k-aji-dev:fix/go-usage-cache-reasoning-keys
Open

basil-k-aji-dev wants to merge 1 commit into
openlit:mainfrom
basil-k-aji-dev:fix/go-usage-cache-reasoning-keys

Conversation

@basil-k-aji-dev

@basil-k-aji-dev basil-k-aji-dev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Issue number: Fixes #1984

Change description:

The Go SDK wrote cache and reasoning token counts under attribute names that neither the Python SDK nor the OpenLIT UI read. This adds the names they do read and keeps the legacy keys, so existing consumers are unaffected.

Added to sdk/go/semconv/genai.go (additions only, no existing constant changed):

  • gen_ai.usage.cache_read.input_tokens and gen_ai.usage.cache_creation.input_tokens, the names in the OpenTelemetry GenAI conventions and the Python SDK. Anthropic non-streaming and streaming emit both, OpenAI non-streaming emits the read count.
  • gen_ai.usage.reasoning.output_tokens, gen_ai.usage.reasoning_tokens (already a constant, reused) and gen_ai.usage.completion_tokens_details.reasoning_tokens for OpenAI non-streaming reasoning counts.

Why these keys: the UI reads usage.cache_read.input_tokens, usage.cache_creation.input_tokens and usage.completion_tokens_details.reasoning_tokens (src/client/src/constants/traces.ts), and the span attribute is looked up as the flat key gen_ai.<path>. Nothing under src/ reads a key the Go SDK emitted before.

Things to know when reviewing:

  • The two constants GenAIUsageCacheReadInputTokens and GenAIUsageCacheCreationInputTokens already exist but hold gen_ai.usage.cache.read_input_tokens and gen_ai.usage.cache.creation_input_tokens, which are not the standard names and are used by no instrumentation. I left them alone for API compatibility, so the new ones carry a Key suffix.
  • Scope is non-streaming for OpenAI. openai/streaming.go has no cache or reasoning code, not even the legacy keys; that is a separate change.
  • Reasoning is partial parity with Python: it does not set gen_ai.usage.reasoning.output_tokens.reported or the derived completed-output-tokens attribute. completion_tokens_details.reasoning_tokens goes beyond what Python's OpenAI path emits, because it is the only reasoning key the trace detail view reads.
  • Cache attributes stay inside the existing > 0 guards. Python emits them even when 0, but the Go usage structs use plain int with omitempty, so absent and zero cannot be told apart. The UI shows - for a missing key.
  • cli/internal/coding/hook/cursor/handle.go hard-codes the non-standard gen_ai.usage.cache.read_input_tokens. Out of scope here.

How was this tested

Tests assert the key strings as literals, so on the unmodified source they fail on a missing attribute rather than a missing symbol:

--- FAIL: TestCreateMessage_Streaming_CacheTokenAttributes
    cache_creation.input_tokens: want 1234, got 0
    cache_read.input_tokens: want 5678, got 0
--- FAIL: TestCreateMessage_CacheTokenAttributes
    gen_ai.usage.cache_read.input_tokens: attribute missing
--- FAIL: TestChatCompletion_CacheAndReasoningTokenAttributes
    gen_ai.usage.cache_read.input_tokens: attribute missing
    gen_ai.usage.reasoning.output_tokens: attribute missing
    gen_ai.usage.reasoning_tokens: attribute missing
    gen_ai.usage.completion_tokens_details.reasoning_tokens: attribute missing

They pass with the change. Each emitted attribute was also removed on its own and each removal fails a test (12 mutations, none survived). go vet ./... and go test ./... pass in sdk/go, and cd cli && go build ./... succeeds against the patched module.

gofmt -l lists four files that are already unformatted on main (helpers/config.go, helpers/pricing.go, anthropic/types.go, openai/types.go); this PR does not touch them. -race could not run on the machine I used.

My other Go SDK PRs (#1982, #1983, #1985) touch the same test files, so whichever merges second needs a small rebase. I will do that.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • PR title follows Conventional Commit format.
  • I have reviewed the contributing guidelines
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

Summary by Sourcery

Align Go SDK token usage attributes with the keys consumed by downstream SDK and UI components.

Bug Fixes:

  • Emit cache and reasoning token usage under the attribute names consumed by the Python SDK and OpenLIT UI while preserving the existing legacy attributes.

Enhancements:

  • Add coverage for Anthropic streaming and non-streaming cache usage and OpenAI cache and reasoning usage attributes.

Tests:

  • Add assertions verifying the new cache and reasoning token attributes and their legacy counterparts.

@sourcery-ai

sourcery-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Data structures

Add constants for the standard cache and reasoning token attribute keys while retaining the existing constants for compatibility.

  • sdk/go/semconv/genai.go L135-141

Implementation

Emit both standard and legacy cache token attributes for Anthropic responses in streaming and non-streaming paths.

  • sdk/go/instrumentation/anthropic/instrumentor.go L204-208
  • sdk/go/instrumentation/anthropic/streaming.go L224-228

Emit the standard cache-read and reasoning token attributes alongside the existing OpenAI attributes for non-streaming responses.

  • sdk/go/instrumentation/openai/instrumentor.go L432-434, L444

Tests

Verify the new and legacy cache token attributes on Anthropic streaming and non-streaming spans.

  • sdk/go/instrumentation/anthropic/anthropic_test.go L624-674

Verify standard cache-read and reasoning token attributes alongside the existing OpenAI attributes.

  • sdk/go/instrumentation/openai/openai_test.go L14-17, L669-734

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Emit Go SDK cache and reasoning counts under UI-readable keys

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Emit cache token counts under keys the UI reads for Anthropic and non-streaming OpenAI spans.
• Emit non-streaming OpenAI reasoning counts under standard and UI-readable keys while retaining
 legacy attributes.
• Add span-level tests for the new keys and existing attributes.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • Anthropic non-streaming, Anthropic streaming, and OpenAI response instrumentation all implement the same end-to-end behavior: translating provider usage fields into span attributes consumed by the repository's telemetry UI and downstream telemetry processing.
  • They share one bounded usage-telemetry scope; the provider-specific functions are propagation hops rather than independent user capabilities.
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, the handlers already conditionally copied provider usage fields to legacy span attributes using existing positive-value guards and SetIntAttribute.
  • After, the same branches add direct aliases for the same integer values.
  • The new correctness condition is that each new key must map to the corresponding existing provider field without changing the legacy value or guard behavior.
  • This is a direct field-to-attribute transformation using established infrastructure; it does not introduce new state transitions, ordering, concurrency, algorithms, or materially new compatibility interaction.
Sources

sdk/go/semconv/genai.go[135-140]

const (
	GenAIUsageCacheReadInputTokensKey                = "gen_ai.usage.cache_read.input_tokens"
	GenAIUsageCacheCreationInputTokensKey            = "gen_ai.usage.cache_creation.input_tokens"
	GenAIUsageReasoningOutputTokens                  = "gen_ai.usage.reasoning.output_tokens"
	GenAIUsageCompletionTokensDetailsReasoningTokens = "gen_ai.usage.completion_tokens_details.reasoning_tokens"
)
Potential damage 🟡 Medium 🩹 Incorrect results

  • If activated with an incorrect mapping or value, token usage shown or processed by telemetry consumers can be wrong.
  • The repository's consumer explicitly reads the new cache attribute names and existing reasoning names, so a bad value can take precedence over or alter displayed usage.
  • The impact is limited to observability, usage accounting, and related analytics; no application response, provider request, or business data is changed by these lines.
  • Reverting the code prevents future spans from receiving the faulty new values, and the retained legacy attributes may allow some consumers to fall back for future data.
  • Already-exported spans remain wrong unless the telemetry backend supports deletion, reprocessing, or manual correction; code rollback alone does not repair historical telemetry.
  • There is no automatic repair worker or external compensation path established by the inspected source.
Assessed commit c483ecc
Diagram

graph TD
  A["Anthropic usage"] --> B(["Message paths"]) --> D["Span attributes"] --> E["Trace details"]
  C["OpenAI usage"] --> F(["Completion path"]) --> D
  G["GenAI key constants"] --> B
  G --> F
Loading
High-Level Assessment

The additive, provider-local changes fit this compatibility fix: they expose the keys consumers read without changing legacy constants or attributes. A shared emission helper would add abstraction for a small number of provider-specific paths.

Files changed (6) +136 / -0

Bug fix (4) +15 / -0
instrumentor.goEmit UI-readable cache counts for Anthropic messages +2/-0

Emit UI-readable cache counts for Anthropic messages

• Adds cache creation and cache read attributes to non-streaming response spans alongside the existing attributes, within the existing positive-count guards.

sdk/go/instrumentation/anthropic/instrumentor.go

streaming.goEmit UI-readable cache counts for Anthropic streams +2/-0

Emit UI-readable cache counts for Anthropic streams

• Adds cache creation and cache read attributes when streaming usage is finalized, retaining the legacy attributes and positive-count guards.

sdk/go/instrumentation/anthropic/streaming.go

instrumentor.goExpose OpenAI cache and reasoning counts on completion spans +4/-0

Expose OpenAI cache and reasoning counts on completion spans

• Adds the UI-readable cache read key and three reasoning keys to non-streaming response spans. Existing attributes and positive-count guards remain.

sdk/go/instrumentation/openai/instrumentor.go

genai.goDefine additional cache and reasoning attribute keys +7/-0

Define additional cache and reasoning attribute keys

• Adds constants for UI-readable cache and reasoning keys without changing existing constant values. The already-defined reasoning_tokens constant is reused by the OpenAI instrumentation.

sdk/go/semconv/genai.go

Tests (2) +121 / -0
anthropic_test.goCover Anthropic cache keys in both message paths +51/-0

Cover Anthropic cache keys in both message paths

• Extends the streaming span test and adds a non-streaming test asserting UI-readable cache counts. The non-streaming test also checks that legacy attributes remain.

sdk/go/instrumentation/anthropic/anthropic_test.go

openai_test.goVerify OpenAI usage attributes on recorded spans +70/-0

Verify OpenAI usage attributes on recorded spans

• Adds a mocked chat-completion test that checks the new cache and reasoning keys as literal strings, plus the retained legacy attributes.

sdk/go/instrumentation/openai/openai_test.go

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Streamed OpenAI drops cache read counts 📎 Requirement gap ≡ Correctness
Description
OpenAI’s non-streaming setResponseAttributes records cached prompt and reasoning tokens, but
openai/streaming.go reads lastChunk.Usage only for token totals and cost, setting neither the
cache-read nor reasoning attributes. When a streamed response reports
PromptTokensDetails.CachedTokens or CompletionTokensDetails.ReasoningTokens, its span lacks the
keys read by the trace detail UI, so those counts remain unavailable until streaming support is
added.
Code

sdk/go/instrumentation/openai/instrumentor.go[444]

+				semconv.SetIntAttribute(span, semconv.GenAIUsageCacheReadInputTokensKey, resp.Usage.PromptTokensDetails.CachedTokens)
Evidence
The non-streaming path sets gen_ai.usage.cache_read.input_tokens from
PromptTokensDetails.CachedTokens and reasoning attributes from
CompletionTokensDetails.ReasoningTokens. In contrast, the streaming usage block at streaming.go
lines 182–187 reads lastChunk.Usage for token counts and cost without setting either kind of
attribute, so provider-reported cached or reasoning tokens are absent from streamed spans.

Go SDK emits cache token counts under UI-compatible attributes
sdk/go/instrumentation/openai/streaming.go[182-187]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
OpenAI streaming responses do not record cached prompt tokens or reasoning token counts reported in `lastChunk.Usage`, although the non-streaming path records both. As a result, streamed spans lack the cache-read and reasoning keys used by the trace detail UI.

## Fix Focus Areas
- sdk/go/instrumentation/openai/streaming.go[182-188]
- sdk/go/instrumentation/openai/instrumentor.go[429-435]
- sdk/go/instrumentation/openai/instrumentor.go[441-445]

## Recommended Fix
Inside `if lastChunk.Usage != nil`, check for non-nil `PromptTokensDetails` with `CachedTokens > 0` and set `semconv.GenAIUsageCacheReadInputTokensKey` and the legacy `semconv.GenAIUsagePromptTokensDetailsCacheRead` key. Check for non-nil `CompletionTokensDetails` with `ReasoningTokens > 0` and set the same keys as the non-streaming path: `semconv.GenAIUsageCompletionTokensDetailsReasoningTokens`, `semconv.GenAIUsageReasoningOutputTokens`, `semconv.GenAIUsageReasoningTokens`, and the legacy `semconv.GenAIUsageCompletionTokensDetailsReasoning`. Add streaming tests asserting these attributes are present when the final chunk reports the corresponding counts.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: Auto: ⚖️ Balanced: Behavioral SDK changes span multiple providers and telemetry attribute paths.

Grey Divider

Tip of the day
💡 Did you know, you can route each severity your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@sourcery-ai

sourcery-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit c483ecc

#1984 Bug: Go SDK writes cache and reasoning token counts under attribute names nothing reads · 3 of 3 met

# Requirement Status Notes
1 Emit cache_read.input_tokens and cache_creation.input_tokens for Anthropic cache usage ✅ Met Both streaming and non-streaming instrumentation emit the canonical keys while retaining the legacy attributes.
2 Emit cache_read.input_tokens for OpenAI cached-token usage ✅ Met OpenAI non-streaming instrumentation emits the canonical key alongside the legacy attribute.
3 Emit reasoning tokens under the key the UI reads ✅ Met OpenAI non-streaming instrumentation emits gen_ai.usage.completion_tokens_details.reasoning_tokens and retains the legacy attribute.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="sdk/go/instrumentation/anthropic/instrumentor.go" line_range="204-208" />
<code_context>
 		semconv.SetIntAttribute(span, semconv.GenAIUsageTotalTokens, resp.Usage.InputTokens+resp.Usage.OutputTokens)
 		if resp.Usage.CacheCreationInputTokens > 0 {
 			semconv.SetIntAttribute(span, semconv.GenAIUsagePromptTokensDetailsCacheWrite, resp.Usage.CacheCreationInputTokens)
+			semconv.SetIntAttribute(span, semconv.GenAIUsageCacheCreationInputTokensKey, resp.Usage.CacheCreationInputTokens)
 		}
 		if resp.Usage.CacheReadInputTokens > 0 {
 			semconv.SetIntAttribute(span, semconv.GenAIUsagePromptTokensDetailsCacheRead, resp.Usage.CacheReadInputTokens)
+			semconv.SetIntAttribute(span, semconv.GenAIUsageCacheReadInputTokensKey, resp.Usage.CacheReadInputTokens)
 		}
 	}
</code_context>
<issue_to_address>
**Canonical cache counts remain missing**

When the Anthropic or OpenAI response includes cache-token usage, the new emitters write cache counts under `gen_ai.usage.cache_read.input_tokens` and `gen_ai.usage.cache_creation.input_tokens` rather than the convention’s `gen_ai.usage.cache.read_input_tokens` and `gen_ai.usage.cache.creation_input_tokens`; consumers following the canonical schema do not find these counts.

Emit the cache counts under the convention’s `cache.read_input_tokens` and `cache.creation_input_tokens` keys, while retaining any compatibility aliases only if they do not replace those canonical attributes.

Also at `sdk/go/instrumentation/anthropic/streaming.go:224-228`, `sdk/go/instrumentation/openai/instrumentor.go:444`, `sdk/go/semconv/genai.go:136-137`.
</issue_to_address>

### Comment 2
<location path="sdk/go/instrumentation/anthropic/instrumentor.go" line_range="204-208" />
<code_context>
 		semconv.SetIntAttribute(span, semconv.GenAIUsageTotalTokens, resp.Usage.InputTokens+resp.Usage.OutputTokens)
 		if resp.Usage.CacheCreationInputTokens > 0 {
 			semconv.SetIntAttribute(span, semconv.GenAIUsagePromptTokensDetailsCacheWrite, resp.Usage.CacheCreationInputTokens)
+			semconv.SetIntAttribute(span, semconv.GenAIUsageCacheCreationInputTokensKey, resp.Usage.CacheCreationInputTokens)
 		}
 		if resp.Usage.CacheReadInputTokens > 0 {
 			semconv.SetIntAttribute(span, semconv.GenAIUsagePromptTokensDetailsCacheRead, resp.Usage.CacheReadInputTokens)
+			semconv.SetIntAttribute(span, semconv.GenAIUsageCacheReadInputTokensKey, resp.Usage.CacheReadInputTokens)
 		}
 	}
</code_context>
<issue_to_address>
**Usage aliases are dropped at span limits**

When a caller configures a restrictive OpenTelemetry span attribute limit and earlier span attributes leave room for a legacy usage key but not its new aliases, `SetIntAttribute` adds each UI-facing key after its legacy counterpart. When the span’s attribute limit has room for the legacy key but not the additional aliases, OpenTelemetry drops the new keys and the UI still shows the usage counts as missing.

Set the UI-facing keys before compatibility aliases so they take precedence when span attribute limits are reached.

Also at `sdk/go/instrumentation/anthropic/streaming.go:224-228`, `sdk/go/instrumentation/openai/instrumentor.go:432-444`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and if the new attributes contain incorrect token counts, exported spans may retain those values after a revert. The same counts are also emitted under existing attributes, so affected telemetry can be identified and corrected or recomputed; reverting stops the incorrect keys from being emitted in future spans.

Blocking findings: sdk/go/instrumentation/anthropic/instrumentor.go:208, sdk/go/instrumentation/anthropic/instrumentor.go:208


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +204 to +208
semconv.SetIntAttribute(span, semconv.GenAIUsageCacheCreationInputTokensKey, resp.Usage.CacheCreationInputTokens)
}
if resp.Usage.CacheReadInputTokens > 0 {
semconv.SetIntAttribute(span, semconv.GenAIUsagePromptTokensDetailsCacheRead, resp.Usage.CacheReadInputTokens)
semconv.SetIntAttribute(span, semconv.GenAIUsageCacheReadInputTokensKey, resp.Usage.CacheReadInputTokens)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Medium · Canonical cache counts remain missing

When the Anthropic or OpenAI response includes cache-token usage, the new emitters write cache counts under gen_ai.usage.cache_read.input_tokens and gen_ai.usage.cache_creation.input_tokens rather than the convention’s gen_ai.usage.cache.read_input_tokens and gen_ai.usage.cache.creation_input_tokens; consumers following the canonical schema do not find these counts.

Emit the cache counts under the convention’s cache.read_input_tokens and cache.creation_input_tokens keys, while retaining any compatibility aliases only if they do not replace those canonical attributes.

Also at sdk/go/instrumentation/anthropic/streaming.go:224-228, sdk/go/instrumentation/openai/instrumentor.go:444, sdk/go/semconv/genai.go:136-137.

Prompt for AI agents
In `sdk/go/instrumentation/anthropic/instrumentor.go` at lines 204-208:

**Canonical cache counts remain missing**

When the Anthropic or OpenAI response includes cache-token usage, the new emitters write cache counts under `gen_ai.usage.cache_read.input_tokens` and `gen_ai.usage.cache_creation.input_tokens` rather than the convention’s `gen_ai.usage.cache.read_input_tokens` and `gen_ai.usage.cache.creation_input_tokens`; consumers following the canonical schema do not find these counts.

Emit the cache counts under the convention’s `cache.read_input_tokens` and `cache.creation_input_tokens` keys, while retaining any compatibility aliases only if they do not replace those canonical attributes.

Also at `sdk/go/instrumentation/anthropic/streaming.go:224-228`, `sdk/go/instrumentation/openai/instrumentor.go:444`, `sdk/go/semconv/genai.go:136-137`.

From agent-guides/coding-agents-convention.md L3:

This is the **strict** contract between every coding-agent vendor and OpenLit. Every adapter, every native-telemetry mapping, every query has to match it exactly. Drift in either direction (renaming an attribute, switching units, adding ad-hoc vendor-namespaced keys) breaks the `/coding-agents` and `/agents` views in subtle, hard-to-diagnose ways. When in doubt, prefer this document over what any individual vendor's docs claim.

Comment on lines +204 to +208
semconv.SetIntAttribute(span, semconv.GenAIUsageCacheCreationInputTokensKey, resp.Usage.CacheCreationInputTokens)
}
if resp.Usage.CacheReadInputTokens > 0 {
semconv.SetIntAttribute(span, semconv.GenAIUsagePromptTokensDetailsCacheRead, resp.Usage.CacheReadInputTokens)
semconv.SetIntAttribute(span, semconv.GenAIUsageCacheReadInputTokensKey, resp.Usage.CacheReadInputTokens)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Medium · Usage aliases are dropped at span limits

When a caller configures a restrictive OpenTelemetry span attribute limit and earlier span attributes leave room for a legacy usage key but not its new aliases, SetIntAttribute adds each UI-facing key after its legacy counterpart. When the span’s attribute limit has room for the legacy key but not the additional aliases, OpenTelemetry drops the new keys and the UI still shows the usage counts as missing.

Set the UI-facing keys before compatibility aliases so they take precedence when span attribute limits are reached.

Also at sdk/go/instrumentation/anthropic/streaming.go:224-228, sdk/go/instrumentation/openai/instrumentor.go:432-444.

Prompt for AI agents
In `sdk/go/instrumentation/anthropic/instrumentor.go` at lines 204-208:

**Usage aliases are dropped at span limits**

When a caller configures a restrictive OpenTelemetry span attribute limit and earlier span attributes leave room for a legacy usage key but not its new aliases, `SetIntAttribute` adds each UI-facing key after its legacy counterpart. When the span’s attribute limit has room for the legacy key but not the additional aliases, OpenTelemetry drops the new keys and the UI still shows the usage counts as missing.

Set the UI-facing keys before compatibility aliases so they take precedence when span attribute limits are reached.

Also at `sdk/go/instrumentation/anthropic/streaming.go:224-228`, `sdk/go/instrumentation/openai/instrumentor.go:432-444`.

This branch was previously deployed

1 inactive deployment
release-notes — c483ecc9 Deployed Nov 22, 2026 by basil-k-aji-dev via Normalize / Conventional title #879
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.

Bug: Go SDK writes cache and reasoning token counts under attribute names nothing reads

1 participant