fix(litellm): preserve stream types in streaming wrappers and isolate span attribute extraction errors - #3578
Open
sushantsimpplr wants to merge 1 commit into
Conversation
Contributor
|
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request |
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.
fixes #3577
Instrumentation must be transparent to callers of the instrumented functions. Three related defects in
openinference-instrumentation-litellmbreak that, with litellm itself as the highest-impact caller — its Responses API → chat-completions bridge re-enters the instrumentedlitellm.acompletionand type-checks the result, so with this instrumentor active every streamed/v1/responsesrequest to a provider without native Responses support fails withUnexpected response type: <class 'async_generator'>, and a secondary serialization crash masks the error (details in the issue).Changes
_TracedSyncStream/_TracedAsyncStream(wrapt.ObjectProxy, already a dependency) present as the original stream (isinstancepasses, attribute access delegates) while iterating the existing finalizing generators, so span accumulation/finalization is unchanged. The four streaming return sites (completion,acompletion,responses,aresponses) now return the proxy instead of the bare generator.aresponsesstreaming — mirrors the sync wrapper's existing gate: streams that are notResponsesAPIStreamingIteratorpass through untouched (previously the finalizer silently drained them into an empty stream). Both responses wrappers now also end the span on the pass-through path (previously leaked)._suppress_extractor_errorsdecorator on the_instrument_func_type_*extractors and_finalize_span: extraction failures (e.g.ValueError: Circular reference detectedfromjson.dumpson self-referencing kwargs seen on litellm router retries) log and drop attributes instead of raising into the traced call.Behavior before/after
Testing
tests/test_streaming_transparency.py: sync + async stream type preservation (content and span capture asserted), foreign-iterator pass-through onaresponses, and extractor isolation on cyclic kwargs.ruff check/ruff format --checkclean on changed files.Notes / shortcomings
_json_serializeinopeninference-instrumentationcore could additionally be made cycle-safe (benefits all instrumentors); also left out of scope here.