Skip to content

Commit

Permalink
feat: Send PII to Spotlight when no DSN is set (#3804)
Browse files Browse the repository at this point in the history
* 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 <anton.pirker@sentry.io>
  • Loading branch information
BYK and antonpirker authored Nov 21, 2024
1 parent 295dd8d commit 8fe5bb4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
12 changes: 10 additions & 2 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ def _get_options(*args, **kwargs):
rv["traces_sample_rate"] = 1.0

if rv["event_scrubber"] is None:
rv["event_scrubber"] = EventScrubber(send_default_pii=rv["send_default_pii"])
rv["event_scrubber"] = EventScrubber(
send_default_pii=(
False if rv["send_default_pii"] is None else rv["send_default_pii"]
)
)

if rv["socket_options"] and not isinstance(rv["socket_options"], list):
logger.warning(
Expand Down Expand Up @@ -451,7 +455,11 @@ def should_send_default_pii(self):
Returns whether the client should send default PII (Personally Identifiable Information) data to Sentry.
"""
return self.options.get("send_default_pii", False)
result = self.options.get("send_default_pii")
if result is None:
result = not self.options["dsn"] and self.spotlight is not None

return result

@property
def dsn(self):
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ class OP:
# This type exists to trick mypy and PyCharm into thinking `init` and `Client`
# take these arguments (even though they take opaque **kwargs)
class ClientConstructor:

def __init__(
self,
dsn=None, # type: Optional[str]
Expand All @@ -506,7 +507,7 @@ def __init__(
transport=None, # type: Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]]
transport_queue_size=DEFAULT_QUEUE_SIZE, # type: int
sample_rate=1.0, # type: float
send_default_pii=False, # type: bool
send_default_pii=None, # type: Optional[bool]
http_proxy=None, # type: Optional[str]
https_proxy=None, # type: Optional[str]
ignore_errors=[], # type: Sequence[Union[type, str]] # noqa: B006
Expand Down
18 changes: 18 additions & 0 deletions tests/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,24 @@ def test_should_send_default_pii_false(sentry_init):
assert should_send_default_pii() is False


def test_should_send_default_pii_default_false(sentry_init):
sentry_init()

assert should_send_default_pii() is False


def test_should_send_default_pii_false_with_dsn_and_spotlight(sentry_init):
sentry_init(dsn="http://key@localhost/1", spotlight=True)

assert should_send_default_pii() is False


def test_should_send_default_pii_true_without_dsn_and_spotlight(sentry_init):
sentry_init(spotlight=True)

assert should_send_default_pii() is True


def test_set_tags():
scope = Scope()
scope.set_tags({"tag1": "value1", "tag2": "value2"})
Expand Down

0 comments on commit 8fe5bb4

Please sign in to comment.