From fb93ba5c26c622f109bd8d6ff53a41c1daae97d1 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Wed, 18 Mar 2026 13:53:50 +0100 Subject: [PATCH] fix(openai): Always set gen_ai.response.streaming for Responses --- sentry_sdk/integrations/openai.py | 8 +++----- tests/integrations/openai/test_openai.py | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index eeeede575f..54574ba752 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -237,10 +237,6 @@ def _set_responses_api_input_data( if model is not None: span.set_data(SPANDATA.GEN_AI_REQUEST_MODEL, model) - stream = kwargs.get("stream") - if stream is not None and _is_given(stream): - span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, stream) - max_tokens = kwargs.get("max_output_tokens") if max_tokens is not None and _is_given(max_tokens): span.set_data(SPANDATA.GEN_AI_REQUEST_MAX_TOKENS, max_tokens) @@ -1097,12 +1093,14 @@ def _new_responses_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "An span.__enter__() span.set_data(SPANDATA.GEN_AI_SYSTEM, "openai") + is_streaming_response = kwargs.get("stream", False) + span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, is_streaming_response) + _set_responses_api_input_data(span, kwargs, integration) start_time = time.perf_counter() response = yield f, args, kwargs - is_streaming_response = kwargs.get("stream", False) if is_streaming_response: _set_streaming_responses_api_output_data( span, response, kwargs, integration, start_time, finish_span=True diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index 390b26481b..237fe7d71e 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -1784,6 +1784,7 @@ def test_ai_client_span_responses_api_no_pii(sentry_init, capture_events): "gen_ai.request.top_p": 0.9, "gen_ai.request.model": "gpt-4o", "gen_ai.response.model": "response-model-id", + "gen_ai.response.streaming": False, "gen_ai.system": "openai", "gen_ai.usage.input_tokens": 20, "gen_ai.usage.input_tokens.cached": 5, @@ -1901,6 +1902,7 @@ def test_ai_client_span_responses_api( "gen_ai.request.top_p": 0.9, "gen_ai.system": "openai", "gen_ai.response.model": "response-model-id", + "gen_ai.response.streaming": False, "gen_ai.usage.input_tokens": 20, "gen_ai.usage.input_tokens.cached": 5, "gen_ai.usage.output_tokens": 10, @@ -2210,6 +2212,7 @@ async def test_ai_client_span_responses_async_api( "gen_ai.request.messages": '["How do I check if a Python object is an instance of a class?"]', "gen_ai.request.model": "gpt-4o", "gen_ai.response.model": "response-model-id", + "gen_ai.response.streaming": False, "gen_ai.system": "openai", "gen_ai.usage.input_tokens": 20, "gen_ai.usage.input_tokens.cached": 5,