Repository navigation
Conversation
The sync and async chat-completion streaming finalizers only recorded the exception on a mid-stream failure, leaving the span status UNSET. The non-streaming wrappers already set StatusCode.ERROR, so failed streams were invisible to status-filtered error views. Set ERROR status next to record_exception in both finalizers. Signed-off-by: Vladimir Babin <vovababin@gmail.com>
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 branch has not been deployed
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 #4013.
What
The sync (
_finalize_sync_streaming_span) and async (_finalize_streaming_span) chat-completion streaming finalizers only calledspan.record_exception(e)when a stream failed mid-way (connection dropped,MidStreamFallbackError, etc.), leaving the span status UNSET. The non-streaming wrappers already setStatusCode.ERROR, so failed streaming calls were invisible to error views and alerts that filter on span status.This adds
span.set_status(Status(StatusCode.ERROR, str(e)))next to the existingrecord_exceptionin both finalizers — matching the non-streaming behavior.Tests
Added two tests to
tests/test_instrumentor.py(test_completion_sync_streaming_sets_error_status_on_mid_stream_failure,test_acompletion_streaming_sets_error_status_on_mid_stream_failure) that drive a stream raising mid-iteration and assert the span ends withStatusCode.ERRORplus oneexceptionevent.Validation
RED→GREEN confirmed: before the source change both tests fail with
assert <StatusCode.UNSET> == <StatusCode.ERROR>; after it, both pass.Broader streaming/exception/status selection (
-k "stream or exception or status"): 22 passed. One unrelated test (test_completion_streaming_with_extended_thinking_anthropic) fails on this machine because its VCR cassette tries to reach a live Anthropic endpoint — it fails identically on the unmodifiedmain, so it is not caused by this change.