@@ -77,6 +77,7 @@ def response_hook(span, instance, response):
7777from typing import Any , Collection
7878
7979import redis
80+ import redis .asyncio
8081from wrapt import wrap_function_wrapper
8182
8283from opentelemetry import trace
@@ -102,6 +103,8 @@ def response_hook(span, instance, response):
102103 typing .Callable [[Span , redis .connection .Connection , Any ], None ]
103104]
104105
106+ _REDIS_ASYNCIO_VERSION = (4 , 2 , 0 )
107+
105108
106109def _set_connection_attributes (span , conn ):
107110 if not span .is_recording ():
@@ -176,6 +179,22 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
176179 f"{ pipeline_class } .immediate_execute_command" ,
177180 _traced_execute_command ,
178181 )
182+ if redis .VERSION >= _REDIS_ASYNCIO_VERSION :
183+ wrap_function_wrapper (
184+ "redis.asyncio" ,
185+ f"{ redis_class } .execute_command" ,
186+ _traced_execute_command ,
187+ )
188+ wrap_function_wrapper (
189+ "redis.asyncio.client" ,
190+ f"{ pipeline_class } .execute" ,
191+ _traced_execute_pipeline ,
192+ )
193+ wrap_function_wrapper (
194+ "redis.asyncio.client" ,
195+ f"{ pipeline_class } .immediate_execute_command" ,
196+ _traced_execute_command ,
197+ )
179198
180199
181200class RedisInstrumentor (BaseInstrumentor ):
@@ -222,3 +241,8 @@ def _uninstrument(self, **kwargs):
222241 unwrap (redis .Redis , "pipeline" )
223242 unwrap (redis .client .Pipeline , "execute" )
224243 unwrap (redis .client .Pipeline , "immediate_execute_command" )
244+ if redis .VERSION >= _REDIS_ASYNCIO_VERSION :
245+ unwrap (redis .asyncio .Redis , "execute_command" )
246+ unwrap (redis .asyncio .Redis , "pipeline" )
247+ unwrap (redis .asyncio .client .Pipeline , "execute" )
248+ unwrap (redis .asyncio .client .Pipeline , "immediate_execute_command" )
0 commit comments