@@ -263,10 +263,10 @@ async def test_handoff_span(sentry_init, capture_events, mock_usage):
263
263
264
264
(transaction ,) = events
265
265
spans = transaction ["spans" ]
266
- handoff_span = spans [2 ]
267
266
268
- # Verify handoff span was created
269
- assert handoff_span is not None
267
+ # There should be exactly one handoff span
268
+ (handoff_span ,) = [span for span in spans if span ["op" ] == "gen_ai.handoff" ]
269
+
270
270
assert (
271
271
handoff_span ["description" ] == "handoff from primary_agent to secondary_agent"
272
272
)
@@ -354,12 +354,25 @@ def simple_test_tool(message: str) -> str:
354
354
355
355
(transaction ,) = events
356
356
spans = transaction ["spans" ]
357
- (
358
- agent_span ,
359
- ai_client_span1 ,
360
- tool_span ,
361
- ai_client_span2 ,
362
- ) = spans
357
+
358
+ assert len (spans ) == 4
359
+
360
+ # Find each span by its characteristics
361
+ agent_span = next (s for s in spans if s ["description" ] == "invoke_agent test_agent" )
362
+ tool_span = next (
363
+ s for s in spans if s ["description" ] == "execute_tool simple_test_tool"
364
+ )
365
+ ai_client_span1 = next (
366
+ s
367
+ for s in spans
368
+ if s ["description" ] == "chat gpt-4"
369
+ and "gen_ai.response.tool_calls" in s ["data" ]
370
+ )
371
+ ai_client_span2 = next (
372
+ s
373
+ for s in spans
374
+ if s ["description" ] == "chat gpt-4" and "gen_ai.response.text" in s ["data" ]
375
+ )
363
376
364
377
available_tools = safe_serialize (
365
378
[
@@ -383,7 +396,6 @@ def simple_test_tool(message: str) -> str:
383
396
assert transaction ["transaction" ] == "test_agent workflow"
384
397
assert transaction ["contexts" ]["trace" ]["origin" ] == "auto.ai.openai_agents"
385
398
386
- assert agent_span ["description" ] == "invoke_agent test_agent"
387
399
assert agent_span ["origin" ] == "auto.ai.openai_agents"
388
400
assert agent_span ["data" ]["gen_ai.agent.name" ] == "test_agent"
389
401
assert agent_span ["data" ]["gen_ai.operation.name" ] == "invoke_agent"
@@ -394,7 +406,6 @@ def simple_test_tool(message: str) -> str:
394
406
assert agent_span ["data" ]["gen_ai.request.top_p" ] == 1.0
395
407
assert agent_span ["data" ]["gen_ai.system" ] == "openai"
396
408
397
- assert ai_client_span1 ["description" ] == "chat gpt-4"
398
409
assert ai_client_span1 ["data" ]["gen_ai.operation.name" ] == "chat"
399
410
assert ai_client_span1 ["data" ]["gen_ai.system" ] == "openai"
400
411
assert ai_client_span1 ["data" ]["gen_ai.agent.name" ] == "test_agent"
@@ -442,7 +453,6 @@ def simple_test_tool(message: str) -> str:
442
453
]
443
454
)
444
455
445
- assert tool_span ["description" ] == "execute_tool simple_test_tool"
446
456
assert tool_span ["data" ]["gen_ai.agent.name" ] == "test_agent"
447
457
assert tool_span ["data" ]["gen_ai.operation.name" ] == "execute_tool"
448
458
assert (
@@ -464,7 +474,6 @@ def simple_test_tool(message: str) -> str:
464
474
assert tool_span ["data" ]["gen_ai.tool.output" ] == "Tool executed with: hello"
465
475
assert tool_span ["data" ]["gen_ai.tool.type" ] == "function"
466
476
467
- assert ai_client_span2 ["description" ] == "chat gpt-4"
468
477
assert ai_client_span2 ["data" ]["gen_ai.agent.name" ] == "test_agent"
469
478
assert ai_client_span2 ["data" ]["gen_ai.operation.name" ] == "chat"
470
479
assert (
0 commit comments