Repository: DataDog/dd-trace-py

Issue:
redis-py-cluster new API 2.0.0
### Which version of dd-trace-py are you using?
 lastest 0.34.0

### Which version of the libraries are you using?

redis-py-cluster  2.0.0

### How can we reproduce your problem?

change https://github.com/DataDog/dd-trace-py/blob/master/tox.ini redis-py-cluster version

### What is the result that you get?

ERROR. It's no more StrictRedisCluster but  just RedisCluster

### What is result that you expected?

moving to new api



Discussion:

Resolving patch:
diff --git a/ddtrace/contrib/rediscluster/patch.py b/ddtrace/contrib/rediscluster/patch.py
--- a/ddtrace/contrib/rediscluster/patch.py
+++ b/ddtrace/contrib/rediscluster/patch.py
@@ -12,6 +12,11 @@
 from ..redis.util import format_command_args
 
 
+# DEV: In `2.0.0` `__version__` is a string and `VERSION` is a tuple,
+#      but in `1.x.x` `__version__` is a tuple annd `VERSION` does not exist
+REDISCLUSTER_VERSION = getattr(rediscluster, 'VERSION', rediscluster.__version__)
+
+
 def patch():
     """Patch the instrumented methods
     """
@@ -20,18 +25,30 @@ def patch():
     setattr(rediscluster, '_datadog_patch', True)
 
     _w = wrapt.wrap_function_wrapper
-    _w('rediscluster', 'StrictRedisCluster.execute_command', traced_execute_command)
-    _w('rediscluster', 'StrictRedisCluster.pipeline', traced_pipeline)
-    _w('rediscluster', 'StrictClusterPipeline.execute', traced_execute_pipeline)
-    Pin(service=redisx.DEFAULT_SERVICE, app=redisx.APP).onto(rediscluster.StrictRedisCluster)
+    if REDISCLUSTER_VERSION >= (2, 0, 0):
+        _w('rediscluster', 'RedisCluster.execute_command', traced_execute_command)
+        _w('rediscluster', 'RedisCluster.pipeline', traced_pipeline)
+        _w('rediscluster', 'ClusterPipeline.execute', traced_execute_pipeline)
+        Pin(service=redisx.DEFAULT_SERVICE, app=redisx.APP).onto(rediscluster.RedisCluster)
+    else:
+        _w('rediscluster', 'StrictRedisCluster.execute_command', traced_execute_command)
+        _w('rediscluster', 'StrictRedisCluster.pipeline', traced_pipeline)
+        _w('rediscluster', 'StrictClusterPipeline.execute', traced_execute_pipeline)
+        Pin(service=redisx.DEFAULT_SERVICE, app=redisx.APP).onto(rediscluster.StrictRedisCluster)
 
 
 def unpatch():
     if getattr(rediscluster, '_datadog_patch', False):
         setattr(rediscluster, '_datadog_patch', False)
-        unwrap(rediscluster.StrictRedisCluster, 'execute_command')
-        unwrap(rediscluster.StrictRedisCluster, 'pipeline')
-        unwrap(rediscluster.StrictClusterPipeline, 'execute')
+
+        if REDISCLUSTER_VERSION >= (2, 0, 0):
+            unwrap(rediscluster.RedisCluster, 'execute_command')
+            unwrap(rediscluster.RedisCluster, 'pipeline')
+            unwrap(rediscluster.ClusterPipeline, 'execute')
+        else:
+            unwrap(rediscluster.StrictRedisCluster, 'execute_command')
+            unwrap(rediscluster.StrictRedisCluster, 'pipeline')
+            unwrap(rediscluster.StrictClusterPipeline, 'execute')
 
 
 #


Test patch:
diff --git a/tests/contrib/rediscluster/test.py b/tests/contrib/rediscluster/test.py
--- a/tests/contrib/rediscluster/test.py
+++ b/tests/contrib/rediscluster/test.py
@@ -3,6 +3,7 @@
 
 from ddtrace import Pin
 from ddtrace.contrib.rediscluster.patch import patch, unpatch
+from ddtrace.contrib.rediscluster.patch import REDISCLUSTER_VERSION
 from ..config import REDISCLUSTER_CONFIG
 from ...test_tracer import get_dummy_tracer
 from ...base import BaseTracerTestCase
@@ -20,7 +21,10 @@ def _get_test_client(self):
             {'host': self.TEST_HOST, 'port': int(port)}
             for port in self.TEST_PORTS.split(',')
         ]
-        return rediscluster.StrictRedisCluster(startup_nodes=startup_nodes)
+        if REDISCLUSTER_VERSION >= (2, 0, 0):
+            return rediscluster.RedisCluster(startup_nodes=startup_nodes)
+        else:
+            return rediscluster.StrictRedisCluster(startup_nodes=startup_nodes)
 
     def setUp(self):
         super(TestRedisPatch, self).setUp()