diff --git a/sentry_sdk/integrations/redis/__init__.py b/sentry_sdk/integrations/redis/__init__.py index f443138295..9595794e74 100644 --- a/sentry_sdk/integrations/redis/__init__.py +++ b/sentry_sdk/integrations/redis/__init__.py @@ -1,3 +1,5 @@ +import warnings + from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.integrations.redis.consts import _DEFAULT_MAX_DATA_SIZE from sentry_sdk.integrations.redis.rb import _patch_rb @@ -16,10 +18,18 @@ class RedisIntegration(Integration): identifier = "redis" def __init__(self, max_data_size=_DEFAULT_MAX_DATA_SIZE, cache_prefixes=None): - # type: (int, Optional[list[str]]) -> None + # type: (Optional[int], Optional[list[str]]) -> None self.max_data_size = max_data_size self.cache_prefixes = cache_prefixes if cache_prefixes is not None else [] + if max_data_size is not None: + warnings.warn( + "The `max_data_size` parameter of `RedisIntegration` is " + "deprecated and will be removed in version 3.0 of sentry-sdk.", + DeprecationWarning, + stacklevel=2, + ) + @staticmethod def setup_once(): # type: () -> None diff --git a/sentry_sdk/integrations/redis/consts.py b/sentry_sdk/integrations/redis/consts.py index 737e829735..0822c2c930 100644 --- a/sentry_sdk/integrations/redis/consts.py +++ b/sentry_sdk/integrations/redis/consts.py @@ -16,4 +16,4 @@ ] _MAX_NUM_ARGS = 10 # Trim argument lists to this many values _MAX_NUM_COMMANDS = 10 # Trim command lists to this many values -_DEFAULT_MAX_DATA_SIZE = 1024 +_DEFAULT_MAX_DATA_SIZE = None diff --git a/sentry_sdk/integrations/redis/modules/caches.py b/sentry_sdk/integrations/redis/modules/caches.py index c6fc19f5b2..07b418ad0d 100644 --- a/sentry_sdk/integrations/redis/modules/caches.py +++ b/sentry_sdk/integrations/redis/modules/caches.py @@ -66,10 +66,7 @@ def _get_cache_span_description(redis_command, args, kwargs, integration): # type: (str, tuple[Any, ...], dict[str, Any], RedisIntegration) -> str description = _key_as_string(_get_safe_key(redis_command, args, kwargs)) - data_should_be_truncated = ( - integration.max_data_size and len(description) > integration.max_data_size - ) - if data_should_be_truncated: + if integration.max_data_size and len(description) > integration.max_data_size: description = description[: integration.max_data_size - len("...")] + "..." return description diff --git a/sentry_sdk/integrations/redis/modules/queries.py b/sentry_sdk/integrations/redis/modules/queries.py index e0d85a4ef7..a4229a4d5d 100644 --- a/sentry_sdk/integrations/redis/modules/queries.py +++ b/sentry_sdk/integrations/redis/modules/queries.py @@ -34,10 +34,7 @@ def _get_db_span_description(integration, command_name, args): with capture_internal_exceptions(): description = _get_safe_command(command_name, args) - data_should_be_truncated = ( - integration.max_data_size and len(description) > integration.max_data_size - ) - if data_should_be_truncated: + if integration.max_data_size and len(description) > integration.max_data_size: description = description[: integration.max_data_size - len("...")] + "..." return description diff --git a/tests/integrations/redis/test_redis.py b/tests/integrations/redis/test_redis.py index 5173885f33..1861e7116f 100644 --- a/tests/integrations/redis/test_redis.py +++ b/tests/integrations/redis/test_redis.py @@ -154,7 +154,7 @@ def test_pii_data_sent(sentry_init, capture_events): assert spans[3]["description"] == "DEL 'somekey1' 'somekey2'" -def test_data_truncation(sentry_init, capture_events): +def test_no_data_truncation_by_default(sentry_init, capture_events): sentry_init( integrations=[RedisIntegration()], traces_sample_rate=1.0, @@ -172,10 +172,8 @@ def test_data_truncation(sentry_init, capture_events): (event,) = events spans = event["spans"] assert spans[0]["op"] == "db.redis" - assert spans[0]["description"] == "SET 'somekey1' '%s..." % ( - long_string[: 1024 - len("...") - len("SET 'somekey1' '")], - ) - assert spans[1]["description"] == "SET 'somekey2' '%s'" % (short_string,) + assert spans[0]["description"] == f"SET 'somekey1' '{long_string}'" + assert spans[1]["description"] == f"SET 'somekey2' '{short_string}'" def test_data_truncation_custom(sentry_init, capture_events):