Skip to content

Commit 576ba3f

Browse files
authored
ref(redis)!: Drop send_default_pii support (#7824)
Redis command arguments are now gated solely on `data_collection["database_query_data"]`. The `send_default_pii` fallback in `_get_safe_command` is removed. Tests that exercised `send_default_pii` (including the precedence test) are removed, and the remaining ones use `data_collection` instead. Fixes PY-2837 Fixes #7608
1 parent 1fe2b2c commit 576ba3f

2 files changed

Lines changed: 5 additions & 171 deletions

File tree

‎sentry_sdk/integrations/redis/utils.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
_MULTI_KEY_COMMANDS,
99
_SINGLE_KEY_COMMANDS,
1010
)
11-
from sentry_sdk.scope import should_send_default_pii
1211
from sentry_sdk.traces import Span
13-
from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE, has_data_collection_enabled
12+
from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE
1413

1514
if TYPE_CHECKING:
1615
from typing import Any, Optional, Sequence
@@ -20,7 +19,6 @@ def _get_safe_command(name: str, args: "Sequence[Any]") -> str:
2019
command_parts = [name]
2120

2221
name_low = name.lower()
23-
send_default_pii = should_send_default_pii()
2422
client_options = sentry_sdk.get_client().options
2523

2624
for i, arg in enumerate(args):
@@ -35,10 +33,7 @@ def _get_safe_command(name: str, args: "Sequence[Any]") -> str:
3533
if arg_is_the_key:
3634
command_parts.append(repr(arg))
3735
else:
38-
if has_data_collection_enabled(client_options):
39-
if client_options["data_collection"]["database_query_data"]:
40-
command_parts.append(repr(arg))
41-
elif send_default_pii:
36+
if client_options["data_collection"]["database_query_data"]:
4237
command_parts.append(repr(arg))
4338
else:
4439
command_parts.append(SENSITIVE_DATA_SUBSTITUTE)

‎tests/integrations/redis/test_redis.py‎

Lines changed: 3 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -42,52 +42,6 @@ def test_basic(sentry_init, capture_events):
4242
}
4343

4444

