fix(litellm): copy streaming latency attrs to canonical attempt span - #41
Merged
sayonfortify merged 1 commit intoJun 20, 2026
Merged
Conversation
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
LiteLLM streaming TTFT/STTG is measured on FortifyRoot's
fortifyroot.litellm.safetywrapper span, but retry-aware extraction treatsfortifyroot.litellm.attempt_Nas the canonical LLM usage span. In live fixture validation, the wrapper and attempt spans can be processed separately, so backend parent inheritance is not sufficient.This change copies wrapper-owned streaming latency attrs onto the active canonical attempt span:
fortifyroot.llm.streaming.time_to_first_token_msfortifyroot.llm.streaming.time_to_generate_msThe streaming wrapper accepts an optional canonical-span setter; the LiteLLM instrumentor supplies a setter that finds active attempt spans under the safety wrapper, sets the attrs immediately, and stores them so finalization re-applies them before span end.
Validation
python3 -m py_compileon changed source/testsconda run -n py3.12 python -m pytest packages/opentelemetry-instrumentation-litellm/tests/test_safety_hooks.py packages/opentelemetry-instrumentation-litellm/tests/test_retry_attempt_emission.py -k 'streaming_wrapper_sets_streaming_latency_attrs or single_attempt_emits_one_retry_attempt_under_parent' -q3 passed, 42 deselectedFR_PROVIDER_MODE=fixture ./scripts/run-tests.sh --telemetry -- -k 'streaming_latency_litellm_single_canonical_usage_event or streaming_latency_llamaindex_single_canonical_usage_event' -rsanalytics_roundtrip 2 passed, 29 deselected; overall13 passed, 0 failedNotes
No provider calls/cost in the system-test validation: provider mode was fixture. The system-test failure that motivated this showed canonical LiteLLM usage rows existed, but TTFT/STTG were absent until these attrs were copied to the canonical attempt span.