1- from sentry_sdk import Hub
1+ import sentry_sdk
22from sentry_sdk .consts import OP
33from sentry_sdk .integrations .redis import (
44 RedisIntegration ,
88)
99from sentry_sdk ._types import TYPE_CHECKING
1010from sentry_sdk .tracing import Span
11- from sentry_sdk .utils import capture_internal_exceptions
11+ from sentry_sdk .utils import (
12+ capture_internal_exceptions ,
13+ ensure_integration_enabled_async ,
14+ )
1215
1316if TYPE_CHECKING :
1417 from collections .abc import Callable
@@ -23,14 +26,10 @@ def patch_redis_async_pipeline(
2326 # type: (Union[type[Pipeline[Any]], type[ClusterPipeline[Any]]], bool, Any, Callable[[Span, Any], None]) -> None
2427 old_execute = pipeline_cls .execute
2528
29+ @ensure_integration_enabled_async (RedisIntegration , old_execute )
2630 async def _sentry_execute (self , * args , ** kwargs ):
2731 # type: (Any, *Any, **Any) -> Any
28- hub = Hub .current
29-
30- if hub .get_integration (RedisIntegration ) is None :
31- return await old_execute (self , * args , ** kwargs )
32-
33- with hub .start_span (
32+ with sentry_sdk .start_span (
3433 op = OP .DB_REDIS , description = "redis.pipeline.execute"
3534 ) as span :
3635 with capture_internal_exceptions ():
@@ -45,26 +44,22 @@ async def _sentry_execute(self, *args, **kwargs):
4544
4645 return await old_execute (self , * args , ** kwargs )
4746
48- pipeline_cls .execute = _sentry_execute # type: ignore[method-assign]
47+ pipeline_cls .execute = _sentry_execute # type: ignore
4948
5049
5150def patch_redis_async_client (cls , is_cluster , set_db_data_fn ):
5251 # type: (Union[type[StrictRedis[Any]], type[RedisCluster[Any]]], bool, Callable[[Span, Any], None]) -> None
5352 old_execute_command = cls .execute_command
5453
54+ @ensure_integration_enabled_async (RedisIntegration , old_execute_command ) # type: ignore
5555 async def _sentry_execute_command (self , name , * args , ** kwargs ):
5656 # type: (Any, str, *Any, **Any) -> Any
57- hub = Hub .current
58-
59- if hub .get_integration (RedisIntegration ) is None :
60- return await old_execute_command (self , name , * args , ** kwargs )
61-
6257 description = _get_span_description (name , * args )
6358
64- with hub .start_span (op = OP .DB_REDIS , description = description ) as span :
59+ with sentry_sdk .start_span (op = OP .DB_REDIS , description = description ) as span :
6560 set_db_data_fn (span , self )
6661 _set_client_data (span , is_cluster , name , * args )
6762
6863 return await old_execute_command (self , name , * args , ** kwargs )
6964
70- cls .execute_command = _sentry_execute_command # type: ignore[method-assign]
65+ cls .execute_command = _sentry_execute_command # type: ignore
0 commit comments