diff --git a/sentry_sdk/integrations/openai_agents/utils.py b/sentry_sdk/integrations/openai_agents/utils.py index f1d81fd413..b82518c7b3 100644 --- a/sentry_sdk/integrations/openai_agents/utils.py +++ b/sentry_sdk/integrations/openai_agents/utils.py @@ -209,16 +209,13 @@ def _set_output_data( span: "Union[sentry_sdk.tracing.Span, StreamedSpan]", result: "Any" ) -> None: client = sentry_sdk.get_client() - record_inputs = False record_outputs = False if has_data_collection_enabled(client.options): - record_inputs = client.options["data_collection"]["gen_ai"]["inputs"] record_outputs = client.options["data_collection"]["gen_ai"]["outputs"] elif should_send_default_pii(): - record_inputs = True record_outputs = True - if not record_inputs and not record_outputs: + if not record_outputs: return output_messages: "dict[str, list[Any]]" = { @@ -237,7 +234,7 @@ def _set_output_data( # Unknown output message type, just return the json output_messages["response"].append(output_message.dict()) - if record_inputs and len(output_messages["tool"]) > 0: + if record_outputs and len(output_messages["tool"]) > 0: if isinstance(span, StreamedSpan): span.set_attribute( SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, diff --git a/tests/integrations/openai_agents/test_openai_agents.py b/tests/integrations/openai_agents/test_openai_agents.py index 0bd9fb9de5..455cebbf01 100644 --- a/tests/integrations/openai_agents/test_openai_agents.py +++ b/tests/integrations/openai_agents/test_openai_agents.py @@ -1180,55 +1180,48 @@ async def test_data_collection_inputs( @pytest.mark.parametrize("span_streaming", [True, False]) @pytest.mark.parametrize("stream_gen_ai_spans", [True, False]) @pytest.mark.parametrize( - "data_collection,send_default_pii,expect_output,expect_tool_calls", + "data_collection,send_default_pii,expect_output", [ pytest.param( {"gen_ai": {"outputs": True}}, False, True, - True, id="gen-ai-outputs-enabled-overrides-pii-disabled", ), pytest.param( {"gen_ai": {"outputs": False}}, True, False, - True, - id="gen-ai-outputs-disabled-still-collects-tool-calls-gated-on-inputs", + id="gen-ai-outputs-disabled-overrides-pii-enabled", ), pytest.param( {}, False, True, - True, id="gen-ai-omitted-defaults-to-enabled", ), pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, False, False, - False, id="gen-ai-inputs-and-outputs-disabled-and-pii-disabled", ), pytest.param( {"gen_ai": {"inputs": False}}, False, True, - False, - id="gen-ai-inputs-disabled-drops-tool-calls-only", + id="gen-ai-inputs-disabled-keeps-outputs-and-tool-calls", ), pytest.param( None, False, False, - False, id="no-data-collection-falls-back-to-send-default-pii", ), pytest.param( None, True, True, - True, id="no-data-collection-pii-enabled-collects", ), ], @@ -1245,7 +1238,6 @@ async def test_data_collection_outputs( data_collection, send_default_pii, expect_output, - expect_tool_calls, stream_gen_ai_spans, span_streaming, ): @@ -1326,16 +1318,11 @@ async def test_data_collection_outputs( assert len(chat_span_data) == 2 - if expect_tool_calls: + if expect_output: assert any( "simple_test_tool" in data.get(SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, "") for data in chat_span_data ) - else: - for data in chat_span_data: - assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in data - - if expect_output: assert any( "Task completed using the tool" in str(data.get(SPANDATA.GEN_AI_RESPONSE_TEXT, "")) @@ -1343,6 +1330,7 @@ async def test_data_collection_outputs( ) else: for data in chat_span_data: + assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in data assert SPANDATA.GEN_AI_RESPONSE_TEXT not in data # Non-PII data is unaffected by the gate