@@ -103,6 +103,7 @@ def func():
103
103
104
104
from wrapt import wrap_function_wrapper as _wrap
105
105
106
+ # pylint: disable=no-name-in-module
106
107
from opentelemetry .instrumentation .asyncio .metrics import (
107
108
ASYNCIO_COROUTINE_ACTIVE ,
108
109
ASYNCIO_COROUTINE_CANCELLED ,
@@ -215,10 +216,10 @@ def _instrument(self, **kwargs):
215
216
216
217
def _uninstrument (self , ** kwargs ):
217
218
for method in self .methods_with_coroutine :
218
- self . uninstrument_method_with_coroutine (method )
219
- self . uninstrument_gather ()
220
- self . uninstrument_to_thread ()
221
- self . uninstrument_taskgroup_create_task ()
219
+ uninstrument_method_with_coroutine (method )
220
+ uninstrument_gather ()
221
+ uninstrument_to_thread ()
222
+ uninstrument_taskgroup_create_task ()
222
223
223
224
def instrument_method_with_coroutine (self , method_name ):
224
225
"""
@@ -245,24 +246,16 @@ def wrap_coro_or_future(method, instance, args, kwargs):
245
246
246
247
_wrap (asyncio , method_name , wrap_coro_or_future )
247
248
248
- def uninstrument_method_with_coroutine (self , method_name ):
249
- """
250
- Uninstrument specified asyncio method.
251
- """
252
- unwrap (asyncio , method_name )
253
-
254
249
def instrument_gather (self ):
255
250
def wrap_coros_or_futures (method , instance , args , kwargs ):
256
251
if args and len (args ) > 0 :
257
252
# Check if it's a coroutine or future and wrap it
258
253
wrapped_args = tuple (self .trace_item (item ) for item in args )
259
254
return method (* wrapped_args , ** kwargs )
255
+ return method (* args , ** kwargs )
260
256
261
257
_wrap (asyncio , "gather" , wrap_coros_or_futures )
262
258
263
- def uninstrument_gather (self ):
264
- unwrap (asyncio , "gather" )
265
-
266
259
def instrument_to_thread (self ):
267
260
# to_thread was added in Python 3.9
268
261
if sys .version_info < (3 , 9 ):
@@ -276,15 +269,10 @@ def wrap_to_thread(method, instance, args, kwargs):
276
269
wrapped_args = (wrapped_first_arg ,) + args [1 :]
277
270
278
271
return method (* wrapped_args , ** kwargs )
272
+ return method (* args , ** kwargs )
279
273
280
274
_wrap (asyncio , "to_thread" , wrap_to_thread )
281
275
282
- def uninstrument_to_thread (self ):
283
- # to_thread was added in Python 3.9
284
- if sys .version_info < (3 , 9 ):
285
- return
286
- unwrap (asyncio , "to_thread" )
287
-
288
276
def instrument_taskgroup_create_task (self ):
289
277
# TaskGroup.create_task was added in Python 3.11
290
278
if sys .version_info < (3 , 11 ):
@@ -296,14 +284,11 @@ def wrap_taskgroup_create_task(method, instance, args, kwargs):
296
284
wrapped_coro = self .trace_coroutine (coro )
297
285
wrapped_args = (wrapped_coro ,) + args [1 :]
298
286
return method (* wrapped_args , ** kwargs )
287
+ return method (* args , ** kwargs )
299
288
300
- _wrap (asyncio .TaskGroup , "create_task" , wrap_taskgroup_create_task )
301
-
302
- def uninstrument_taskgroup_create_task (self ):
303
- # TaskGroup.create_task was added in Python 3.11
304
- if sys .version_info < (3 , 11 ):
305
- return
306
- unwrap (asyncio .TaskGroup , "create_task" )
289
+ _wrap (
290
+ asyncio .TaskGroup , "create_task" , wrap_taskgroup_create_task # pylint: disable=no-member
291
+ )
307
292
308
293
def trace_to_thread (self , func ):
309
294
"""Trace a function."""
@@ -343,7 +328,7 @@ def trace_item(self, coro_or_future):
343
328
return coro_or_future
344
329
if asyncio .iscoroutine (coro_or_future ):
345
330
return self .trace_coroutine (coro_or_future )
346
- elif futures .isfuture (coro_or_future ):
331
+ if futures .isfuture (coro_or_future ):
347
332
return self .trace_future (coro_or_future )
348
333
return coro_or_future
349
334
@@ -527,3 +512,28 @@ def create_to_thread_metric(self):
527
512
description = "Number of asyncio function finished" ,
528
513
unit = "1" ,
529
514
)
515
+
516
+
517
+ def uninstrument_taskgroup_create_task ():
518
+ # TaskGroup.create_task was added in Python 3.11
519
+ if sys .version_info < (3 , 11 ):
520
+ return
521
+ unwrap (asyncio .TaskGroup , "create_task" ) # pylint: disable=no-member
522
+
523
+
524
+ def uninstrument_to_thread ():
525
+ # to_thread was added in Python 3.9
526
+ if sys .version_info < (3 , 9 ):
527
+ return
528
+ unwrap (asyncio , "to_thread" )
529
+
530
+
531
+ def uninstrument_gather ():
532
+ unwrap (asyncio , "gather" )
533
+
534
+
535
+ def uninstrument_method_with_coroutine (method_name ):
536
+ """
537
+ Uninstrument specified asyncio method.
538
+ """
539
+ unwrap (asyncio , method_name )
0 commit comments