diff --git a/sentry_sdk/integrations/litellm.py b/sentry_sdk/integrations/litellm.py index cb50da2ea7..467f7c07ad 100644 --- a/sentry_sdk/integrations/litellm.py +++ b/sentry_sdk/integrations/litellm.py @@ -117,7 +117,7 @@ def _input_callback(kwargs: "Dict[str, Any]") -> None: record_inputs = False if has_data_collection_enabled(client.options): record_inputs = client.options["data_collection"]["gen_ai"]["inputs"] - elif should_send_default_pii() and integration.include_prompts: + elif should_send_default_pii(): record_inputs = True if record_inputs: @@ -198,7 +198,7 @@ def _success_callback( record_outputs = False if has_data_collection_enabled(client.options): record_outputs = client.options["data_collection"]["gen_ai"]["outputs"] - elif should_send_default_pii() and integration.include_prompts: + elif should_send_default_pii(): record_outputs = True if record_outputs: @@ -336,9 +336,6 @@ class LiteLLMIntegration(Integration): identifier = "litellm" origin = f"auto.ai.{identifier}" - def __init__(self: "LiteLLMIntegration", include_prompts: bool = True) -> None: - self.include_prompts = include_prompts - @staticmethod def setup_once() -> None: """Set up LiteLLM callbacks for monitoring.""" diff --git a/tests/integrations/litellm/test_litellm.py b/tests/integrations/litellm/test_litellm.py index 2330072beb..145ddaa6e3 100644 --- a/tests/integrations/litellm/test_litellm.py +++ b/tests/integrations/litellm/test_litellm.py @@ -135,25 +135,19 @@ def __init__( @pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, True), - (True, False), - (False, True), - (False, False), - ], + "send_default_pii", + [True, False], ) def test_nonstreaming_chat_completion( reset_litellm_executor, sentry_init, capture_items, send_default_pii, - include_prompts, get_model_response, nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=include_prompts)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -214,7 +208,7 @@ def test_nonstreaming_chat_completion( assert span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert span["attributes"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" - if send_default_pii and include_prompts: + if send_default_pii: assert json.loads(span["attributes"][SPANDATA.GEN_AI_REQUEST_MESSAGES]) == [ { "role": "user", @@ -234,24 +228,18 @@ def test_nonstreaming_chat_completion( @pytest.mark.asyncio(loop_scope="session") @pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, True), - (True, False), - (False, True), - (False, False), - ], + "send_default_pii", + [True, False], ) async def test_async_nonstreaming_chat_completion( sentry_init, capture_items, send_default_pii, - include_prompts, get_model_response, nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=include_prompts)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -313,7 +301,7 @@ async def test_async_nonstreaming_chat_completion( assert span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert span["attributes"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" - if send_default_pii and include_prompts: + if send_default_pii: assert json.loads(span["attributes"][SPANDATA.GEN_AI_REQUEST_MESSAGES]) == [ { "role": "user", @@ -332,26 +320,20 @@ async def test_async_nonstreaming_chat_completion( @pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, True), - (True, False), - (False, True), - (False, False), - ], + "send_default_pii", + [True, False], ) def test_streaming_chat_completion( reset_litellm_executor, sentry_init, capture_items, send_default_pii, - include_prompts, get_model_response, server_side_event_chunks, streaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=include_prompts)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -406,26 +388,20 @@ def test_streaming_chat_completion( @pytest.mark.asyncio(loop_scope="session") @pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, True), - (True, False), - (False, True), - (False, False), - ], + "send_default_pii", + [True, False], ) async def test_async_streaming_chat_completion( sentry_init, capture_items, send_default_pii, - include_prompts, get_model_response, async_iterator, server_side_event_chunks, streaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=include_prompts)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -495,7 +471,7 @@ def test_embeddings_create( to ensure proper integration testing. """ sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -565,7 +541,7 @@ async def test_async_embeddings_create( to ensure proper integration testing. """ sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -630,7 +606,7 @@ def test_embeddings_create_with_list_input( ): """Test embedding with list input.""" sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -694,7 +670,7 @@ async def test_async_embeddings_create_with_list_input( ): """Test embedding with list input.""" sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -757,7 +733,7 @@ def test_embeddings_no_pii( ): """Test that PII is not captured when disabled.""" sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=False, # PII disabled @@ -813,7 +789,7 @@ async def test_async_embeddings_no_pii( ): """Test that PII is not captured when disabled.""" sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=False, # PII disabled @@ -1515,7 +1491,7 @@ def test_binary_content_encoding_image_url( nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1605,7 +1581,7 @@ async def test_async_binary_content_encoding_image_url( nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1696,7 +1672,7 @@ def test_binary_content_encoding_mixed_content( nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1775,7 +1751,7 @@ async def test_async_binary_content_encoding_mixed_content( nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1855,7 +1831,7 @@ def test_binary_content_encoding_uri_type( nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1938,7 +1914,7 @@ async def test_async_binary_content_encoding_uri_type( nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[LiteLLMIntegration(include_prompts=True)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -2116,12 +2092,11 @@ def test_convert_message_parts_image_url_missing_url(): @pytest.mark.parametrize( - "data_collection, send_default_pii, include_prompts, expected_present, expected_absent", + "data_collection, send_default_pii, expected_present, expected_absent", [ pytest.param( {"gen_ai": {"inputs": True, "outputs": True}}, False, - False, [SPANDATA.GEN_AI_REQUEST_MESSAGES, SPANDATA.GEN_AI_RESPONSE_TEXT], [], id="gen-ai-inputs-and-outputs-enabled-override-legacy-off", @@ -2129,7 +2104,6 @@ def test_convert_message_parts_image_url_missing_url(): pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, True, - True, [], [SPANDATA.GEN_AI_REQUEST_MESSAGES, SPANDATA.GEN_AI_RESPONSE_TEXT], id="gen-ai-inputs-and-outputs-disabled-override-legacy-on", @@ -2137,7 +2111,6 @@ def test_convert_message_parts_image_url_missing_url(): pytest.param( {"gen_ai": {"inputs": True, "outputs": False}}, False, - False, [SPANDATA.GEN_AI_REQUEST_MESSAGES], [SPANDATA.GEN_AI_RESPONSE_TEXT], id="gen-ai-inputs-enabled-outputs-disabled", @@ -2145,7 +2118,6 @@ def test_convert_message_parts_image_url_missing_url(): pytest.param( {"gen_ai": {"inputs": False, "outputs": True}}, False, - False, [SPANDATA.GEN_AI_RESPONSE_TEXT], [SPANDATA.GEN_AI_REQUEST_MESSAGES], id="gen-ai-outputs-enabled-inputs-disabled", @@ -2153,7 +2125,6 @@ def test_convert_message_parts_image_url_missing_url(): pytest.param( {"gen_ai": {}}, False, - False, [SPANDATA.GEN_AI_REQUEST_MESSAGES, SPANDATA.GEN_AI_RESPONSE_TEXT], [], id="gen-ai-inputs-and-outputs-omitted-default-to-enabled", @@ -2161,15 +2132,13 @@ def test_convert_message_parts_image_url_missing_url(): pytest.param( None, True, - True, [SPANDATA.GEN_AI_REQUEST_MESSAGES, SPANDATA.GEN_AI_RESPONSE_TEXT], [], - id="no-gen-ai-config-legacy-pii-and-include-prompts-enabled", + id="no-gen-ai-config-legacy-pii", ), pytest.param( None, False, - True, [], [SPANDATA.GEN_AI_REQUEST_MESSAGES, SPANDATA.GEN_AI_RESPONSE_TEXT], id="no-gen-ai-config-legacy-pii-disabled", @@ -2184,12 +2153,11 @@ def test_chat_completion_data_collection( nonstreaming_chat_completions_model_response, data_collection, send_default_pii, - include_prompts, expected_present, expected_absent, ): sentry_init_kwargs = dict( - integrations=[LiteLLMIntegration(include_prompts=include_prompts)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -2266,26 +2234,23 @@ def test_chat_completion_data_collection( @pytest.mark.parametrize( - "data_collection, send_default_pii, include_prompts, should_collect_input", + "data_collection, send_default_pii, should_collect_input", [ pytest.param( {"gen_ai": {"inputs": True}}, False, - False, True, id="gen-ai-inputs-enabled-override-legacy-off", ), pytest.param( {"gen_ai": {"inputs": False}}, True, - True, False, id="gen-ai-inputs-disabled-override-legacy-on", ), pytest.param( {"gen_ai": {}}, False, - False, True, id="gen-ai-inputs-omitted-default-to-enabled", ), @@ -2293,13 +2258,11 @@ def test_chat_completion_data_collection( None, True, True, - True, - id="no-gen-ai-config-legacy-pii-and-include-prompts-enabled", + id="no-gen-ai-config-legacy-pii", ), pytest.param( None, False, - True, False, id="no-gen-ai-config-legacy-pii-disabled", ), @@ -2312,11 +2275,10 @@ def test_embeddings_data_collection( openai_embedding_model_response, data_collection, send_default_pii, - include_prompts, should_collect_input, ): sentry_init_kwargs = dict( - integrations=[LiteLLMIntegration(include_prompts=include_prompts)], + integrations=[LiteLLMIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii,