From ee0b7d94228331c23d507a76d3aa5475a58a71b1 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Tue, 31 Mar 2026 14:25:10 +0200 Subject: [PATCH 1/3] feat(langchain): Record run_name in on_tool_start --- sentry_sdk/integrations/langchain.py | 7 +++++ .../integrations/langchain/test_langchain.py | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 2d64c22325..3dec48c7f1 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -641,6 +641,13 @@ def on_tool_start( SPANDATA.GEN_AI_AGENT_NAME, agent_metadata["lc_agent_name"] ) + run_name = kwargs.get("name") + if run_name is not None: + span.set_data( + SPANDATA.GEN_AI_PIPELINE_NAME, + run_name, + ) + if should_send_default_pii() and self.include_prompts: set_data_normalized( span, diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index 0f8b5bed51..029bfa7986 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -220,6 +220,33 @@ def test_langchain_chat( assert chat_spans[0]["data"]["gen_ai.pipeline.name"] == "my-snazzy-pipeline" +def test_langchain_tool( + sentry_init, + capture_events, +): + sentry_init( + integrations=[ + LangchainIntegration( + include_prompts=True, + ) + ], + traces_sample_rate=1.0, + send_default_pii=True, + ) + events = capture_events() + + with start_transaction(): + get_word_length.invoke( + {"word": "eudca"}, + config={"run_name": "my-snazzy-pipeline"}, + ) + + tx = events[0] + tool_spans = list(x for x in tx["spans"] if x["op"] == "gen_ai.execute_tool") + assert len(tool_spans) == 1 + assert tool_spans[0]["data"]["gen_ai.pipeline.name"] == "my-snazzy-pipeline" + + @pytest.mark.skipif( LANGCHAIN_VERSION < (1,), reason="LangChain 1.0+ required (ONE AGENT refactor)", From 471260ede3f805c1c66b3d38ba42c890bbfb91de Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Tue, 31 Mar 2026 15:26:00 +0200 Subject: [PATCH 2/3] truthy check --- sentry_sdk/integrations/langchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 3dec48c7f1..54c90172fb 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -642,7 +642,7 @@ def on_tool_start( ) run_name = kwargs.get("name") - if run_name is not None: + if run_name: span.set_data( SPANDATA.GEN_AI_PIPELINE_NAME, run_name, From 848797a18da1d52b4359d7f2d5694c5348d221b5 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Wed, 1 Apr 2026 11:21:53 +0200 Subject: [PATCH 3/3] update test name --- tests/integrations/langchain/test_langchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index e7edd645f2..a711ef0c7b 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -223,7 +223,7 @@ def test_langchain_chat( assert chat_spans[0]["data"]["gen_ai.pipeline.name"] == "my-snazzy-pipeline" -def test_langchain_tool( +def test_langchain_tool_call_with_run_name( sentry_init, capture_events, ):