fix(openai): copy cache tokens onto retry attempts - #42
Closed
sayonfortify wants to merge 1 commit into
Closed
Conversation
Contributor
Author
|
Closing this direct-vendored PR because vendored OpenLLMetry changes must land in FortifyRoot/openllmetry-py first per internal-sop/openllmetry/VENDORING_SOP.md. Source fix is now in FortifyRoot/openllmetry-py#32; after that merges and a new fr-v0.52.6.N tag is cut, I will re-vendor into ocelle-py and open/update the SDK PR from the tag. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prompt_tokens_details.cached_tokensonto the canonicalllm_attemptspan asgen_ai.usage.cache_read_input_tokenstotal_tokensonto retry-attempt spans via the existing semantic constantWhy
Backend
v0.0.80is deployed and can store cache tokens, but live validation still showed zero cache reads for OpenAI. RDS trace projection showed the cache attr on the skipped parentopenai.chatspan, while the canonicalfortifyroot.openai.attempt_1span had token usage but no cache attr. Because attempts can be exported/processed without parent attrs available, the durable fix is to write cache-token usage directly onto the canonical retry-attempt span in Ocelle.Validation
PYTHONPATH=src pytest tests/openai/test_instrumentation.py -q→ 21 passedPYTHONPATH=src pytest tests/test_ocelle_imports.py -q→ 3 passedPYTHONPATH=src python -m compileall -q src/fortifyroot/_vendor/opentelemetry/instrumentation/openai/retry_handler.py tests/openai/test_instrumentation.pygit diff --checkv0.0.80:openai-cache-token-rds-probe-17062026-sdkfix-localcached=2688)llm_usage_eventsstoredcache_read_sum=18816,max_cache_read=2688Notes
py3.12: top-leveltraceloopis installed, sotest_no_traceloop_in_top_levelfails. This is unrelated to the change; CI clean env should remain authoritative.