Skip to content

FR: Copy OpenAI cache tokens to retry attempts - #32

Merged
sayonfortify merged 1 commit into
fr-v0.52.6.xfrom
fix/openai-retry-cache-token-attrs
Jun 16, 2026
Merged

FR: Copy OpenAI cache tokens to retry attempts#32
sayonfortify merged 1 commit into
fr-v0.52.6.xfrom
fix/openai-retry-cache-token-attrs

Conversation

@sayonfortify

Copy link
Copy Markdown

Summary

  • copy OpenAI response-body prompt_tokens_details.cached_tokens onto the canonical retry-attempt span as gen_ai.usage.cache_read_input_tokens
  • copy total_tokens onto retry-attempt spans as llm.usage.total_tokens
  • extend the retry-attempt unit test to assert the canonical attempt span carries total/cache usage attributes

Why

FortifyRoot backend now stores cache-token columns from span attributes, but live validation showed OpenAI cache tokens only on the skipped parent openai.chat span. The backend canonical usage event is the fortifyroot.openai.attempt_1 span, so cache usage must be present on that retry-attempt span to survive export batching and backend dedup.

Validation

  • python3 scripts/apply-fr-modification-notices.py --check
  • PYTHONPATH=../opentelemetry-semantic-conventions-ai:../opentelemetry-instrumentation-fortifyroot:. pytest tests/test_retry_attempt_emission.py -q from packages/opentelemetry-instrumentation-openai → 37 passed
  • python -m compileall -q packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/retry_handler.py packages/opentelemetry-instrumentation-openai/tests/test_retry_attempt_emission.py

Downstream

After merge, cut the next fr-v0.52.6.N tag and vendor it into ocelle-py via ocelle-py/scripts/vendor.sh.

@sayonfortify
sayonfortify merged commit 724081b into fr-v0.52.6.x Jun 16, 2026
10 checks passed
@sayonfortify
sayonfortify deleted the fix/openai-retry-cache-token-attrs branch June 16, 2026 20:22
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.

1 participant