9
9
10
10
from .fake_model import FakeModel
11
11
from .test_responses import get_text_message
12
- from .testing_processor import assert_no_traces , fetch_normalized_spans , fetch_traces
12
+ from .testing_processor import assert_no_traces , fetch_normalized_spans
13
13
14
14
15
15
@pytest .mark .asyncio
@@ -193,16 +193,29 @@ async def test_trace_config_works():
193
193
await Runner .run (
194
194
agent ,
195
195
input = "first_test" ,
196
- run_config = RunConfig (workflow_name = "Foo bar" , group_id = "123" , trace_id = "456 " ),
196
+ run_config = RunConfig (workflow_name = "Foo bar" , group_id = "123" , trace_id = "trace_456 " ),
197
197
)
198
198
199
- traces = fetch_traces ()
200
- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
201
- export = traces [0 ].export ()
202
- assert export is not None , "Trace export should not be None"
203
- assert export ["workflow_name" ] == "Foo bar"
204
- assert export ["group_id" ] == "123"
205
- assert export ["id" ] == "456"
199
+ assert fetch_normalized_spans (keep_trace_id = True ) == snapshot (
200
+ [
201
+ {
202
+ "id" : "trace_456" ,
203
+ "workflow_name" : "Foo bar" ,
204
+ "group_id" : "123" ,
205
+ "children" : [
206
+ {
207
+ "type" : "agent" ,
208
+ "data" : {
209
+ "name" : "test_agent" ,
210
+ "handoffs" : [],
211
+ "tools" : [],
212
+ "output_type" : "str" ,
213
+ },
214
+ }
215
+ ],
216
+ }
217
+ ]
218
+ )
206
219
207
220
208
221
@pytest .mark .asyncio
@@ -259,8 +272,24 @@ async def test_streaming_single_run_is_single_trace():
259
272
async for _ in x .stream_events ():
260
273
pass
261
274
262
- traces = fetch_traces ()
263
- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
275
+ assert fetch_normalized_spans () == snapshot (
276
+ [
277
+ {
278
+ "workflow_name" : "Agent workflow" ,
279
+ "children" : [
280
+ {
281
+ "type" : "agent" ,
282
+ "data" : {
283
+ "name" : "test_agent" ,
284
+ "handoffs" : [],
285
+ "tools" : [],
286
+ "output_type" : "str" ,
287
+ },
288
+ }
289
+ ],
290
+ }
291
+ ]
292
+ )
264
293
265
294
266
295
@pytest .mark .asyncio
@@ -285,8 +314,38 @@ async def test_multiple_streamed_runs_are_multiple_traces():
285
314
async for _ in x .stream_events ():
286
315
pass
287
316
288
- traces = fetch_traces ()
289
- assert len (traces ) == 2 , f"Expected 2 traces, got { len (traces )} "
317
+ assert fetch_normalized_spans () == snapshot (
318
+ [
319
+ {
320
+ "workflow_name" : "Agent workflow" ,
321
+ "children" : [
322
+ {
323
+ "type" : "agent" ,
324
+ "data" : {
325
+ "name" : "test_agent_1" ,
326
+ "handoffs" : [],
327
+ "tools" : [],
328
+ "output_type" : "str" ,
329
+ },
330
+ }
331
+ ],
332
+ },
333
+ {
334
+ "workflow_name" : "Agent workflow" ,
335
+ "children" : [
336
+ {
337
+ "type" : "agent" ,
338
+ "data" : {
339
+ "name" : "test_agent_1" ,
340
+ "handoffs" : [],
341
+ "tools" : [],
342
+ "output_type" : "str" ,
343
+ },
344
+ }
345
+ ],
346
+ },
347
+ ]
348
+ )
290
349
291
350
292
351
@pytest .mark .asyncio
@@ -317,8 +376,42 @@ async def test_wrapped_streaming_trace_is_single_trace():
317
376
async for _ in x .stream_events ():
318
377
pass
319
378
320
- traces = fetch_traces ()
321
- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
379
+ assert fetch_normalized_spans () == snapshot (
380
+ [
381
+ {
382
+ "workflow_name" : "test_workflow" ,
383
+ "children" : [
384
+ {
385
+ "type" : "agent" ,
386
+ "data" : {
387
+ "name" : "test_agent_1" ,
388
+ "handoffs" : [],
389
+ "tools" : [],
390
+ "output_type" : "str" ,
391
+ },
392
+ },
393
+ {
394
+ "type" : "agent" ,
395
+ "data" : {
396
+ "name" : "test_agent_1" ,
397
+ "handoffs" : [],
398
+ "tools" : [],
399
+ "output_type" : "str" ,
400
+ },
401
+ },
402
+ {
403
+ "type" : "agent" ,
404
+ "data" : {
405
+ "name" : "test_agent_1" ,
406
+ "handoffs" : [],
407
+ "tools" : [],
408
+ "output_type" : "str" ,
409
+ },
410
+ },
411
+ ],
412
+ }
413
+ ]
414
+ )
322
415
323
416
324
417
@pytest .mark .asyncio
@@ -347,8 +440,42 @@ async def test_wrapped_mixed_trace_is_single_trace():
347
440
async for _ in x .stream_events ():
348
441
pass
349
442
350
- traces = fetch_traces ()
351
- assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
443
+ assert fetch_normalized_spans () == snapshot (
444
+ [
445
+ {
446
+ "workflow_name" : "test_workflow" ,
447
+ "children" : [
448
+ {
449
+ "type" : "agent" ,
450
+ "data" : {
451
+ "name" : "test_agent_1" ,
452
+ "handoffs" : [],
453
+ "tools" : [],
454
+ "output_type" : "str" ,
455
+ },
456
+ },
457
+ {
458
+ "type" : "agent" ,
459
+ "data" : {
460
+ "name" : "test_agent_1" ,
461
+ "handoffs" : [],
462
+ "tools" : [],
463
+ "output_type" : "str" ,
464
+ },
465
+ },
466
+ {
467
+ "type" : "agent" ,
468
+ "data" : {
469
+ "name" : "test_agent_1" ,
470
+ "handoffs" : [],
471
+ "tools" : [],
472
+ "output_type" : "str" ,
473
+ },
474
+ },
475
+ ],
476
+ }
477
+ ]
478
+ )
352
479
353
480
354
481
@pytest .mark .asyncio
0 commit comments