Repository navigation
Conversation
_abuild_from_streaming_response collected every chunk's text into complete_response and then passed the async generator object itself to handle_streaming_response. set_response_attributes wrote that object into gen_ai.completion.0.content, so the span carried an object repr instead of the model output and the SDK logged an invalid attribute type on every call. With events enabled no gen_ai.choice record was emitted at all, because emit_response_events only handles str and GenerationResponse. Pass complete_response, as the synchronous path already does, and cover the async streaming span with a unit test.
|
|
Author
|
This project requires signing the CLA, and I cannot complete that on behalf of my account, so I am closing this PR rather than leaving it blocked. The analysis and patch stay available in the branch if someone able to sign wants to take them over. |
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.
What
_abuild_from_streaming_responseaccumulates the text of every streamed chunk intocomplete_response, but it passes the async generator object itself tohandle_streaming_response:set_response_attributesthen writes that object intogen_ai.completion.0.content. The span ends up holding a memory address (<async_generator object ... at 0x...>) instead of the model output, and the SDK logsInvalid type <class 'async_generator'> for attribute valueon every call. With events enabled (use_legacy_attributes=False) the async path emits nogen_ai.choiceevent at all, becauseemit_response_eventsonly handlesstrandGenerationResponse.The sync sibling
_build_from_streaming_responsealready does it right — it passescomplete_response(lines 159-161).How
Pass the accumulated text, matching the sync path:
Tests
New
tests/test_streaming_attributes.pydrives_abuild_from_streaming_responsewith an in-memoryAsyncGeneratorof chunks and asserts the exported span:gen_ai.completion.0.content == "Hello world!"(before the fix this is the generator repr),gen_ai.completion.0.role == "assistant".Config.use_legacy_attributesis pinned withmonkeypatchso the assertion is mode-independent. The whole package suite passes locally:18 passed.The expectation matches
tests/disabled_test_bison.py:134, which assertsgen_ai.completion.0.content == "".join(response)for the same async streaming path.Prepared with the help of an AI assistant.
Summary by CodeRabbit