Repository navigation
fix(google-genai): Set response ID and model on streaming spans - #8260
Closed
sentry-junior[bot] wants to merge 1 commit into
Closed
sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
accumulate_streaming_response() initialized response_id and model to None but never read them from the chunks, so streaming chat spans never had gen_ai.response.id or gen_ai.response.model. Fixes #5812
Contributor
Coverage Results 📊✅ 139222 passed | ⏭️ 7861 skipped | Total: 147083 | Pass Rate: 94.66% | Execution Time: 441m 28s All tests are passing successfully. ✅ Patch coverage is 100.00% (2 of 2 changed executable lines covered; target 80%). Changed files with executable lines (1)
Coverage diff@@ Coverage Diff @@
## master #8260 +/-##
==========================================
+ Coverage 90.21% 90.23% +0.02%
==========================================
Files 203 203 —
Tracked lines 27335 27337 +2
Branches 10246 10246 —
==========================================
+ Hits 24660 24667 +7
+ Misses 2675 2670 -5
+ Partials 1559 1555 -4Generated by Coverage Action |
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 #5812
Repro: getsentry/repro#71
Cause:
accumulate_streaming_response()initializedresponse_idandmodeltoNonebut never readresponse_id/model_versionfrom the chunks, so chat spans forgenerate_content_stream(sync and async) never gotgen_ai.response.idorgen_ai.response.model. The non-streaming path already sets both.Fix: read both fields from each chunk, keeping the last non-empty value, so a later chunk without them doesn't clear a value from an earlier one (same convention as the Anthropic integration).
Validation
gen_ai.response.id/gen_ai.response.modelassertions totest_streaming_generate_content(both span-streaming and transaction paths). The existing fixture only puts these fields on the first chunk. Before the fix all 4 parametrizations failed withKeyError: 'gen_ai.response.id'; after, they pass.tests/integrations/google_genaisuite: 526 passed, 1 skipped onpy3.14-google_genai-v3.1.0,py3.14-google_genai-latest,py3.13-google_genai-v1.75.0,py3.12-google_genai-v1.29.0.tests/test_ai_monitoring.py,tests/test_ai_integration_deactivation.py(py3.14-common): pass.ruff check,ruff format --check,mypy sentry_sdk: clean.via automation
evt_986cce2def3acf1f0c69ed3fe2462a31· Run IDdispatch_109f04a9bfcd879564aa7be0e00e8ebf.--
View Session [Sentry]