1+ from __future__ import absolute_import
2+
13from elasticapm .instrumentation .packages .base import AbstractInstrumentedModule
24from elasticapm .traces import capture_span
35
46
5- class RedisInstrumentation (AbstractInstrumentedModule ):
7+ class Redis3CheckMixin (object ):
8+ instrument_list_3 = []
9+ instrument_list = []
10+
11+ def get_instrument_list (self ):
12+ try :
13+ from redis import VERSION
14+
15+ if VERSION [0 ] >= 3 :
16+ return self .instrument_list_3
17+ return self .instrument_list
18+ except ImportError :
19+ return self .instrument_list
20+
21+
22+ class RedisInstrumentation (Redis3CheckMixin , AbstractInstrumentedModule ):
623 name = "redis"
724
25+ # no need to instrument StrictRedis in redis-py >= 3.0
26+ instrument_list_3 = [("redis.client" , "Redis.execute_command" )]
827 instrument_list = [("redis.client" , "Redis.execute_command" ), ("redis.client" , "StrictRedis.execute_command" )]
928
1029 def call (self , module , method , wrapped , instance , args , kwargs ):
@@ -17,9 +36,11 @@ def call(self, module, method, wrapped, instance, args, kwargs):
1736 return wrapped (* args , ** kwargs )
1837
1938
20- class RedisPipelineInstrumentation (AbstractInstrumentedModule ):
39+ class RedisPipelineInstrumentation (Redis3CheckMixin , AbstractInstrumentedModule ):
2140 name = "redis"
2241
42+ # BasePipeline has been renamed to Pipeline in redis-py 3
43+ instrument_list_3 = [("redis.client" , "Pipeline.execute" )]
2344 instrument_list = [("redis.client" , "BasePipeline.execute" )]
2445
2546 def call (self , module , method , wrapped , instance , args , kwargs ):
0 commit comments