Skip to content

fix(semconv): restore cache token compatibility aliases on SpanAttributes - #4667

Open
Quantum-Enigma-dot wants to merge 1 commit into
traceloop:mainfrom
Quantum-Enigma-dot:fix-cache-token-migration-regression
Open

Quantum-Enigma-dot wants to merge 1 commit into
traceloop:mainfrom
Quantum-Enigma-dot:fix-cache-token-migration-regression

Conversation

@Quantum-Enigma-dot

@Quantum-Enigma-dot Quantum-Enigma-dot commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary

Restore cache token compatibility aliases on SpanAttributes.

Problem

PR #4243 migrated cache token semantic conventions to GenAIAttributes, but several downstream runtime code paths and tests still reference:

  • SpanAttributes.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS
  • SpanAttributes.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS

This results in AttributeError when cache-token code paths are exercised.

Fix

  • Restore cache token compatibility aliases on SpanAttributes
  • Add regression coverage to prevent future removal
  • Clean up related comments

Validation

  • Added regression tests for cache token aliases
  • Semantic conventions test suite: 253 passed
  • Bedrock prompt caching tests: passed
  • Groq span utils tests: passed
  • Ruff checks: passed

Fixes #4665

Summary by CodeRabbit

  • New Features
    • Added standardized GenAI telemetry attributes for cache-read and cache-creation input tokens. These attributes provide distinct fields for reporting both types of cached input-token usage and match the corresponding OpenTelemetry conventions. Existing cache-token attribute values remain unchanged.

@Quantum-Enigma-dot

Copy link
Copy Markdown
Author

This PR restores backward-compatibility aliases for cache token semantic conventions, adds regression coverage, and resolves the issue introduced during the #4243 migration.

Happy to make any follow-up changes if needed.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 35379a9d-3d7b-463d-ba68-2a411585fa05
Commits

Reviewing files that changed from the base of the PR and between 8d9c93f and 402439f.

Files selected for processing: 2
  • packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/__init__.py
  • packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/_testing.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The semantic conventions package adds GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS and GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS to SpanAttributes, referencing upstream constants. Tests verify the aliases and their string values. The existing LLM_* aliases retain their string values.

Changes: Cache token aliases

Layer / File(s) Summary
Add and verify cache-token aliases
packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/__init__.py, packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/_testing.py
SpanAttributes exposes two upstream-backed cache-token aliases. Tests check that they match the upstream constants and expected strings.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: max-deygin-traceloop

Merge Risk: Minimal · up to 40243

No actionable merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: restoring cache-token compatibility aliases on SpanAttributes.
Linked Issues check Passed Issue #4665 requires Bedrock and Groq cache-token paths to avoid AttributeError and to retain current cache-token constants or compatible aliases. SpanAttributes now defines both `GEN_AI_USAGE_CACHE…
Out of Scope Changes check Passed The reviewed changes are limited to the two compatibility aliases, related cache comments, and regression tests in the semantic-conventions package. These changes directly support issue #4665. No unre…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #4665 requires Bedrock and Groq cache-token paths to avoid AttributeError and to retain current cache-token constants or compatible aliases. SpanAttributes now defines both GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS and GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS from upstream GenAIAttributes. The added TestSpanAttributesCacheAliases tests verify presence, upstream equality, and the current dotted attribute values. These changes satisfy the linked coding requirements.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to the two compatibility aliases, related cache comments, and regression tests in the semantic-conventions package. These changes directly support issue #4665. No unrelated implementation change is shown.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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 Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentation

1 participant