Skip to content

fix(util-genai): omit zero cache tokens on remote agent invocation spans - #1141

Merged
lmolkova merged 2 commits into
open-telemetry:mainfrom
WendeelMarinho:fix/util-genai-remote-agent-zero-cache
Nov 29, 2026
Merged

lmolkova merged 2 commits into
open-telemetry:mainfrom
WendeelMarinho:fix/util-genai-remote-agent-zero-cache

Conversation

@WendeelMarinho

Copy link
Copy Markdown
Contributor

Remote agent invocation spans emitted gen_ai.usage.cache_read.input_tokens and cache_write.input_tokens even when they were 0. The spec only recommends them "when available and non-zero" (since #548), and inference spans already drop zeros with or None. This happens in practice: google-genai's Interactions API copies total_cached_tokens, which is 0 in every recorded cassette.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  • py311-test-util-genai: 819 passed; the new test_zero_cache_token_attributes_omitted fails without the fix
  • check-util-api: OK

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added

@WendeelMarinho
WendeelMarinho requested a review from a team as a code owner November 28, 2026 16:24
Copilot AI balanced review requested due to automatic review settings November 28, 2026 16:24
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-11-29 01:11 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change to omit zero-valued cache token attributes from remote agent spans.

No open issues 🎉

What changed in this PR

Fixes shared GenAI utilities so remote agent invocation spans omit zero-valued cache token attributes, matching inference span behavior.

Changes:

  • Emit cache-read and cache-write token attributes only when non-zero.
  • Add a regression test verifying that zero cache counts are omitted while ordinary input-token usage is preserved.
  • Document the user-visible fix in the changelog.
File Description
util/​opentelemetry-util-genai/​tests/​test_handler_agent.py Adds regression coverage for zero cache token omission.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_agent_invocation.py Omits zero-valued cache token attributes from remote agent spans.
util/​opentelemetry-util-genai/​.changelog/​1141.fixed Documents the corrected span behavior.

Review effort: Balanced

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the fix that omits zero-valued cache token attributes from remote agent invocation spans.

No open issues 🎉

Review effort: Balanced

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants