@@ -400,10 +400,12 @@ def test_tool_execution_span(
400400 assert tx ["contexts" ]["trace" ]["origin" ] == "manual"
401401
402402 chat_spans = list (x for x in tx ["spans" ] if x ["op" ] == "gen_ai.chat" )
403- tool_exec_span = next (x for x in tx ["spans" ] if x ["op" ] == "gen_ai.execute_tool" )
404-
405403 assert len (chat_spans ) == 2
406404
405+ tool_exec_spans = list (x for x in tx ["spans" ] if x ["op" ] == "gen_ai.execute_tool" )
406+ assert len (tool_exec_spans ) == 1
407+ tool_exec_span = tool_exec_spans [0 ]
408+
407409 assert chat_spans [0 ]["origin" ] == "auto.ai.langchain"
408410 assert chat_spans [1 ]["origin" ] == "auto.ai.langchain"
409411 assert tool_exec_span ["origin" ] == "auto.ai.langchain"
@@ -426,13 +428,8 @@ def test_tool_execution_span(
426428 "Tool calls should be recorded when send_default_pii=True and include_prompts=True"
427429 )
428430 tool_calls_data = chat_spans [0 ]["data" ][SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS ]
429- assert isinstance (tool_calls_data , (list , str )) # Could be serialized
430- if isinstance (tool_calls_data , str ):
431- assert "get_word_length" in tool_calls_data
432- elif isinstance (tool_calls_data , list ) and len (tool_calls_data ) > 0 :
433- # Check if tool calls contain expected function name
434- tool_call_str = str (tool_calls_data )
435- assert "get_word_length" in tool_call_str
431+ assert isinstance (tool_calls_data , str )
432+ assert "get_word_length" in tool_calls_data
436433 else :
437434 assert SPANDATA .GEN_AI_REQUEST_MESSAGES not in chat_spans [0 ].get ("data" , {})
438435 assert SPANDATA .GEN_AI_RESPONSE_TEXT not in chat_spans [0 ].get ("data" , {})
0 commit comments