@@ -173,7 +173,15 @@ def test_start_model_invoke_span_latest_conventions(mock_tracer):
173173 mock_span = mock .MagicMock ()
174174 mock_tracer .start_span .return_value = mock_span
175175
176- messages = [{"role" : "user" , "content" : [{"text" : "Hello" }]}]
176+ messages = [
177+ {"role" : "user" , "content" : [{"text" : "Hello 2025-1993" }]},
178+ {
179+ "role" : "assistant" ,
180+ "content" : [
181+ {"toolUse" : {"input" : '"expression": "2025-1993"' , "name" : "calculator" , "toolUseId" : "123" }}
182+ ],
183+ },
184+ ]
177185 model_id = "test-model"
178186
179187 span = tracer .start_model_invoke_span (messages = messages , agent_name = "TestAgent" , model_id = model_id )
@@ -191,8 +199,19 @@ def test_start_model_invoke_span_latest_conventions(mock_tracer):
191199 [
192200 {
193201 "role" : messages [0 ]["role" ],
194- "parts" : [{"type" : "text" , "content" : messages [0 ]["content" ]}],
195- }
202+ "parts" : [{"type" : "text" , "content" : "Hello 2025-1993" }],
203+ },
204+ {
205+ "role" : messages [1 ]["role" ],
206+ "parts" : [
207+ {
208+ "type" : "tool_call" ,
209+ "name" : "calculator" ,
210+ "id" : "123" ,
211+ "arguments" : '"expression": "2025-1993"' ,
212+ }
213+ ],
214+ },
196215 ]
197216 )
198217 },
@@ -215,8 +234,6 @@ def test_end_model_invoke_span(mock_span):
215234 mock_span .set_attribute .assert_any_call ("gen_ai.usage.completion_tokens" , 20 )
216235 mock_span .set_attribute .assert_any_call ("gen_ai.usage.output_tokens" , 20 )
217236 mock_span .set_attribute .assert_any_call ("gen_ai.usage.total_tokens" , 30 )
218- mock_span .set_attribute .assert_any_call ("gen_ai.usage.cache_read_input_tokens" , 0 )
219- mock_span .set_attribute .assert_any_call ("gen_ai.usage.cache_write_input_tokens" , 0 )
220237 mock_span .set_attribute .assert_any_call ("gen_ai.server.request.duration" , 20 )
221238 mock_span .set_attribute .assert_any_call ("gen_ai.server.time_to_first_token" , 10 )
222239 mock_span .add_event .assert_called_with (
@@ -244,8 +261,6 @@ def test_end_model_invoke_span_latest_conventions(mock_span):
244261 mock_span .set_attribute .assert_any_call ("gen_ai.usage.completion_tokens" , 20 )
245262 mock_span .set_attribute .assert_any_call ("gen_ai.usage.output_tokens" , 20 )
246263 mock_span .set_attribute .assert_any_call ("gen_ai.usage.total_tokens" , 30 )
247- mock_span .set_attribute .assert_any_call ("gen_ai.usage.cache_read_input_tokens" , 0 )
248- mock_span .set_attribute .assert_any_call ("gen_ai.usage.cache_write_input_tokens" , 0 )
249264 mock_span .set_attribute .assert_any_call ("gen_ai.server.time_to_first_token" , 10 )
250265 mock_span .set_attribute .assert_any_call ("gen_ai.server.request.duration" , 20 )
251266 mock_span .add_event .assert_called_with (
@@ -255,7 +270,7 @@ def test_end_model_invoke_span_latest_conventions(mock_span):
255270 [
256271 {
257272 "role" : "assistant" ,
258- "parts" : [{"type" : "text" , "content" : message [ "content" ] }],
273+ "parts" : [{"type" : "text" , "content" : "Response" }],
259274 "finish_reason" : "end_turn" ,
260275 }
261276 ]
@@ -324,7 +339,7 @@ def test_start_tool_call_span_latest_conventions(mock_tracer):
324339 "type" : "tool_call" ,
325340 "name" : tool ["name" ],
326341 "id" : tool ["toolUseId" ],
327- "arguments" : [{ "content" : tool ["input" ]} ],
342+ "arguments" : tool ["input" ],
328343 }
329344 ],
330345 }
@@ -404,7 +419,7 @@ def test_start_swarm_span_with_contentblock_task_latest_conventions(mock_tracer)
404419 "gen_ai.client.inference.operation.details" ,
405420 attributes = {
406421 "gen_ai.input.messages" : serialize (
407- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : [{ "text" : " Original Task: foo bar"}] }]}]
422+ [{"role" : "user" , "parts" : [{"type" : "text" , "content" : " Original Task: foo bar" }]}]
408423 )
409424 },
410425 )
@@ -492,7 +507,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
492507 """Test ending a tool call span with the latest semantic conventions."""
493508 tracer = Tracer ()
494509 tracer .use_latest_genai_conventions = True
495- tool_result = {"status" : "success" , "content" : [{"text" : "Tool result" }]}
510+ tool_result = {"status" : "success" , "content" : [{"text" : "Tool result" }, { "json" : { "foo" : "bar" }} ]}
496511
497512 tracer .end_tool_call_span (mock_span , tool_result )
498513
@@ -508,7 +523,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
508523 {
509524 "type" : "tool_call_response" ,
510525 "id" : tool_result .get ("toolUseId" , "" ),
511- "result " : tool_result .get ("content" ),
526+ "response " : tool_result .get ("content" ),
512527 }
513528 ],
514529 }
@@ -564,9 +579,7 @@ def test_start_event_loop_cycle_span_latest_conventions(mock_tracer):
564579 mock_span .add_event .assert_any_call (
565580 "gen_ai.client.inference.operation.details" ,
566581 attributes = {
567- "gen_ai.input.messages" : serialize (
568- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : messages [0 ]["content" ]}]}]
569- )
582+ "gen_ai.input.messages" : serialize ([{"role" : "user" , "parts" : [{"type" : "text" , "content" : "Hello" }]}])
570583 },
571584 )
572585 assert span is not None
@@ -576,7 +589,12 @@ def test_end_event_loop_cycle_span(mock_span):
576589 """Test ending an event loop cycle span."""
577590 tracer = Tracer ()
578591 message = {"role" : "assistant" , "content" : [{"text" : "Response" }]}
579- tool_result_message = {"role" : "assistant" , "content" : [{"toolResult" : {"response" : "Success" }}]}
592+ tool_result_message = {
593+ "role" : "assistant" ,
594+ "content" : [
595+ {"toolResult" : {"toolUseId" : "123" , "status" : "success" , "content" : [{"text" : "Weather is sunny" }]}}
596+ ],
597+ }
580598
581599 tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
582600
@@ -596,7 +614,12 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
596614 tracer = Tracer ()
597615 tracer .use_latest_genai_conventions = True
598616 message = {"role" : "assistant" , "content" : [{"text" : "Response" }]}
599- tool_result_message = {"role" : "assistant" , "content" : [{"toolResult" : {"response" : "Success" }}]}
617+ tool_result_message = {
618+ "role" : "assistant" ,
619+ "content" : [
620+ {"toolResult" : {"toolUseId" : "123" , "status" : "success" , "content" : [{"text" : "Weather is sunny" }]}}
621+ ],
622+ }
600623
601624 tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
602625
@@ -607,7 +630,13 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
607630 [
608631 {
609632 "role" : "assistant" ,
610- "parts" : [{"type" : "text" , "content" : tool_result_message ["content" ]}],
633+ "parts" : [
634+ {
635+ "type" : "tool_call_response" ,
636+ "id" : "123" ,
637+ "response" : [{"text" : "Weather is sunny" }],
638+ }
639+ ],
611640 }
612641 ]
613642 )
@@ -682,7 +711,7 @@ def test_start_agent_span_latest_conventions(mock_tracer):
682711 "gen_ai.client.inference.operation.details" ,
683712 attributes = {
684713 "gen_ai.input.messages" : serialize (
685- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : [{ "text" : " test prompt"}] }]}]
714+ [{"role" : "user" , "parts" : [{"type" : "text" , "content" : " test prompt" }]}]
686715 )
687716 },
688717 )
0 commit comments