Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sentry_sdk/integrations/redis/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/redis/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions sentry_sdk/integrations/redis/modules/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions sentry_sdk/integrations/redis/modules/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/integrations/redis/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down