diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index 5aca42e4b7..2ca633c4c7 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -608,16 +608,13 @@ def _set_output_data( set_on_span(SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS, [finish_reason]) 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() and integration.include_prompts: - record_inputs = True record_outputs = True - if record_inputs or record_outputs: + if record_outputs: output_messages: "dict[str, list[Any]]" = { "response": [], "tool": [], @@ -629,7 +626,7 @@ def _set_output_data( elif output["type"] == "tool_use": output_messages["tool"].append(output) - if record_inputs and len(output_messages["tool"]) > 0: + if len(output_messages["tool"]) > 0: set_data_normalized( span, SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, @@ -637,7 +634,7 @@ def _set_output_data( unpack=False, ) - if record_outputs and len(output_messages["response"]) > 0: + if len(output_messages["response"]) > 0: set_data_normalized( span, SPANDATA.GEN_AI_RESPONSE_TEXT, output_messages["response"] ) diff --git a/tests/integrations/anthropic/test_anthropic.py b/tests/integrations/anthropic/test_anthropic.py index 7a54dfa1ae..9711beb3d5 100644 --- a/tests/integrations/anthropic/test_anthropic.py +++ b/tests/integrations/anthropic/test_anthropic.py @@ -639,14 +639,13 @@ async def test_nonstreaming_create_message_data_collection_async( @pytest.mark.parametrize("span_streaming", [True, False]) @pytest.mark.parametrize("stream_gen_ai_spans", [True, False]) @pytest.mark.parametrize( - "data_collection,send_default_pii,include_prompts,outputs_collected,tool_calls_collected", + "data_collection,send_default_pii,include_prompts,outputs_collected", [ pytest.param( {"gen_ai": {"outputs": True}}, False, False, True, - True, id="gen-ai-outputs-enabled-overrides-pii-and-include-prompts", ), pytest.param( @@ -654,23 +653,13 @@ async def test_nonstreaming_create_message_data_collection_async( True, True, False, - True, - id="gen-ai-outputs-disabled-still-collects-tool-calls-gated-on-inputs", - ), - pytest.param( - {"gen_ai": {"inputs": False}}, - True, - True, - True, - False, - id="gen-ai-inputs-disabled-drops-tool-calls-only", + id="gen-ai-outputs-disabled-overrides-pii-and-include-prompts", ), pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, True, True, False, - False, id="gen-ai-inputs-and-outputs-disabled-overrides-pii-and-include-prompts", ), pytest.param( @@ -678,7 +667,6 @@ async def test_nonstreaming_create_message_data_collection_async( False, False, True, - True, id="gen-ai-inputs-and-outputs-omitted-defaults-to-enabled", ), pytest.param( @@ -686,7 +674,6 @@ async def test_nonstreaming_create_message_data_collection_async( True, True, True, - True, id="legacy-pii-and-include-prompts-enabled", ), pytest.param( @@ -694,7 +681,6 @@ async def test_nonstreaming_create_message_data_collection_async( False, True, False, - False, id="legacy-pii-disabled", ), ], @@ -707,7 +693,6 @@ def test_nonstreaming_create_message_data_collection_outputs( send_default_pii, include_prompts, outputs_collected, - tool_calls_collected, stream_gen_ai_spans, span_streaming, ): @@ -765,15 +750,12 @@ def test_nonstreaming_create_message_data_collection_outputs( span_data[SPANDATA.GEN_AI_RESPONSE_TEXT] == DATA_COLLECTION_EXPECTED_RESPONSE_TEXT ) - else: - assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span_data - - if tool_calls_collected: assert ( json.loads(span_data[SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS]) == DATA_COLLECTION_EXPECTED_TOOL_CALLS ) else: + assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span_data assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in span_data @@ -785,14 +767,13 @@ def test_nonstreaming_create_message_data_collection_outputs( @pytest.mark.parametrize("stream_gen_ai_spans", [True, False]) @pytest.mark.asyncio @pytest.mark.parametrize( - "data_collection,send_default_pii,include_prompts,outputs_collected,tool_calls_collected", + "data_collection,send_default_pii,include_prompts,outputs_collected", [ pytest.param( {"gen_ai": {"outputs": True}}, False, False, True, - True, id="gen-ai-outputs-enabled-overrides-pii-and-include-prompts", ), pytest.param( @@ -800,23 +781,13 @@ def test_nonstreaming_create_message_data_collection_outputs( True, True, False, - True, - id="gen-ai-outputs-disabled-still-collects-tool-calls-gated-on-inputs", - ), - pytest.param( - {"gen_ai": {"inputs": False}}, - True, - True, - True, - False, - id="gen-ai-inputs-disabled-drops-tool-calls-only", + id="gen-ai-outputs-disabled-overrides-pii-and-include-prompts", ), pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, True, True, False, - False, id="gen-ai-inputs-and-outputs-disabled-overrides-pii-and-include-prompts", ), pytest.param( @@ -824,7 +795,6 @@ def test_nonstreaming_create_message_data_collection_outputs( False, False, True, - True, id="gen-ai-inputs-and-outputs-omitted-defaults-to-enabled", ), pytest.param( @@ -832,7 +802,6 @@ def test_nonstreaming_create_message_data_collection_outputs( True, True, True, - True, id="legacy-pii-and-include-prompts-enabled", ), pytest.param( @@ -840,7 +809,6 @@ def test_nonstreaming_create_message_data_collection_outputs( False, True, False, - False, id="legacy-pii-disabled", ), ], @@ -853,7 +821,6 @@ async def test_nonstreaming_create_message_data_collection_outputs_async( send_default_pii, include_prompts, outputs_collected, - tool_calls_collected, stream_gen_ai_spans, span_streaming, ): @@ -911,15 +878,12 @@ async def test_nonstreaming_create_message_data_collection_outputs_async( span_data[SPANDATA.GEN_AI_RESPONSE_TEXT] == DATA_COLLECTION_EXPECTED_RESPONSE_TEXT ) - else: - assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span_data - - if tool_calls_collected: assert ( json.loads(span_data[SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS]) == DATA_COLLECTION_EXPECTED_TOOL_CALLS ) else: + assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span_data assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in span_data