Skip to content

fix(google-genai): Set response ID and model on streaming spans - #8260

Closed
sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/5812-genai-streaming-response-id
Closed

sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/5812-genai-streaming-response-id

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #5812
Repro: getsentry/repro#71

Cause: accumulate_streaming_response() initialized response_id and model to None but never read response_id / model_version from the chunks, so chat spans for generate_content_stream (sync and async) never got gen_ai.response.id or gen_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

  • Added gen_ai.response.id / gen_ai.response.model assertions to test_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 with KeyError: 'gen_ai.response.id'; after, they pass.
  • Full tests/integrations/google_genai suite: 526 passed, 1 skipped on py3.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.
  • Repro (sentry-sdk 2.74.0, google-genai 3.2.0) exits 1 on the release and exits 0 with this branch installed editable (SDK loaded from the checkout).

via automation evt_986cce2def3acf1f0c69ed3fe2462a31 · Run ID dispatch_109f04a9bfcd879564aa7be0e00e8ebf.

--

View Session [Sentry]

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
@sentry-junior sentry-junior Bot added the junior-automation:repro PR from the Junior SDK repro flow label Nov 12, 2026
@sentry-junior
sentry-junior Bot requested a review from a team November 12, 2026 11:51
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
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%).
Project statement coverage is 90.23% (up 0.02 percentage points from base (860a060) to head (d29d509)).

Changed files with executable lines (1)
File Patch coverage Changed executable lines
sentry_sdk/integrations/google_genai/streaming.py 100.00% 2/2 covered
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        -4

Generated by Coverage Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

junior-automation:repro PR from the Junior SDK repro flow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Streaming responses don't capture response_id or model_version

1 participant