@@ -69,112 +69,70 @@ async def outer() -> None:
6969 # tracking via ddtrace.profiling._asyncio
7070 assert len (samples ) > 0
7171
72+ # TODO: Currently, we never report Parent Tasks awaiting a Child Task as part of their own.
73+ # This means we never see the 'await asyncio.gather(...)' tagged with Task name "outer"
74+ # because it is always reported as part of the Stack of a Child Task.
75+ # We will fix this in the future.
76+ # pprof_utils.assert_profile_has_sample(
77+ # profile,
78+ # samples,
79+ # expected_sample=pprof_utils.StackEvent(
80+ # thread_name="MainThread",
81+ # task_name="outer",
82+ # span_id=span_id,
83+ # local_root_span_id=local_root_span_id,
84+ # locations=[
85+ # pprof_utils.StackLocation(
86+ # function_name="outer", filename="test_asyncio_gather.py", line_no=outer.__code__.co_firstlineno+3
87+ # ),
88+ # ],
89+ # ),
90+ # )
91+
7292 pprof_utils .assert_profile_has_sample (
7393 profile ,
7494 samples ,
7595 expected_sample = pprof_utils .StackEvent (
7696 thread_name = "MainThread" ,
77- task_name = "outer " ,
97+ task_name = "inner 1 " ,
7898 span_id = span_id ,
7999 local_root_span_id = local_root_span_id ,
80100 locations = [
81101 pprof_utils .StackLocation (
82- function_name = "outer" , filename = "test_asyncio_gather.py" , line_no = outer .__code__ .co_firstlineno + 3
102+ function_name = "inner1" ,
103+ filename = "test_asyncio_gather.py" ,
104+ line_no = inner1 .__code__ .co_firstlineno + 3 ,
105+ ),
106+ pprof_utils .StackLocation (
107+ function_name = "outer" ,
108+ filename = "test_asyncio_gather.py" ,
109+ line_no = outer .__code__ .co_firstlineno + 3 ,
83110 ),
84- # TODO: We should add the locations of the gathered Tasks here as they should be in the same Stack
85111 ],
86112 ),
113+ print_samples_on_failure = True ,
87114 )
88115
89- try :
90- pprof_utils .assert_profile_has_sample (
91- profile ,
92- samples ,
93- expected_sample = pprof_utils .StackEvent (
94- thread_name = "MainThread" ,
95- task_name = "outer" , # TODO: This is a bug and we need to fix it, it should be "inner 1"
96- span_id = span_id ,
97- local_root_span_id = local_root_span_id ,
98- locations = [
99- pprof_utils .StackLocation (
100- function_name = "inner2" ,
101- filename = "test_asyncio_gather.py" ,
102- line_no = inner2 .__code__ .co_firstlineno + 3 ,
103- ),
104- pprof_utils .StackLocation (
105- function_name = "outer" ,
106- filename = "test_asyncio_gather.py" ,
107- line_no = outer .__code__ .co_firstlineno + 3 ,
108- ),
109- ],
110- ),
111- )
112-
113- pprof_utils .assert_profile_has_sample (
114- profile ,
115- samples ,
116- expected_sample = pprof_utils .StackEvent (
117- thread_name = "MainThread" ,
118- task_name = "inner 1" ,
119- span_id = span_id ,
120- local_root_span_id = local_root_span_id ,
121- locations = [
122- pprof_utils .StackLocation (
123- function_name = "inner1" ,
124- filename = "test_asyncio_gather.py" ,
125- line_no = inner1 .__code__ .co_firstlineno + 3 ,
126- ),
127- pprof_utils .StackLocation (
128- function_name = "outer" ,
129- filename = "test_asyncio_gather.py" ,
130- line_no = outer .__code__ .co_firstlineno + 3 ,
131- ),
132- ],
133- ),
134- )
135- except AssertionError :
136- pprof_utils .assert_profile_has_sample (
137- profile ,
138- samples ,
139- expected_sample = pprof_utils .StackEvent (
140- thread_name = "MainThread" ,
141- task_name = "inner 2" , # TODO: This is a bug and we need to fix it, it should be "inner 1"
142- span_id = span_id ,
143- local_root_span_id = local_root_span_id ,
144- locations = [
145- pprof_utils .StackLocation (
146- function_name = "inner2" ,
147- filename = "test_asyncio_gather.py" ,
148- line_no = inner2 .__code__ .co_firstlineno + 3 ,
149- ),
150- pprof_utils .StackLocation (
151- function_name = "outer" ,
152- filename = "test_asyncio_gather.py" ,
153- line_no = outer .__code__ .co_firstlineno + 3 ,
154- ),
155- ],
156- ),
157- )
158-
159- pprof_utils .assert_profile_has_sample (
160- profile ,
161- samples ,
162- expected_sample = pprof_utils .StackEvent (
163- thread_name = "MainThread" ,
164- task_name = "outer" ,
165- span_id = span_id ,
166- local_root_span_id = local_root_span_id ,
167- locations = [
168- pprof_utils .StackLocation (
169- function_name = "inner1" ,
170- filename = "test_asyncio_gather.py" ,
171- line_no = inner1 .__code__ .co_firstlineno + 3 ,
172- ),
173- pprof_utils .StackLocation (
174- function_name = "outer" ,
175- filename = "test_asyncio_gather.py" ,
176- line_no = outer .__code__ .co_firstlineno + 3 ,
177- ),
178- ],
179- ),
180- )
116+ pprof_utils .assert_profile_has_sample (
117+ profile ,
118+ samples ,
119+ expected_sample = pprof_utils .StackEvent (
120+ thread_name = "MainThread" ,
121+ task_name = "inner 2" ,
122+ span_id = span_id ,
123+ local_root_span_id = local_root_span_id ,
124+ locations = [
125+ pprof_utils .StackLocation (
126+ function_name = "inner2" ,
127+ filename = "test_asyncio_gather.py" ,
128+ line_no = inner2 .__code__ .co_firstlineno + 3 ,
129+ ),
130+ pprof_utils .StackLocation (
131+ function_name = "outer" ,
132+ filename = "test_asyncio_gather.py" ,
133+ line_no = outer .__code__ .co_firstlineno + 3 ,
134+ ),
135+ ],
136+ ),
137+ print_samples_on_failure = True ,
138+ )
0 commit comments