From 645570743e08c1fc6d3b6e492589b2d3a031866b Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Wed, 18 Mar 2026 13:35:08 +0100 Subject: [PATCH] fix(openai): Simplify Responses input handling --- sentry_sdk/integrations/openai.py | 22 +++++----------------- tests/integrations/openai/test_openai.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index a637e4fc47..eeeede575f 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -234,36 +234,24 @@ def _set_responses_api_input_data( ) model = kwargs.get("model") - if model is not None and _is_given(model): - set_data_normalized(span, SPANDATA.GEN_AI_REQUEST_MODEL, model) + 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): - set_data_normalized(span, SPANDATA.GEN_AI_RESPONSE_STREAMING, 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) - presence_penalty = kwargs.get("presence_penalty") - if presence_penalty is not None and _is_given(presence_penalty): - set_data_normalized( - span, SPANDATA.GEN_AI_REQUEST_PRESENCE_PENALTY, presence_penalty - ) - - frequency_penalty = kwargs.get("frequency_penalty") - if frequency_penalty is not None and _is_given(frequency_penalty): - set_data_normalized( - span, SPANDATA.GEN_AI_REQUEST_FREQUENCY_PENALTY, frequency_penalty - ) - temperature = kwargs.get("temperature") if temperature is not None and _is_given(temperature): - set_data_normalized(span, SPANDATA.GEN_AI_REQUEST_TEMPERATURE, temperature) + span.set_data(SPANDATA.GEN_AI_REQUEST_TEMPERATURE, temperature) top_p = kwargs.get("top_p") if top_p is not None and _is_given(top_p): - set_data_normalized(span, SPANDATA.GEN_AI_REQUEST_TOP_P, top_p) + span.set_data(SPANDATA.GEN_AI_REQUEST_TOP_P, top_p) if not should_send_default_pii() or not integration.include_prompts: set_data_normalized(span, SPANDATA.GEN_AI_OPERATION_NAME, "responses") diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index aac6ded13d..390b26481b 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -1767,6 +1767,8 @@ def test_ai_client_span_responses_api_no_pii(sentry_init, capture_events): instructions="You are a coding assistant that talks like a pirate.", input="How do I check if a Python object is an instance of a class?", max_output_tokens=100, + temperature=0.7, + top_p=0.9, ) (transaction,) = events @@ -1778,6 +1780,8 @@ def test_ai_client_span_responses_api_no_pii(sentry_init, capture_events): assert spans[0]["data"] == { "gen_ai.operation.name": "responses", "gen_ai.request.max_tokens": 100, + "gen_ai.request.temperature": 0.7, + "gen_ai.request.top_p": 0.9, "gen_ai.request.model": "gpt-4o", "gen_ai.response.model": "response-model-id", "gen_ai.system": "openai", @@ -1879,6 +1883,8 @@ def test_ai_client_span_responses_api( instructions=instructions, input=input, max_output_tokens=100, + temperature=0.7, + top_p=0.9, ) (transaction,) = events @@ -1891,6 +1897,8 @@ def test_ai_client_span_responses_api( expected_data = { "gen_ai.operation.name": "responses", "gen_ai.request.max_tokens": 100, + "gen_ai.request.temperature": 0.7, + "gen_ai.request.top_p": 0.9, "gen_ai.system": "openai", "gen_ai.response.model": "response-model-id", "gen_ai.usage.input_tokens": 20, @@ -2183,6 +2191,8 @@ async def test_ai_client_span_responses_async_api( instructions=instructions, input=input, max_output_tokens=100, + temperature=0.7, + top_p=0.9, ) (transaction,) = events @@ -2195,6 +2205,8 @@ async def test_ai_client_span_responses_async_api( expected_data = { "gen_ai.operation.name": "responses", "gen_ai.request.max_tokens": 100, + "gen_ai.request.temperature": 0.7, + "gen_ai.request.top_p": 0.9, "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", @@ -2454,6 +2466,8 @@ async def test_ai_client_span_streaming_responses_async_api( input=input, stream=True, max_output_tokens=100, + temperature=0.7, + top_p=0.9, ) async for _ in result: pass @@ -2468,6 +2482,8 @@ async def test_ai_client_span_streaming_responses_async_api( expected_data = { "gen_ai.operation.name": "responses", "gen_ai.request.max_tokens": 100, + "gen_ai.request.temperature": 0.7, + "gen_ai.request.top_p": 0.9, "gen_ai.response.model": "response-model-id", "gen_ai.response.streaming": True, "gen_ai.system": "openai", @@ -2781,6 +2797,8 @@ def test_streaming_responses_api( input="hello", stream=True, max_output_tokens=100, + temperature=0.7, + top_p=0.9, ) response_string = "" @@ -2795,6 +2813,8 @@ def test_streaming_responses_api( assert span["op"] == "gen_ai.responses" assert span["data"][SPANDATA.GEN_AI_SYSTEM] == "openai" assert span["data"][SPANDATA.GEN_AI_REQUEST_MAX_TOKENS] == 100 + assert span["data"][SPANDATA.GEN_AI_REQUEST_TEMPERATURE] == 0.7 + assert span["data"][SPANDATA.GEN_AI_REQUEST_TOP_P] == 0.9 assert span["data"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "response-model-id" @@ -2841,6 +2861,8 @@ async def test_streaming_responses_api_async( input="hello", stream=True, max_output_tokens=100, + temperature=0.7, + top_p=0.9, ) response_string = "" @@ -2855,6 +2877,8 @@ async def test_streaming_responses_api_async( assert span["op"] == "gen_ai.responses" assert span["data"][SPANDATA.GEN_AI_SYSTEM] == "openai" assert span["data"][SPANDATA.GEN_AI_REQUEST_MAX_TOKENS] == 100 + assert span["data"][SPANDATA.GEN_AI_REQUEST_TEMPERATURE] == 0.7 + assert span["data"][SPANDATA.GEN_AI_REQUEST_TOP_P] == 0.9 assert span["data"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "response-model-id"