File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
instrumentation/opentelemetry-instrumentation-asyncio
src/opentelemetry/instrumentation/asyncio Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131 ([ #2589 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2589 ) )
3232- ` opentelemetry-instrumentation-celery ` propagates baggage
3333 ([ #2385 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2385 ) )
34+ - ` opentelemetry-instrumentation-asyncio ` Fixes async generator coroutines not being awaited
35+ ([ #2792 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2792 ) )
3436
3537## Version 1.26.0/0.47b0 (2024-07-23)
3638
Original file line number Diff line number Diff line change @@ -262,7 +262,7 @@ def trace_item(self, coro_or_future):
262262
263263 async def trace_coroutine (self , coro ):
264264 if not hasattr (coro , "__name__" ):
265- return coro
265+ return await coro
266266 start = default_timer ()
267267 attr = {
268268 "type" : "coroutine" ,
Original file line number Diff line number Diff line change @@ -43,19 +43,23 @@ def tearDown(self):
4343
4444 # Asyncio anext() does not have __name__ attribute, which is used to determine if the coroutine should be traced.
4545 # This test is to ensure that the instrumentation does not break when the coroutine does not have __name__ attribute.
46+ # Additionally, ensure the coroutine is actually awaited.
4647 @skipIf (
4748 sys .version_info < (3 , 10 ), "anext is only available in Python 3.10+"
4849 )
4950 def test_asyncio_anext (self ):
5051 async def main ():
5152 async def async_gen ():
52- for it in range (2 ):
53+ # nothing special about this range other than to avoid returning a zero
54+ # from a function named 'main' (which might cause confusion about intent)
55+ for it in range (2 , 4 ):
5356 yield it
5457
5558 async_gen_instance = async_gen ()
5659 agen = anext (async_gen_instance )
57- await asyncio .create_task (agen )
60+ return await asyncio .create_task (agen )
5861
59- asyncio .run (main ())
62+ ret = asyncio .run (main ())
63+ self .assertEqual (ret , 2 ) # first iteration from range()
6064 spans = self .memory_exporter .get_finished_spans ()
6165 self .assertEqual (len (spans ), 0 )
You can’t perform that action at this time.
0 commit comments