@@ -85,45 +85,12 @@ def test_auto_trace_sample(exporter: TestExporter) -> None:
8585 'logfire.pending_parent_id' : '0000000000000001' ,
8686 },
8787 },
88- {
89- 'name' : 'Calling tests.auto_trace_samples.foo.gen (pending)' ,
90- 'context' : {'trace_id' : 1 , 'span_id' : 6 , 'is_remote' : False },
91- 'parent' : {'trace_id' : 1 , 'span_id' : 5 , 'is_remote' : False },
92- 'start_time' : 3000000000 ,
93- 'end_time' : 3000000000 ,
94- 'attributes' : {
95- 'code.filepath' : 'foo.py' ,
96- 'code.lineno' : 123 ,
97- 'code.function' : 'gen' ,
98- 'logfire.msg_template' : 'Calling tests.auto_trace_samples.foo.gen' ,
99- 'logfire.msg' : 'Calling tests.auto_trace_samples.foo.gen' ,
100- 'logfire.span_type' : 'pending_span' ,
101- 'logfire.tags' : ('auto-trace' ,),
102- 'logfire.pending_parent_id' : '0000000000000003' ,
103- },
104- },
105- {
106- 'name' : 'Calling tests.auto_trace_samples.foo.gen' ,
107- 'context' : {'trace_id' : 1 , 'span_id' : 5 , 'is_remote' : False },
108- 'parent' : {'trace_id' : 1 , 'span_id' : 3 , 'is_remote' : False },
109- 'start_time' : 3000000000 ,
110- 'end_time' : 4000000000 ,
111- 'attributes' : {
112- 'code.filepath' : 'foo.py' ,
113- 'code.lineno' : 123 ,
114- 'code.function' : 'gen' ,
115- 'logfire.msg_template' : 'Calling tests.auto_trace_samples.foo.gen' ,
116- 'logfire.span_type' : 'span' ,
117- 'logfire.tags' : ('auto-trace' ,),
118- 'logfire.msg' : 'Calling tests.auto_trace_samples.foo.gen' ,
119- },
120- },
12188 {
12289 'name' : 'Calling async_gen via @instrument' ,
12390 'context' : {'trace_id' : 1 , 'span_id' : 3 , 'is_remote' : False },
12491 'parent' : {'trace_id' : 1 , 'span_id' : 1 , 'is_remote' : False },
12592 'start_time' : 2000000000 ,
126- 'end_time' : 5000000000 ,
93+ 'end_time' : 3000000000 ,
12794 'attributes' : {
12895 'code.filepath' : 'foo.py' ,
12996 'code.lineno' : 123 ,
@@ -138,7 +105,7 @@ def test_auto_trace_sample(exporter: TestExporter) -> None:
138105 'context' : {'trace_id' : 1 , 'span_id' : 1 , 'is_remote' : False },
139106 'parent' : None ,
140107 'start_time' : 1000000000 ,
141- 'end_time' : 7000000000 ,
108+ 'end_time' : 5000000000 ,
142109 'attributes' : {
143110 'code.filepath' : 'foo.py' ,
144111 'code.lineno' : 123 ,
@@ -152,7 +119,7 @@ def test_auto_trace_sample(exporter: TestExporter) -> None:
152119 'events' : [
153120 {
154121 'name' : 'exception' ,
155- 'timestamp' : 6000000000 ,
122+ 'timestamp' : 4000000000 ,
156123 'attributes' : {
157124 'exception.type' : 'IndexError' ,
158125 'exception.message' : 'list index out of range' ,
@@ -443,6 +410,26 @@ def test_no_auto_trace():
443410 )
444411
445412
413+ # language=Python
414+ generators_sample = """
415+ def make_gen():
416+ def gen():
417+ async def foo():
418+ async def bar():
419+ pass
420+ yield bar()
421+ yield from foo()
422+ return gen
423+ """
424+
425+
426+ def test_generators ():
427+ assert get_calling_strings (generators_sample ) == {
428+ 'Calling module.name.make_gen' ,
429+ 'Calling module.name.make_gen.<locals>.gen.<locals>.foo.<locals>.bar' ,
430+ }
431+
432+
446433def test_min_duration (exporter : TestExporter ):
447434 install_auto_tracing ('tests.auto_trace_samples.simple_nesting' , min_duration = 5 )
448435
0 commit comments