Skip to content

Commit

Permalink
feat(redis): Patch rediscluster if present
Browse files Browse the repository at this point in the history
In addition to the redis and rb clients try to patch also the
rediscluster library which does not use the already patched clients.
  • Loading branch information
beezz committed Jun 30, 2020
1 parent 7d482b5 commit 619a95a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion sentry_sdk/integrations/redis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import

from sentry_sdk import Hub
from sentry_sdk.utils import capture_internal_exceptions
from sentry_sdk.utils import capture_internal_exceptions, logger
from sentry_sdk.integrations import Integration

from sentry_sdk._types import MYPY
Expand All @@ -15,6 +15,25 @@
_MULTI_KEY_COMMANDS = frozenset(["del", "touch", "unlink"])


def _patch_rediscluster():
# type: () -> None
try:
import rediscluster
except ImportError:
return

patch_redis_client(rediscluster.RedisCluster)

# up to v1.3.6, __version__ attribute is a tuple
# from v2.0.0, __version__ is a string and VERSION a tuple
version = getattr(rediscluster, "VERSION", rediscluster.__version__)[0]

# StrictRedisCluster was introduced in v0.2.0 and removed in v2.0.0
# https://github.com/Grokzen/redis-py-cluster/blob/master/docs/release-notes.rst
if (0, 2, 0) < version < (2, 0, 0):
patch_redis_client(rediscluster.StrictRedisCluster)


class RedisIntegration(Integration):
identifier = "redis"

Expand All @@ -34,6 +53,11 @@ def setup_once():
patch_redis_client(rb.clients.MappingClient)
patch_redis_client(rb.clients.RoutingClient)

try:
_patch_rediscluster()
except Exception:
logger.exception("Error occured while patching `rediscluster` library")


def patch_redis_client(cls):
# type: (Any) -> None
Expand Down

0 comments on commit 619a95a

Please sign in to comment.