Skip to content

Commit 638e1b4

Browse files
committed
add test
1 parent a83aa6f commit 638e1b4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/integrations/langchain/test_langchain.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,57 @@ def test_langchain_callback_list_existing_callback(sentry_init):
589589

590590
[handler] = passed_callbacks
591591
assert handler is sentry_callback
592+
593+
594+
def test_tools_integration_in_spans(sentry_init, capture_events):
595+
"""Test that tools are properly set on spans in actual LangChain integration."""
596+
sentry_init(
597+
integrations=[LangchainIntegration(include_prompts=False)],
598+
traces_sample_rate=1.0,
599+
)
600+
events = capture_events()
601+
602+
# Create a simple mock LLM that supports tools
603+
from langchain_core.language_models.llms import LLM
604+
605+
class MockLLMWithTools(LLM):
606+
def _call(self, prompt, stop=None, run_manager=None, **kwargs):
607+
return "Mock response"
608+
609+
@property
610+
def _llm_type(self):
611+
return "mock_llm"
612+
613+
# Mock tools for testing
614+
test_tools = [
615+
{"name": "search", "description": "Search tool"},
616+
{"name": "calculator", "description": "Math tool"},
617+
]
618+
619+
with start_transaction():
620+
llm = MockLLMWithTools()
621+
# Simulate a call with tools
622+
llm.invoke("test prompt", config={"tools": test_tools})
623+
624+
# Check that events were captured
625+
if events:
626+
tx = events[0]
627+
spans = tx.get("spans", [])
628+
629+
# Look for spans that should have tools data
630+
for span in spans:
631+
span_data = span.get("data", {})
632+
if SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS in span_data:
633+
tools_data = span_data[SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS]
634+
# Verify tools are in the expected format
635+
assert isinstance(tools_data, (str, list)) # Could be serialized
636+
if isinstance(tools_data, str):
637+
# If serialized as string, should contain tool names
638+
assert "search" in tools_data
639+
assert "calculator" in tools_data
640+
else:
641+
# If still a list, verify structure
642+
assert len(tools_data) == 2
643+
names = [tool.get("name") for tool in tools_data]
644+
assert "search" in names
645+
assert "calculator" in names

0 commit comments

Comments
 (0)