Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sentry_sdk/integrations/google_genai/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def accumulate_streaming_response(
model = None

for chunk in chunks:
# Keep the last non-empty value, so a chunk without these fields
# doesn't clear one seen earlier.
response_id = getattr(chunk, "response_id", None) or response_id
model = getattr(chunk, "model_version", None) or model

# Extract text and tool calls
if getattr(chunk, "candidates", None):
for candidate in getattr(chunk, "candidates", []):
Expand Down
12 changes: 12 additions & 0 deletions tests/integrations/google_genai/test_google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,14 @@ def test_streaming_generate_content(
assert (
chat_span["attributes"][SPANDATA.GEN_AI_REQUEST_MODEL] == "gemini-1.5-flash"
)
assert (
chat_span["attributes"][SPANDATA.GEN_AI_RESPONSE_ID]
== "response-id-stream-123"
)
assert (
chat_span["attributes"][SPANDATA.GEN_AI_RESPONSE_MODEL]
== "gemini-1.5-flash"
)
else:
events = capture_events()

Expand Down Expand Up @@ -916,6 +924,10 @@ def test_streaming_generate_content(

# Verify model name
assert chat_span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "gemini-1.5-flash"
assert (
chat_span["data"][SPANDATA.GEN_AI_RESPONSE_ID] == "response-id-stream-123"
)
assert chat_span["data"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "gemini-1.5-flash"


@pytest.mark.parametrize("span_streaming", [True, False])
Expand Down
Loading