From f6304d438e45f414977a0ceed95680ff6124b0bd Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 9 Jun 2025 17:33:24 -0400 Subject: [PATCH] fix(logs): Don't gate user behind `send_default_pii` --- sentry_sdk/client.py | 2 +- tests/test_logs.py | 26 +++----------------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 9d9a6473e8..979ea92906 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -931,7 +931,7 @@ def _capture_experimental_log(self, log): log["trace_id"] = propagation_context.trace_id # The user, if present, is always set on the isolation scope. - if self.should_send_default_pii() and isolation_scope._user is not None: + if isolation_scope._user is not None: for log_attribute, user_attribute in ( ("user.id", "id"), ("user.name", "username"), diff --git a/tests/test_logs.py b/tests/test_logs.py index 94c0f4ce6f..dcbaba3c4f 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -484,9 +484,9 @@ def test_auto_flush_logs_after_100(sentry_init, capture_envelopes): raise AssertionError("200 logs were never flushed after five seconds") -def test_user_attributes(sentry_init, capture_envelopes): - """User attributes are sent if send_default_pii is True.""" - sentry_init(send_default_pii=True, _experiments={"enable_logs": True}) +def test_log_user_attributes(sentry_init, capture_envelopes): + """User attributes are sent if enable_logs is True.""" + sentry_init(_experiments={"enable_logs": True}) sentry_sdk.set_user({"id": "1", "email": "test@example.com", "username": "test"}) envelopes = capture_envelopes() @@ -507,26 +507,6 @@ def test_user_attributes(sentry_init, capture_envelopes): } -def test_user_attributes_no_pii(sentry_init, capture_envelopes): - """Ensure no user attributes are sent if send_default_pii is False.""" - sentry_init(_experiments={"enable_logs": True}) - - sentry_sdk.set_user({"id": "1", "email": "test@example.com", "username": "test"}) - envelopes = capture_envelopes() - - python_logger = logging.Logger("test-logger") - python_logger.warning("Hello, world!") - - get_client().flush() - - logs = envelopes_to_logs(envelopes) - - (log,) = logs - assert "user.id" not in log["attributes"] - assert "user.email" not in log["attributes"] - assert "user.name" not in log["attributes"] - - @minimum_python_37 def test_auto_flush_logs_after_5s(sentry_init, capture_envelopes): """