Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions sentry_sdk/integrations/langgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class LanggraphIntegration(Integration):
identifier = "langgraph"
origin = f"auto.ai.{identifier}"

def __init__(self: "LanggraphIntegration", include_prompts: bool = True) -> None:
self.include_prompts = include_prompts

@staticmethod
def setup_once() -> None:
version = package_version("langgraph")
Expand All @@ -60,7 +57,7 @@ def _should_record_inputs(integration: "LanggraphIntegration") -> bool:
return bool(client.options["data_collection"]["gen_ai"]["inputs"])

# To remove once data collection has been fully rolled out
return should_send_default_pii() and integration.include_prompts
return should_send_default_pii()


def _should_record_outputs(integration: "LanggraphIntegration") -> bool:
Expand All @@ -69,7 +66,7 @@ def _should_record_outputs(integration: "LanggraphIntegration") -> bool:
return bool(client.options["data_collection"]["gen_ai"]["outputs"])

# To remove once data collection has been fully rolled out
return should_send_default_pii() and integration.include_prompts
return should_send_default_pii()


def _get_graph_name(graph_obj: "Any") -> "Optional[str]":
Expand Down
49 changes: 12 additions & 37 deletions tests/integrations/langgraph/test_langgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,37 +137,18 @@ def _generate(self, messages, stop=None, run_manager=None, **kwargs) -> ChatResu
raise GraphBubbleUp("interrupt")


def test_langgraph_integration_init():
"""Test LanggraphIntegration initialization with different parameters."""
integration = LanggraphIntegration()
assert integration.include_prompts is True
assert integration.identifier == "langgraph"
assert integration.origin == "auto.ai.langgraph"

integration = LanggraphIntegration(include_prompts=False)
assert integration.include_prompts is False
assert integration.identifier == "langgraph"
assert integration.origin == "auto.ai.langgraph"


@pytest.mark.parametrize(
"send_default_pii, include_prompts",
[
(True, True),
(True, False),
(False, True),
(False, False),
],
"send_default_pii",
[True, False],
)
def test_pregel_invoke(
sentry_init,
capture_items,
send_default_pii,
include_prompts,
):
"""Test Pregel.invoke() wrapper creates proper invoke_agent span."""
sentry_init(
integrations=[LanggraphIntegration(include_prompts=include_prompts)],
integrations=[LanggraphIntegration()],
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
)
Expand Down Expand Up @@ -224,7 +205,7 @@ def original_invoke(self, *args, **kwargs):
assert invoke_span["attributes"][SPANDATA.GEN_AI_PIPELINE_NAME] == "test_graph"
assert invoke_span["attributes"][SPANDATA.GEN_AI_AGENT_NAME] == "test_graph"

if send_default_pii and include_prompts:
if send_default_pii:
assert SPANDATA.GEN_AI_REQUEST_MESSAGES in invoke_span["attributes"]
assert SPANDATA.GEN_AI_RESPONSE_TEXT in invoke_span["attributes"]

Expand Down Expand Up @@ -257,23 +238,17 @@ def original_invoke(self, *args, **kwargs):


@pytest.mark.parametrize(
"send_default_pii, include_prompts",
[
(True, True),
(True, False),
(False, True),
(False, False),
],
"send_default_pii",
[True, False],
)
def test_pregel_ainvoke(
sentry_init,
capture_items,
send_default_pii,
include_prompts,
):
"""Test Pregel.ainvoke() async wrapper creates proper invoke_agent span."""
sentry_init(
integrations=[LanggraphIntegration(include_prompts=include_prompts)],
integrations=[LanggraphIntegration()],
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
)
Expand Down Expand Up @@ -327,7 +302,7 @@ async def run_test():
assert invoke_span["attributes"][SPANDATA.GEN_AI_PIPELINE_NAME] == "async_graph"
assert invoke_span["attributes"][SPANDATA.GEN_AI_AGENT_NAME] == "async_graph"

if send_default_pii and include_prompts:
if send_default_pii:
assert SPANDATA.GEN_AI_REQUEST_MESSAGES in invoke_span["attributes"]
assert SPANDATA.GEN_AI_RESPONSE_TEXT in invoke_span["attributes"]

Expand Down Expand Up @@ -357,7 +332,7 @@ def test_pregel_invoke_error(
):
"""Test error handling during graph execution."""
sentry_init(
integrations=[LanggraphIntegration(include_prompts=True)],
integrations=[LanggraphIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
)
Expand Down Expand Up @@ -393,7 +368,7 @@ def test_pregel_ainvoke_error(
):
"""Test error handling during async graph execution."""
sentry_init(
integrations=[LanggraphIntegration(include_prompts=True)],
integrations=[LanggraphIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
)
Expand Down Expand Up @@ -526,7 +501,7 @@ def test_extraction_functions_complex_scenario(
):
"""Test extraction functions with complex scenarios including multiple messages and edge cases."""
sentry_init(
integrations=[LanggraphIntegration(include_prompts=True)],
integrations=[LanggraphIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
)
Expand Down Expand Up @@ -605,7 +580,7 @@ def test_langgraph_message_role_mapping(
):
"""Test that Langgraph integration properly maps message roles like 'ai' to 'assistant'"""
sentry_init(
integrations=[LanggraphIntegration(include_prompts=True)],
integrations=[LanggraphIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
)
Expand Down
Loading