diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 3315ece0fe..8c276ba5e9 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -180,12 +180,6 @@ class LangchainIntegration(Integration): _ignored_exceptions: "set[type[Exception]]" = set() - def __init__( - self: "LangchainIntegration", - include_prompts: bool = True, - ) -> None: - self.include_prompts = include_prompts - @staticmethod def setup_once() -> None: version = parse_version(LANGCHAIN_VERSION) @@ -210,9 +204,8 @@ def _capture_exception(exc: "Any", scope: "Optional[Any]" = None) -> None: class SentryLangchainCallback(BaseCallbackHandler): """Callback handler that creates Sentry spans.""" - def __init__(self, include_prompts: bool) -> None: + def __init__(self) -> None: self.span_map: "OrderedDict[UUID, Union[Span, _AgentFrameworkChatGenerationContext]]" = OrderedDict() - self.include_prompts = include_prompts def _handle_error(self, run_id: "UUID", error: "Any") -> None: is_ignored = isinstance(error, tuple(LangchainIntegration._ignored_exceptions)) @@ -398,7 +391,7 @@ def on_llm_start( 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 self.include_prompts: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_inputs = True @@ -493,7 +486,7 @@ def on_chat_model_start( 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 self.include_prompts: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_inputs = True @@ -546,7 +539,7 @@ def on_chat_model_end( 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 self.include_prompts: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_outputs = True @@ -584,7 +577,7 @@ def on_llm_end( 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 self.include_prompts: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_outputs = True @@ -694,7 +687,7 @@ def on_tool_start( 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 self.include_prompts: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_inputs = True @@ -725,7 +718,7 @@ def on_tool_end( 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 self.include_prompts: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_outputs = True @@ -1078,9 +1071,7 @@ def new_configure( isinstance(cb, SentryLangchainCallback) for cb in itertools.chain(callbacks_list, inheritable_callbacks_list) ): - sentry_handler = SentryLangchainCallback( - integration.include_prompts, - ) + sentry_handler = SentryLangchainCallback() if isinstance(local_callbacks, BaseCallbackManager): local_callbacks = local_callbacks.copy() local_callbacks.handlers = [ @@ -1118,7 +1109,7 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": 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: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_inputs = True record_outputs = True @@ -1172,7 +1163,7 @@ def new_stream(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": 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: + elif should_send_default_pii(): # TODO: Remove this branch once `send_default_pii` is deprecated record_inputs = True record_outputs = True diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index d9dd492044..ea1bf69a25 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -288,11 +288,7 @@ def test_langchain_text_completion( get_model_response, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -366,11 +362,7 @@ def test_langchain_chat_with_run_name( nonstreaming_chat_completions_model_response, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -434,11 +426,7 @@ def test_langchain_multi_choice_response( nonstreaming_multi_candidate_google_genai_model_response, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -484,11 +472,7 @@ def test_langchain_tool_call_with_run_name( capture_items, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -516,13 +500,8 @@ def test_langchain_tool_call_with_run_name( reason="LangChain 1.0+ required (ONE AGENT refactor)", ) @pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, True), - (True, False), - (False, True), - (False, False), - ], + "send_default_pii", + [True, False], ) @pytest.mark.parametrize( "system_instructions_content,expected_system_instructions", @@ -558,18 +537,13 @@ def test_langchain_create_agent( sentry_init, capture_items, send_default_pii, - include_prompts, system_instructions_content, expected_system_instructions, get_model_response, nonstreaming_responses_model_response, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=include_prompts, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -643,7 +617,7 @@ def test_langchain_create_agent( if LANGCHAIN_OPENAI_VERSION >= (0, 3, 13): assert chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "gpt-4" - if send_default_pii and include_prompts: + if send_default_pii: assert ( chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT] == "Hello, how can I help you?" @@ -680,28 +654,18 @@ def test_langchain_create_agent( reason="LangChain 1.0+ required (ONE AGENT refactor)", ) @pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, True), - (True, False), - (False, True), - (False, False), - ], + "send_default_pii", + [True, False], ) def test_tool_execution_span( sentry_init, capture_items, send_default_pii, - include_prompts, get_model_response, nonstreaming_responses_tool_call_model_responses, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=include_prompts, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -842,7 +806,7 @@ def test_tool_execution_span( chat_spans[1]["attributes"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "gpt-4-0613" ) - if send_default_pii and include_prompts: + if send_default_pii: assert "word" in tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_INPUT] assert "5" in chat_spans[1]["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT] @@ -850,9 +814,7 @@ def test_tool_execution_span( # Verify tool calls are recorded when PII is enabled assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS in chat_spans[0].get( "attributes", {} - ), ( - "Tool calls should be recorded when send_default_pii=True and include_prompts=True" - ) + ), "Tool calls should be recorded when send_default_pii=True" tool_calls_data = chat_spans[0]["attributes"][ SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS ] @@ -873,16 +835,10 @@ def test_tool_execution_span( # Verify tool calls are NOT recorded when PII is disabled assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get( "attributes", {} - ), ( - f"Tool calls should NOT be recorded when send_default_pii={send_default_pii} " - f"and include_prompts={include_prompts}" - ) + ), f"Tool calls should NOT be recorded when send_default_pii={send_default_pii}" assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[1].get( "attributes", {} - ), ( - f"Tool calls should NOT be recorded when send_default_pii={send_default_pii} " - f"and include_prompts={include_prompts}" - ) + ), f"Tool calls should NOT be recorded when send_default_pii={send_default_pii}" # Verify that available tools are always recorded regardless of PII settings for chat_span in chat_spans: @@ -890,32 +846,18 @@ def test_tool_execution_span( assert "get_word_length" in tools_data -@pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, False), - (False, True), - (False, False), - ], -) -def test_langchain_openai_tools_agent_no_prompts( +def test_langchain_openai_tools_agent_no_sensitive_data( sentry_init, capture_items, - send_default_pii, - include_prompts, get_model_response, server_side_event_chunks, streaming_chat_completions_model_responses, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=include_prompts, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, - send_default_pii=send_default_pii, + send_default_pii=False, ) prompt = ChatPromptTemplate.from_messages( @@ -1032,16 +974,10 @@ def test_langchain_openai_tools_agent_no_prompts( # Verify tool calls are NOT recorded when PII is disabled assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get( "attributes", {} - ), ( - f"Tool calls should NOT be recorded when send_default_pii={send_default_pii} " - f"and include_prompts={include_prompts}" - ) + ), "Tool calls should NOT be recorded when send_default_pii=False" assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[1].get( "attributes", {} - ), ( - f"Tool calls should NOT be recorded when send_default_pii={send_default_pii} " - f"and include_prompts={include_prompts}" - ) + ), "Tool calls should NOT be recorded when send_default_pii=False" # Verify finish_reasons is always an array of strings assert chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS] == [ @@ -1113,11 +1049,7 @@ def test_langchain_openai_tools_agent( streaming_chat_completions_model_responses, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1244,7 +1176,7 @@ def test_langchain_openai_tools_agent( # Verify tool calls are recorded when PII is enabled assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS in chat_spans[0].get("attributes", {}), ( - "Tool calls should be recorded when send_default_pii=True and include_prompts=True" + "Tool calls should be recorded when send_default_pii=True" ) tool_calls_data = chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS] @@ -1281,11 +1213,7 @@ def test_langchain_openai_tools_agent_with_config( streaming_chat_completions_model_responses, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1349,32 +1277,18 @@ def test_langchain_openai_tools_agent_with_config( assert invoke_agent_span["attributes"]["gen_ai.function_id"] == "my-snazzy-pipeline" -@pytest.mark.parametrize( - "send_default_pii, include_prompts", - [ - (True, False), - (False, True), - (False, False), - ], -) -def test_langchain_openai_tools_agent_stream_no_prompts( +def test_langchain_openai_tools_agent_stream_no_sensitive_data( sentry_init, capture_items, - send_default_pii, - include_prompts, get_model_response, server_side_event_chunks, streaming_chat_completions_model_responses, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=include_prompts, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, - send_default_pii=send_default_pii, + send_default_pii=False, ) prompt = ChatPromptTemplate.from_messages( @@ -1493,16 +1407,10 @@ def test_langchain_openai_tools_agent_stream_no_prompts( # Verify tool calls are NOT recorded when PII is disabled assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get( "attributes", {} - ), ( - f"Tool calls should NOT be recorded when send_default_pii={send_default_pii} " - f"and include_prompts={include_prompts}" - ) + ), "Tool calls should NOT be recorded when send_default_pii=False" assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[1].get( "attributes", {} - ), ( - f"Tool calls should NOT be recorded when send_default_pii={send_default_pii} " - f"and include_prompts={include_prompts}" - ) + ), "Tool calls should NOT be recorded when send_default_pii=False" # Verify finish_reasons is always an array of strings assert chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS] == [ @@ -1576,11 +1484,7 @@ def test_langchain_openai_tools_agent_stream( streaming_chat_completions_model_responses, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1710,7 +1614,7 @@ def test_langchain_openai_tools_agent_stream( # Verify tool calls are recorded when PII is enabled assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS in chat_spans[0].get("attributes", {}), ( - "Tool calls should be recorded when send_default_pii=True and include_prompts=True" + "Tool calls should be recorded when send_default_pii=True" ) tool_calls_data = chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS] @@ -1747,11 +1651,7 @@ def test_langchain_openai_tools_agent_stream_with_config( streaming_chat_completions_model_responses, ): sentry_init( - integrations=[ - LangchainIntegration( - include_prompts=True, - ) - ], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1837,7 +1737,7 @@ def _llm_type(self) -> str: return "acme-llm" sentry_init( - integrations=[LangchainIntegration(include_prompts=True)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -1894,7 +1794,7 @@ def _llm_type(self) -> str: return "acme-llm" sentry_init( - integrations=[LangchainIntegration(include_prompts=True)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, ) @@ -1948,7 +1848,7 @@ def test_langchain_tool_error( nonstreaming_responses_tool_call_model_responses, ): sentry_init( - integrations=[LangchainIntegration(include_prompts=True)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, ) @@ -2057,7 +1957,7 @@ def _identifying_params(self): ) # Create a manual SentryLangchainCallback - manual_callback = SentryLangchainCallback(include_prompts=False) + manual_callback = SentryLangchainCallback() # Create RunnableConfig with the manual callback config = RunnableConfig(callbacks=[manual_callback]) @@ -2080,8 +1980,8 @@ def _identifying_params(self): def test_span_map_is_instance_variable(): """Test that each SentryLangchainCallback instance has its own span_map.""" # Create two separate callback instances - callback1 = SentryLangchainCallback(include_prompts=True) - callback2 = SentryLangchainCallback(include_prompts=True) + callback1 = SentryLangchainCallback() + callback2 = SentryLangchainCallback() # Verify they have different span_map instances assert callback1.span_map is not callback2.span_map, ( @@ -2128,7 +2028,7 @@ def test_langchain_callback_manager_with_sentry_callback(sentry_init): disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, ) - sentry_callback = SentryLangchainCallback(False) + sentry_callback = SentryLangchainCallback() local_manager = BaseCallbackManager(handlers=[sentry_callback]) with mock.patch("sentry_sdk.integrations.langchain.manager") as mock_manager_module: @@ -2194,7 +2094,7 @@ def test_langchain_callback_list_existing_callback(sentry_init): disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, ) - sentry_callback = SentryLangchainCallback(False) + sentry_callback = SentryLangchainCallback() local_callbacks = [sentry_callback] with mock.patch("sentry_sdk.integrations.langchain.manager") as mock_manager_module: @@ -2254,7 +2154,7 @@ def _llm_type(self) -> str: return "openai-chat" sentry_init( - integrations=[LangchainIntegration(include_prompts=True)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=True, @@ -2643,7 +2543,7 @@ def test_langchain_ai_system_detection( traces_sample_rate=1.0, ) - callback = SentryLangchainCallback(include_prompts=True) + callback = SentryLangchainCallback() run_id = "test-ai-system-uuid" serialized = {"_type": ai_type} if ai_type is not None else {} @@ -2795,12 +2695,11 @@ def test_transform_list_with_legacy_image_url(self): @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: [ {"role": "user", "content": "How many letters in the word eudca"} @@ -2816,7 +2715,6 @@ def test_transform_list_with_legacy_image_url(self): pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, True, - True, {}, [ SPANDATA.GEN_AI_REQUEST_MESSAGES, @@ -2828,7 +2726,6 @@ def test_transform_list_with_legacy_image_url(self): pytest.param( {"gen_ai": {"inputs": True, "outputs": False}}, False, - False, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ {"role": "user", "content": "How many letters in the word eudca"} @@ -2843,7 +2740,6 @@ def test_transform_list_with_legacy_image_url(self): pytest.param( {"gen_ai": {"inputs": False, "outputs": True}}, False, - False, {SPANDATA.GEN_AI_RESPONSE_TEXT: "the model response"}, [ SPANDATA.GEN_AI_REQUEST_MESSAGES, @@ -2854,7 +2750,6 @@ def test_transform_list_with_legacy_image_url(self): pytest.param( {"gen_ai": {}}, False, - False, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ {"role": "user", "content": "How many letters in the word eudca"} @@ -2870,7 +2765,6 @@ def test_transform_list_with_legacy_image_url(self): pytest.param( None, True, - True, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ {"role": "user", "content": "How many letters in the word eudca"} @@ -2886,7 +2780,6 @@ def test_transform_list_with_legacy_image_url(self): pytest.param( None, False, - True, {}, [ SPANDATA.GEN_AI_REQUEST_MESSAGES, @@ -2905,12 +2798,11 @@ def test_langchain_chat_data_collection( nonstreaming_chat_completions_model_response, data_collection, send_default_pii, - include_prompts, expected_present, expected_absent, ): sentry_init_kwargs = dict( - integrations=[LangchainIntegration(include_prompts=include_prompts)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -2983,12 +2875,11 @@ def test_langchain_chat_data_collection( @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: [ { @@ -3007,7 +2898,6 @@ def test_langchain_chat_data_collection( pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, True, - True, {}, [ SPANDATA.GEN_AI_REQUEST_MESSAGES, @@ -3018,7 +2908,6 @@ def test_langchain_chat_data_collection( pytest.param( {"gen_ai": {"inputs": True, "outputs": False}}, False, - False, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ { @@ -3036,7 +2925,6 @@ def test_langchain_chat_data_collection( pytest.param( {"gen_ai": {"inputs": False, "outputs": True}}, False, - False, {SPANDATA.GEN_AI_RESPONSE_TEXT: "The capital of France is Paris."}, [SPANDATA.GEN_AI_REQUEST_MESSAGES], id="gen-ai-outputs-enabled-inputs-disabled", @@ -3044,7 +2932,6 @@ def test_langchain_chat_data_collection( pytest.param( {"gen_ai": {}}, False, - False, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ { @@ -3063,7 +2950,6 @@ def test_langchain_chat_data_collection( pytest.param( None, True, - True, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ { @@ -3082,7 +2968,6 @@ def test_langchain_chat_data_collection( pytest.param( None, False, - True, {}, [ SPANDATA.GEN_AI_REQUEST_MESSAGES, @@ -3099,12 +2984,11 @@ def test_langchain_text_completion_data_collection( get_model_response, data_collection, send_default_pii, - include_prompts, expected_present, expected_absent, ): sentry_init_kwargs = dict( - integrations=[LangchainIntegration(include_prompts=include_prompts)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -3177,12 +3061,11 @@ def test_langchain_text_completion_data_collection( @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_TOOL_DEFINITIONS, SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, @@ -3193,7 +3076,6 @@ def test_langchain_text_completion_data_collection( pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, True, - True, [], [ SPANDATA.GEN_AI_TOOL_DEFINITIONS, @@ -3205,7 +3087,6 @@ def test_langchain_text_completion_data_collection( pytest.param( {"gen_ai": {"inputs": True, "outputs": False}}, False, - False, [SPANDATA.GEN_AI_TOOL_DEFINITIONS], [ # REQUEST_AVAILABLE_TOOLS is the legacy value set when data collection is not enabled @@ -3217,7 +3098,6 @@ def test_langchain_text_completion_data_collection( pytest.param( {"gen_ai": {"inputs": False, "outputs": True}}, True, - True, [SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS], [ SPANDATA.GEN_AI_TOOL_DEFINITIONS, @@ -3228,7 +3108,6 @@ def test_langchain_text_completion_data_collection( pytest.param( {"gen_ai": {}}, False, - False, [ SPANDATA.GEN_AI_TOOL_DEFINITIONS, SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, @@ -3239,7 +3118,6 @@ def test_langchain_text_completion_data_collection( pytest.param( None, True, - True, [ SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS, SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, @@ -3250,7 +3128,6 @@ def test_langchain_text_completion_data_collection( pytest.param( None, False, - False, [SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS], [ SPANDATA.GEN_AI_TOOL_DEFINITIONS, @@ -3269,12 +3146,11 @@ def test_langchain_data_collection_tools( streaming_chat_completions_model_responses, data_collection, send_default_pii, - include_prompts, expected_present, expected_absent, ): sentry_init_kwargs = dict( - integrations=[LangchainIntegration(include_prompts=include_prompts)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -3383,7 +3259,7 @@ def test_langchain_data_collection_request_tool_call_params( tool_calls_collected, ): sentry_init_kwargs = dict( - integrations=[LangchainIntegration(include_prompts=False)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -3393,7 +3269,7 @@ def test_langchain_data_collection_request_tool_call_params( sentry_init(**sentry_init_kwargs) - callback = SentryLangchainCallback(include_prompts=False) + callback = SentryLangchainCallback() captured = capture_items("span") @@ -3429,12 +3305,11 @@ def test_langchain_data_collection_request_tool_call_params( @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_TOOL_INPUT: {"word": "eudca"}, SPANDATA.GEN_AI_TOOL_OUTPUT: 5, @@ -3445,7 +3320,6 @@ def test_langchain_data_collection_request_tool_call_params( pytest.param( {"gen_ai": {"inputs": False, "outputs": False}}, True, - True, {}, [SPANDATA.GEN_AI_TOOL_INPUT, SPANDATA.GEN_AI_TOOL_OUTPUT], id="gen-ai-inputs-and-outputs-disabled-override-legacy-on", @@ -3453,7 +3327,6 @@ def test_langchain_data_collection_request_tool_call_params( pytest.param( {"gen_ai": {"inputs": True, "outputs": False}}, False, - False, {SPANDATA.GEN_AI_TOOL_INPUT: {"word": "eudca"}}, [SPANDATA.GEN_AI_TOOL_OUTPUT], id="gen-ai-inputs-enabled-outputs-disabled", @@ -3461,7 +3334,6 @@ def test_langchain_data_collection_request_tool_call_params( pytest.param( {"gen_ai": {"inputs": False, "outputs": True}}, False, - False, {SPANDATA.GEN_AI_TOOL_OUTPUT: 5}, [SPANDATA.GEN_AI_TOOL_INPUT], id="gen-ai-outputs-enabled-inputs-disabled", @@ -3469,7 +3341,6 @@ def test_langchain_data_collection_request_tool_call_params( pytest.param( {"gen_ai": {}}, False, - False, { SPANDATA.GEN_AI_TOOL_INPUT: {"word": "eudca"}, SPANDATA.GEN_AI_TOOL_OUTPUT: 5, @@ -3480,7 +3351,6 @@ def test_langchain_data_collection_request_tool_call_params( pytest.param( None, True, - True, { SPANDATA.GEN_AI_TOOL_INPUT: {"word": "eudca"}, SPANDATA.GEN_AI_TOOL_OUTPUT: 5, @@ -3491,7 +3361,6 @@ def test_langchain_data_collection_request_tool_call_params( pytest.param( None, False, - True, {}, [SPANDATA.GEN_AI_TOOL_INPUT, SPANDATA.GEN_AI_TOOL_OUTPUT], id="no-gen-ai-config-legacy-pii-disabled", @@ -3507,12 +3376,11 @@ def test_langchain_tool_execution_data_collection( streaming_chat_completions_model_responses, data_collection, send_default_pii, - include_prompts, expected_present, expected_absent, ): sentry_init_kwargs = dict( - integrations=[LangchainIntegration(include_prompts=include_prompts)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii, @@ -3584,12 +3452,11 @@ def test_langchain_tool_execution_data_collection( @pytest.mark.parametrize("agent_method", ["invoke", "stream"]) @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: [ "How many letters in the word eudca" @@ -3602,7 +3469,6 @@ def test_langchain_tool_execution_data_collection( 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", @@ -3610,7 +3476,6 @@ def test_langchain_tool_execution_data_collection( pytest.param( {"gen_ai": {"inputs": True, "outputs": False}}, False, - False, {SPANDATA.GEN_AI_REQUEST_MESSAGES: ["How many letters in the word eudca"]}, [SPANDATA.GEN_AI_RESPONSE_TEXT], id="gen-ai-inputs-enabled-outputs-disabled", @@ -3618,7 +3483,6 @@ def test_langchain_tool_execution_data_collection( pytest.param( {"gen_ai": {"inputs": False, "outputs": True}}, False, - False, {SPANDATA.GEN_AI_RESPONSE_TEXT: "The word eudca has 5 letters."}, [SPANDATA.GEN_AI_REQUEST_MESSAGES], id="gen-ai-outputs-enabled-inputs-disabled", @@ -3626,7 +3490,6 @@ def test_langchain_tool_execution_data_collection( pytest.param( {"gen_ai": {}}, False, - False, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ "How many letters in the word eudca" @@ -3639,7 +3502,6 @@ def test_langchain_tool_execution_data_collection( pytest.param( None, True, - True, { SPANDATA.GEN_AI_REQUEST_MESSAGES: [ "How many letters in the word eudca" @@ -3652,7 +3514,6 @@ def test_langchain_tool_execution_data_collection( pytest.param( None, False, - True, {}, [SPANDATA.GEN_AI_REQUEST_MESSAGES, SPANDATA.GEN_AI_RESPONSE_TEXT], id="no-gen-ai-config-legacy-pii-disabled", @@ -3668,13 +3529,12 @@ def test_langchain_agent_executor_data_collection( streaming_chat_completions_model_responses, data_collection, send_default_pii, - include_prompts, expected_present, expected_absent, agent_method, ): sentry_init_kwargs = dict( - integrations=[LangchainIntegration(include_prompts=include_prompts)], + integrations=[LangchainIntegration()], disabled_integrations=[StdlibIntegration], traces_sample_rate=1.0, send_default_pii=send_default_pii,