@@ -173,7 +173,15 @@ def test_start_model_invoke_span_latest_conventions(mock_tracer):
173
173
mock_span = mock .MagicMock ()
174
174
mock_tracer .start_span .return_value = mock_span
175
175
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
+ ]
177
185
model_id = "test-model"
178
186
179
187
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):
191
199
[
192
200
{
193
201
"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
+ },
196
215
]
197
216
)
198
217
},
@@ -215,8 +234,6 @@ def test_end_model_invoke_span(mock_span):
215
234
mock_span .set_attribute .assert_any_call ("gen_ai.usage.completion_tokens" , 20 )
216
235
mock_span .set_attribute .assert_any_call ("gen_ai.usage.output_tokens" , 20 )
217
236
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 )
220
237
mock_span .set_attribute .assert_any_call ("gen_ai.server.request.duration" , 20 )
221
238
mock_span .set_attribute .assert_any_call ("gen_ai.server.time_to_first_token" , 10 )
222
239
mock_span .add_event .assert_called_with (
@@ -244,8 +261,6 @@ def test_end_model_invoke_span_latest_conventions(mock_span):
244
261
mock_span .set_attribute .assert_any_call ("gen_ai.usage.completion_tokens" , 20 )
245
262
mock_span .set_attribute .assert_any_call ("gen_ai.usage.output_tokens" , 20 )
246
263
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 )
249
264
mock_span .set_attribute .assert_any_call ("gen_ai.server.time_to_first_token" , 10 )
250
265
mock_span .set_attribute .assert_any_call ("gen_ai.server.request.duration" , 20 )
251
266
mock_span .add_event .assert_called_with (
@@ -255,7 +270,7 @@ def test_end_model_invoke_span_latest_conventions(mock_span):
255
270
[
256
271
{
257
272
"role" : "assistant" ,
258
- "parts" : [{"type" : "text" , "content" : message [ "content" ] }],
273
+ "parts" : [{"type" : "text" , "content" : "Response" }],
259
274
"finish_reason" : "end_turn" ,
260
275
}
261
276
]
@@ -324,7 +339,7 @@ def test_start_tool_call_span_latest_conventions(mock_tracer):
324
339
"type" : "tool_call" ,
325
340
"name" : tool ["name" ],
326
341
"id" : tool ["toolUseId" ],
327
- "arguments" : [{ "content" : tool ["input" ]} ],
342
+ "arguments" : tool ["input" ],
328
343
}
329
344
],
330
345
}
@@ -404,7 +419,7 @@ def test_start_swarm_span_with_contentblock_task_latest_conventions(mock_tracer)
404
419
"gen_ai.client.inference.operation.details" ,
405
420
attributes = {
406
421
"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" }]}]
408
423
)
409
424
},
410
425
)
@@ -492,7 +507,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
492
507
"""Test ending a tool call span with the latest semantic conventions."""
493
508
tracer = Tracer ()
494
509
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" }} ]}
496
511
497
512
tracer .end_tool_call_span (mock_span , tool_result )
498
513
@@ -508,7 +523,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
508
523
{
509
524
"type" : "tool_call_response" ,
510
525
"id" : tool_result .get ("toolUseId" , "" ),
511
- "result " : tool_result .get ("content" ),
526
+ "response " : tool_result .get ("content" ),
512
527
}
513
528
],
514
529
}
@@ -564,9 +579,7 @@ def test_start_event_loop_cycle_span_latest_conventions(mock_tracer):
564
579
mock_span .add_event .assert_any_call (
565
580
"gen_ai.client.inference.operation.details" ,
566
581
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" }]}])
570
583
},
571
584
)
572
585
assert span is not None
@@ -576,7 +589,12 @@ def test_end_event_loop_cycle_span(mock_span):
576
589
"""Test ending an event loop cycle span."""
577
590
tracer = Tracer ()
578
591
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
+ }
580
598
581
599
tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
582
600
@@ -596,7 +614,12 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
596
614
tracer = Tracer ()
597
615
tracer .use_latest_genai_conventions = True
598
616
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
+ }
600
623
601
624
tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
602
625
@@ -607,7 +630,13 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
607
630
[
608
631
{
609
632
"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
+ ],
611
640
}
612
641
]
613
642
)
@@ -682,7 +711,7 @@ def test_start_agent_span_latest_conventions(mock_tracer):
682
711
"gen_ai.client.inference.operation.details" ,
683
712
attributes = {
684
713
"gen_ai.input.messages" : serialize (
685
- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : [{ "text" : " test prompt"}] }]}]
714
+ [{"role" : "user" , "parts" : [{"type" : "text" , "content" : " test prompt" }]}]
686
715
)
687
716
},
688
717
)
0 commit comments