Skip to content

Commit c4071b3

Browse files
chore: Deprecate description truncation option for Redis spans (#5073)
Set the default value of the `max_data_size` parameter of `RedisIntegration` to `None`, so that Redis span descriptions are not truncated by default. Deprecate the parameter and announce its removal in the next major release. Closes #4990
1 parent 25999b5 commit c4071b3

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

sentry_sdk/integrations/redis/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
from sentry_sdk.integrations import Integration, DidNotEnable
24
from sentry_sdk.integrations.redis.consts import _DEFAULT_MAX_DATA_SIZE
35
from sentry_sdk.integrations.redis.rb import _patch_rb
@@ -16,10 +18,18 @@ class RedisIntegration(Integration):
1618
identifier = "redis"
1719

1820
def __init__(self, max_data_size=_DEFAULT_MAX_DATA_SIZE, cache_prefixes=None):
19-
# type: (int, Optional[list[str]]) -> None
21+
# type: (Optional[int], Optional[list[str]]) -> None
2022
self.max_data_size = max_data_size
2123
self.cache_prefixes = cache_prefixes if cache_prefixes is not None else []
2224

25+
if max_data_size is not None:
26+
warnings.warn(
27+
"The `max_data_size` parameter of `RedisIntegration` is "
28+
"deprecated and will be removed in version 3.0 of sentry-sdk.",
29+
DeprecationWarning,
30+
stacklevel=2,
31+
)
32+
2333
@staticmethod
2434
def setup_once():
2535
# type: () -> None

sentry_sdk/integrations/redis/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
]
1717
_MAX_NUM_ARGS = 10 # Trim argument lists to this many values
1818
_MAX_NUM_COMMANDS = 10 # Trim command lists to this many values
19-
_DEFAULT_MAX_DATA_SIZE = 1024
19+
_DEFAULT_MAX_DATA_SIZE = None

sentry_sdk/integrations/redis/modules/caches.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ def _get_cache_span_description(redis_command, args, kwargs, integration):
6666
# type: (str, tuple[Any, ...], dict[str, Any], RedisIntegration) -> str
6767
description = _key_as_string(_get_safe_key(redis_command, args, kwargs))
6868

69-
data_should_be_truncated = (
70-
integration.max_data_size and len(description) > integration.max_data_size
71-
)
72-
if data_should_be_truncated:
69+
if integration.max_data_size and len(description) > integration.max_data_size:
7370
description = description[: integration.max_data_size - len("...")] + "..."
7471

7572
return description

sentry_sdk/integrations/redis/modules/queries.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ def _get_db_span_description(integration, command_name, args):
3434
with capture_internal_exceptions():
3535
description = _get_safe_command(command_name, args)
3636

37-
data_should_be_truncated = (
38-
integration.max_data_size and len(description) > integration.max_data_size
39-
)
40-
if data_should_be_truncated:
37+
if integration.max_data_size and len(description) > integration.max_data_size:
4138
description = description[: integration.max_data_size - len("...")] + "..."
4239

4340
return description

tests/integrations/redis/test_redis.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_pii_data_sent(sentry_init, capture_events):
154154
assert spans[3]["description"] == "DEL 'somekey1' 'somekey2'"
155155

156156

157-
def test_data_truncation(sentry_init, capture_events):
157+
def test_no_data_truncation_by_default(sentry_init, capture_events):
158158
sentry_init(
159159
integrations=[RedisIntegration()],
160160
traces_sample_rate=1.0,
@@ -172,10 +172,8 @@ def test_data_truncation(sentry_init, capture_events):
172172
(event,) = events
173173
spans = event["spans"]
174174
assert spans[0]["op"] == "db.redis"
175-
assert spans[0]["description"] == "SET 'somekey1' '%s..." % (
176-
long_string[: 1024 - len("...") - len("SET 'somekey1' '")],
177-
)
178-
assert spans[1]["description"] == "SET 'somekey2' '%s'" % (short_string,)
175+
assert spans[0]["description"] == f"SET 'somekey1' '{long_string}'"
176+
assert spans[1]["description"] == f"SET 'somekey2' '{short_string}'"
179177

180178

181179
def test_data_truncation_custom(sentry_init, capture_events):

0 commit comments

Comments
 (0)