45-
@pytest.mark.parametrize(
46-
"is_transaction, send_default_pii, expected_first_ten",
47-
[
48-
(False, False, ["GET 'foo'", "SET 'bar' [Filtered]", "SET 'baz' [Filtered]"]),
49-
(True, True, ["GET 'foo'", "SET 'bar' 1", "SET 'baz' 2"]),
50-
],
51-
)
52-
def test_redis_pipeline(
53-
sentry_init,
54-
capture_events,
55-
capture_items,
56-
is_transaction,
57-
send_default_pii,
58-
expected_first_ten,
59-
):
60-
sentry_init(
61-
integrations=[RedisIntegration()],
62-
traces_sample_rate=1.0,
63-
send_default_pii=send_default_pii,
64-
)
65-
66-
connection = FakeRedis()
67-
68-
items = capture_items("span")
69-
70-
with sentry_sdk.start_span(name="custom parent"):
71-
pipeline = connection.pipeline(transaction=is_transaction)
72-
pipeline.get("foo")
73-
pipeline.set("bar", 1)
74-
pipeline.set("baz", 2)
75-
pipeline.execute()
76-
77-
sentry_sdk.flush()
78-
79-
assert len(items) == 2
80-
pipeline_span, parent_span = items[0].payload, items[1].payload
81-
82-
assert parent_span["name"] == "custom parent"
83-
assert parent_span["is_segment"] is True
84-
85-
assert pipeline_span["name"] == "redis.pipeline.execute"
86-
assert pipeline_span["attributes"]["sentry.op"] == "db.redis"
87-
assert pipeline_span["attributes"]["sentry.origin"] == "auto.db.redis"
88-
assert pipeline_span["attributes"][SPANDATA.DB_SYSTEM_NAME] == "redis"
89-
90-
9145
@pytest.mark.parametrize(
9246
"data_collection, expected_first_ten",
9347
[
@@ -135,38 +89,6 @@ def test_redis_pipeline_data_collection(
13589
assert pipeline_span["attributes"]["sentry.op"] == "db.redis"
13690

13791

138-
def test_sensitive_data(
139-
sentry_init,
140-
capture_events,
141-
capture_items,
142-
):
143-
# fakeredis does not support the AUTH command, so we need to mock it
144-
with mock.patch(
145-
"sentry_sdk.integrations.redis.utils._COMMANDS_INCLUDING_SENSITIVE_DATA",
146-
["get"],
147-
):
148-
sentry_init(
149-
integrations=[RedisIntegration()],
150-
traces_sample_rate=1.0,
151-
send_default_pii=True,
152-
)
153-
154-
connection = FakeRedis()
155-
156-
items = capture_items("span")
157-
with sentry_sdk.start_span(name="custom parent"):
158-
connection.get("this is super secret")
159-
sentry_sdk.flush()
160-
161-
assert len(items) == 2
162-
redis_span, parent_span = items[0].payload, items[1].payload
163-
164-
assert parent_span["name"] == "custom parent"
165-
assert redis_span["name"] == "GET [Filtered]"
166-
assert redis_span["attributes"][SPANDATA.DB_QUERY_TEXT] == "GET [Filtered]"
167-
assert redis_span["attributes"]["sentry.op"] == "db.redis"
168-
169-
17092
def test_pii_data_redacted(
17193
sentry_init,
17294
capture_events,
@@ -205,7 +127,7 @@ def test_pii_data_redacted(
205127
@pytest.mark.parametrize(
206128
"data_collection, expected_description",
207129
[
208-
({"database_query_data": False}, "SET 'somekey1'"),
130+
({"database_query_data": False}, "SET 'somekey1' [Filtered]"),
209131
({"database_query_data": True}, "SET 'somekey1' 'my secret string1'"),
210132
({}, "SET 'somekey1' 'my secret string1'"),
211133
],
@@ -246,94 +168,11 @@ def test_data_collection_database_query_data(
246168
assert set_span["attributes"]["sentry.op"] == "db.redis"
247169

248170

249-
@pytest.mark.parametrize(
250-
"data_collection, send_default_pii, expected_description",
251-
[
252-
({"database_query_data": False}, True, "SET 'somekey1'"),
253-
(
254-
{"database_query_data": True},
255-
False,
256-
"SET 'somekey1' 'my secret string1'",
257-
),
258-
],
259-
)
260-
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
261-
def test_database_query_data_takes_precedence_over_send_default_pii(
262-
sentry_init,
263-
capture_events,
264-
capture_items,
265-
data_collection,
266-
send_default_pii,
267-
expected_description,
268-
):
269-
sentry_init(
270-
integrations=[RedisIntegration()],
271-
traces_sample_rate=1.0,
272-
send_default_pii=send_default_pii,
273-
data_collection=data_collection,
274-
)
275-
276-
connection = FakeRedis()
277-
278-
items = capture_items("span")
279-
280-
with sentry_sdk.start_span(name="custom parent"):
281-
connection.set("somekey1", "my secret string1")
282-
283-
sentry_sdk.flush()
284-
285-
assert len(items) == 2
286-
set_span, parent = [item.payload for item in items]
287-
288-
assert parent["name"] == "custom parent"
289-
assert set_span["name"] == expected_description
290-
assert set_span["attributes"][SPANDATA.DB_QUERY_TEXT] == expected_description
291-
assert set_span["attributes"]["sentry.op"] == "db.redis"
292-
293-
294-
def test_pii_data_sent(sentry_init, capture_items):
295-
sentry_init(
296-
integrations=[RedisIntegration()],
297-
traces_sample_rate=1.0,
298-
send_default_pii=True,
299-
)
300-
301-
connection = FakeRedis()
302-
303-
items = capture_items("span")
304-
305-
with sentry_sdk.start_span(name="custom parent"):
306-
connection.set("somekey1", "my secret string1")
307-
connection.set("somekey2", "my secret string2")
308-
connection.get("somekey2")
309-
connection.delete("somekey1", "somekey2")
310-
311-
sentry_sdk.flush()
312-
313-
assert len(items) == 5
314-
set1, set2, get, delete, parent = [item.payload for item in items]
315-
316-
assert parent["name"] == "custom parent"
317-
assert set1["name"] == "SET 'somekey1' 'my secret string1'"
318-
assert (
319-
set1["attributes"][SPANDATA.DB_QUERY_TEXT]
320-
== "SET 'somekey1' 'my secret string1'"
321-
)
322-
assert set1["attributes"]["sentry.op"] == "db.redis"
323-
assert set2["name"] == "SET 'somekey2' 'my secret string2'"
324-
assert (
325-
set2["attributes"][SPANDATA.DB_QUERY_TEXT]
326-
== "SET 'somekey2' 'my secret string2'"
327-
)
328-
assert get["name"] == "GET 'somekey2'"
329-
assert delete["name"] == "DEL 'somekey1' 'somekey2'"
330-
331-
332171
def test_no_data_truncation_by_default(sentry_init, capture_items):
333172
sentry_init(
334173
integrations=[RedisIntegration()],
335174
traces_sample_rate=1.0,
336-
send_default_pii=True,
175+
data_collection={"database_query_data": True},
337176
)
338177

339178
connection = FakeRedis()
@@ -366,7 +205,7 @@ def test_no_data_truncation_by_default(sentry_init, capture_items):
366205
def test_breadcrumbs(sentry_init, capture_events):
367206
sentry_init(
368207
integrations=[RedisIntegration()],
369-
send_default_pii=True,
208+
data_collection={"database_query_data": True},
370209
)
371210
events = capture_events()
372211

0 commit comments

Comments
 (0)