Skip to content

Commit 8fe5bb4

Browse files
BYKantonpirker
andauthored
feat: Send PII to Spotlight when no DSN is set (#3804)
* feat: Send PII to Spotlight when no DSN is set Quick fix for getsentry/spotlight#543 until we implement a global scrubber that only scrubs events sent to the clound thorugh the DSN. * add tests fix bugs * Make scrubber initialization more explicit * Refactored to not change the default value of send_default_pii * Add test to show that there is now no way to opt out of sending PII to spotlight. * Revert "Refactored to not change the default value of send_default_pii" This reverts commit 15cf625. * Revert "Add test to show that there is now no way to opt out of sending PII to spotlight." This reverts commit de7f398. --------- Co-authored-by: Anton Pirker <[email protected]>
1 parent 295dd8d commit 8fe5bb4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

sentry_sdk/client.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ def _get_options(*args, **kwargs):
128128
rv["traces_sample_rate"] = 1.0
129129

130130
if rv["event_scrubber"] is None:
131-
rv["event_scrubber"] = EventScrubber(send_default_pii=rv["send_default_pii"])
131+
rv["event_scrubber"] = EventScrubber(
132+
send_default_pii=(
133+
False if rv["send_default_pii"] is None else rv["send_default_pii"]
134+
)
135+
)
132136

133137
if rv["socket_options"] and not isinstance(rv["socket_options"], list):
134138
logger.warning(
@@ -451,7 +455,11 @@ def should_send_default_pii(self):
451455
452456
Returns whether the client should send default PII (Personally Identifiable Information) data to Sentry.
453457
"""
454-
return self.options.get("send_default_pii", False)
458+
result = self.options.get("send_default_pii")
459+
if result is None:
460+
result = not self.options["dsn"] and self.spotlight is not None
461+
462+
return result
455463

456464
@property
457465
def dsn(self):

sentry_sdk/consts.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ class OP:
489489
# This type exists to trick mypy and PyCharm into thinking `init` and `Client`
490490
# take these arguments (even though they take opaque **kwargs)
491491
class ClientConstructor:
492+
492493
def __init__(
493494
self,
494495
dsn=None, # type: Optional[str]
@@ -506,7 +507,7 @@ def __init__(
506507
transport=None, # type: Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]]
507508
transport_queue_size=DEFAULT_QUEUE_SIZE, # type: int
508509
sample_rate=1.0, # type: float
509-
send_default_pii=False, # type: bool
510+
send_default_pii=None, # type: Optional[bool]
510511
http_proxy=None, # type: Optional[str]
511512
https_proxy=None, # type: Optional[str]
512513
ignore_errors=[], # type: Sequence[Union[type, str]] # noqa: B006

tests/test_scope.py

+18
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,24 @@ def test_should_send_default_pii_false(sentry_init):
811811
assert should_send_default_pii() is False
812812

813813

814+
def test_should_send_default_pii_default_false(sentry_init):
815+
sentry_init()
816+
817+
assert should_send_default_pii() is False
818+
819+
820+
def test_should_send_default_pii_false_with_dsn_and_spotlight(sentry_init):
821+
sentry_init(dsn="http://key@localhost/1", spotlight=True)
822+
823+
assert should_send_default_pii() is False
824+
825+
826+
def test_should_send_default_pii_true_without_dsn_and_spotlight(sentry_init):
827+
sentry_init(spotlight=True)
828+
829+
assert should_send_default_pii() is True
830+
831+
814832
def test_set_tags():
815833
scope = Scope()
816834
scope.set_tags({"tag1": "value1", "tag2": "value2"})

0 commit comments

Comments
 (0)