File tree 3 files changed +10
-4
lines changed
instrumentation/opentelemetry-instrumentation-asyncio
src/opentelemetry/instrumentation/asyncio
3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
29
([ #2589 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2589 ) )
30
30
- ` opentelemetry-instrumentation-celery ` propagates baggage
31
31
([ #2385 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2385 ) )
32
+ - ` opentelemetry-instrumentation-asyncio ` Fixes async generator coroutines not being awaited
33
+ ([ #2792 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2792 ) )
32
34
33
35
## Version 1.26.0/0.47b0 (2024-07-23)
34
36
Original file line number Diff line number Diff line change @@ -262,7 +262,7 @@ def trace_item(self, coro_or_future):
262
262
263
263
async def trace_coroutine (self , coro ):
264
264
if not hasattr (coro , "__name__" ):
265
- return coro
265
+ return await coro
266
266
start = default_timer ()
267
267
attr = {
268
268
"type" : "coroutine" ,
Original file line number Diff line number Diff line change @@ -43,19 +43,23 @@ def tearDown(self):
43
43
44
44
# Asyncio anext() does not have __name__ attribute, which is used to determine if the coroutine should be traced.
45
45
# 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.
46
47
@skipIf (
47
48
sys .version_info < (3 , 10 ), "anext is only available in Python 3.10+"
48
49
)
49
50
def test_asyncio_anext (self ):
50
51
async def main ():
51
52
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 ):
53
56
yield it
54
57
55
58
async_gen_instance = async_gen ()
56
59
agen = anext (async_gen_instance )
57
- await asyncio .create_task (agen )
60
+ return await asyncio .create_task (agen )
58
61
59
- asyncio .run (main ())
62
+ ret = asyncio .run (main ())
63
+ self .assertEqual (ret , 2 ) # first iteration from range()
60
64
spans = self .memory_exporter .get_finished_spans ()
61
65
self .assertEqual (len (spans ), 0 )
You can’t perform that action at this time.
0 commit comments