diff --git a/sentry_sdk/integrations/google_genai/streaming.py b/sentry_sdk/integrations/google_genai/streaming.py index 7f3f58dc93..05b2318f5b 100644 --- a/sentry_sdk/integrations/google_genai/streaming.py +++ b/sentry_sdk/integrations/google_genai/streaming.py @@ -123,10 +123,13 @@ def set_span_data_for_streaming_response( safe_serialize(accumulated_response["tool_calls"]), ) - if accumulated_response.get("id"): - span.set_data(SPANDATA.GEN_AI_RESPONSE_ID, accumulated_response["id"]) - if accumulated_response.get("model"): - span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, accumulated_response["model"]) + response_id = accumulated_response.get("id") + if response_id is not None: + span.set_data(SPANDATA.GEN_AI_RESPONSE_ID, response_id) + + response_model = accumulated_response.get("model") + if response_model is not None: + span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, response_model) if accumulated_response["usage_metadata"] is None: return