File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
instrumentation/opentelemetry-instrumentation-asyncio
src/opentelemetry/instrumentation/asyncio Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## Unreleased
99
10+ - ` opentelemetry-instrumentation-asyncio ` instrumented ` asyncio.wait_for ` properly raises ` asyncio.TimeoutError ` as expected
11+ ([ #2637 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2637 ) )
1012- ` opentelemetry-instrumentation-aws-lambda ` Bugfix: AWS Lambda event source key incorrect for SNS in instrumentation library.
1113 ([ #2612 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2612 ) )
1214- ` opentelemetry-instrumentation-system-metrics ` Permit to use psutil 6.0+.
Original file line number Diff line number Diff line change @@ -280,8 +280,11 @@ async def trace_coroutine(self, coro):
280280 # CancelledError is raised when a coroutine is cancelled
281281 # before it has a chance to run. We don't want to record
282282 # this as an error.
283+ # Still it needs to be raised in order for `asyncio.wait_for`
284+ # to properly work with timeout and raise accordingly `asyncio.TimeoutError`
283285 except asyncio .CancelledError :
284286 attr ["state" ] = "cancelled"
287+ raise
285288 except Exception as exc :
286289 exception = exc
287290 state = determine_state (exception )
Original file line number Diff line number Diff line change @@ -68,6 +68,19 @@ async def main():
6868 spans = self .memory_exporter .get_finished_spans ()
6969 self .assertEqual (len (spans ), 2 )
7070
71+ def test_asyncio_wait_for_with_timeout (self ):
72+ expected_timeout_error = None
73+
74+ async def main ():
75+ nonlocal expected_timeout_error
76+ try :
77+ await asyncio .wait_for (async_func (), 0.01 )
78+ except asyncio .TimeoutError as timeout_error :
79+ expected_timeout_error = timeout_error
80+
81+ asyncio .run (main ())
82+ self .assertNotEqual (expected_timeout_error , None )
83+
7184 def test_asyncio_as_completed (self ):
7285 async def main ():
7386 if sys .version_info >= (3 , 11 ):
You can’t perform that action at this time.
0 commit comments