@@ -214,11 +214,17 @@ def test_langchain_agent(
214214
215215 tx = events [0 ]
216216 assert tx ["type" ] == "transaction"
217+ assert tx ["contexts" ]["trace" ]["origin" ] == "manual"
218+
217219 chat_spans = list (x for x in tx ["spans" ] if x ["op" ] == "gen_ai.chat" )
218220 tool_exec_span = next (x for x in tx ["spans" ] if x ["op" ] == "gen_ai.execute_tool" )
219221
220222 assert len (chat_spans ) == 2
221223
224+ assert chat_spans [0 ]["origin" ] == "auto.ai.langchain"
225+ assert chat_spans [1 ]["origin" ] == "auto.ai.langchain"
226+ assert tool_exec_span ["origin" ] == "auto.ai.langchain"
227+
222228 # We can't guarantee anything about the "shape" of the langchain execution graph
223229 assert len (list (x for x in tx ["spans" ] if x ["op" ] == "gen_ai.chat" )) > 0
224230
@@ -409,122 +415,6 @@ def test_span_status_error(sentry_init, capture_events):
409415 assert transaction ["contexts" ]["trace" ]["status" ] == "internal_error"
410416
411417
412- def test_span_origin (sentry_init , capture_events ):
413- sentry_init (
414- integrations = [LangchainIntegration ()],
415- traces_sample_rate = 1.0 ,
416- )
417- events = capture_events ()
418-
419- prompt = ChatPromptTemplate .from_messages (
420- [
421- (
422- "system" ,
423- "You are very powerful assistant, but don't know current events" ,
424- ),
425- ("user" , "{input}" ),
426- MessagesPlaceholder (variable_name = "agent_scratchpad" ),
427- ]
428- )
429- global stream_result_mock
430- stream_result_mock = Mock (
431- side_effect = [
432- [
433- ChatGenerationChunk (
434- type = "ChatGenerationChunk" ,
435- message = AIMessageChunk (
436- content = "" ,
437- additional_kwargs = {
438- "tool_calls" : [
439- {
440- "index" : 0 ,
441- "id" : "call_BbeyNhCKa6kYLYzrD40NGm3b" ,
442- "function" : {
443- "arguments" : "" ,
444- "name" : "get_word_length" ,
445- },
446- "type" : "function" ,
447- }
448- ]
449- },
450- ),
451- ),
452- ChatGenerationChunk (
453- type = "ChatGenerationChunk" ,
454- message = AIMessageChunk (
455- content = "" ,
456- additional_kwargs = {
457- "tool_calls" : [
458- {
459- "index" : 0 ,
460- "id" : None ,
461- "function" : {
462- "arguments" : '{"word": "eudca"}' ,
463- "name" : None ,
464- },
465- "type" : None ,
466- }
467- ]
468- },
469- ),
470- ),
471- ChatGenerationChunk (
472- type = "ChatGenerationChunk" ,
473- message = AIMessageChunk (
474- content = "5" ,
475- usage_metadata = {
476- "input_tokens" : 142 ,
477- "output_tokens" : 50 ,
478- "total_tokens" : 192 ,
479- "input_token_details" : {"audio" : 0 , "cache_read" : 0 },
480- "output_token_details" : {"audio" : 0 , "reasoning" : 0 },
481- },
482- ),
483- generation_info = {"finish_reason" : "function_call" },
484- ),
485- ],
486- [
487- ChatGenerationChunk (
488- text = "The word eudca has 5 letters." ,
489- type = "ChatGenerationChunk" ,
490- message = AIMessageChunk (
491- content = "The word eudca has 5 letters." ,
492- usage_metadata = {
493- "input_tokens" : 89 ,
494- "output_tokens" : 28 ,
495- "total_tokens" : 117 ,
496- "input_token_details" : {"audio" : 0 , "cache_read" : 0 },
497- "output_token_details" : {"audio" : 0 , "reasoning" : 0 },
498- },
499- ),
500- ),
501- ChatGenerationChunk (
502- type = "ChatGenerationChunk" ,
503- generation_info = {"finish_reason" : "stop" },
504- message = AIMessageChunk (content = "" ),
505- ),
506- ],
507- ]
508- )
509- llm = MockOpenAI (
510- model_name = "gpt-3.5-turbo" ,
511- temperature = 0 ,
512- openai_api_key = "badkey" ,
513- )
514- agent = create_openai_tools_agent (llm , [get_word_length ], prompt )
515-
516- agent_executor = AgentExecutor (agent = agent , tools = [get_word_length ], verbose = True )
517-
518- with start_transaction ():
519- list (agent_executor .stream ({"input" : "How many letters in the word eudca" }))
520-
521- (event ,) = events
522-
523- assert event ["contexts" ]["trace" ]["origin" ] == "manual"
524- for span in event ["spans" ]:
525- assert span ["origin" ] == "auto.ai.langchain"
526-
527-
528418def test_manual_callback_no_duplication (sentry_init ):
529419 """
530420 Test that when a user manually provides a SentryLangchainCallback,
0 commit comments