|
17 | 17 | from langchain_core.outputs import ChatGenerationChunk
|
18 | 18 |
|
19 | 19 | from sentry_sdk import start_transaction
|
20 |
| -from sentry_sdk.integrations.langchain import LangchainIntegration |
| 20 | +from sentry_sdk.integrations.langchain import ( |
| 21 | + LangchainIntegration, |
| 22 | + SentryLangchainCallback, |
| 23 | +) |
21 | 24 | from langchain.agents import tool, AgentExecutor, create_openai_tools_agent
|
22 | 25 | from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
23 | 26 |
|
@@ -342,3 +345,22 @@ def test_span_origin(sentry_init, capture_events):
|
342 | 345 | assert event["contexts"]["trace"]["origin"] == "manual"
|
343 | 346 | for span in event["spans"]:
|
344 | 347 | assert span["origin"] == "auto.ai.langchain"
|
| 348 | + |
| 349 | + |
| 350 | +def test_span_map_is_instance_variable(): |
| 351 | + """Test that each SentryLangchainCallback instance has its own span_map.""" |
| 352 | + # Create two separate callback instances |
| 353 | + callback1 = SentryLangchainCallback(max_span_map_size=100, include_prompts=True) |
| 354 | + callback2 = SentryLangchainCallback(max_span_map_size=100, include_prompts=True) |
| 355 | + |
| 356 | + # Verify they have different span_map instances |
| 357 | + assert ( |
| 358 | + callback1.span_map is not callback2.span_map |
| 359 | + ), "span_map should be an instance variable, not shared between instances" |
| 360 | + |
| 361 | + |
| 362 | +def test_span_map_not_class_attribute(): |
| 363 | + """Test that span_map is not accessible as a class attribute.""" |
| 364 | + # This should raise AttributeError if span_map is properly an instance variable |
| 365 | + with pytest.raises(AttributeError): |
| 366 | + SentryLangchainCallback.span_map |
0 commit comments