Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
sentry: Send user identifiers, but strip PII.
Alex Vandiver3d24571cad3e
diff --git a/zproject/sentry.py b/zproject/sentry.pyindex 9d29270d1fa..18125f00f63 100644--- a/zproject/sentry.py+++ b/zproject/sentry.py@@ -26,6 +26,9 @@ def add_context(event: 'Event', hint: 'Hint') -> Optional['Event']:from zerver.models import get_user_profile_by_idwith capture_internal_exceptions():+ # event.user is the user context, from Sentry, which is+ # pre-populated with some keys via its Django integration:+ # https://docs.sentry.io/platforms/python/guides/django/enriching-error-data/additional-data/identify-user/user_info = event.get("user", {})if user_info.get("id"):user_profile = get_user_profile_by_id(user_info["id"])@@ -34,6 +37,11 @@ def add_context(event: 'Event', hint: 'Hint') -> Optional['Event']:# str() to force the lazy-translation to apply now,# since it won't serialize into json for Sentry otherwiseuser_info["role"] = str(user_profile.get_role_name())+ # These are PII, and should be scrubbed+ if "username" in user_info:+ del user_info["username"]+ if "email" in user_info:+ del user_info["email"]return eventdef setup_sentry(dsn: Optional[str], *integrations: Integration) -> None:@@ -50,6 +58,14 @@ def setup_sentry(dsn: Optional[str], *integrations: Integration) -> None:*integrations,],before_send=add_context,+ # Because we strip the email/username from the Sentry data+ # above, the effect of this flag is that the requests/users+ # involved in exceptions will be identified in Sentry only by+ # their IP address, user ID, realm, and role. We consider+ # this an appropriate balance between avoiding Sentry getting+ # PII while having the identifiers needed to determine that an+ # exception only affects a small subset of users or realms.+ send_default_pii=True,)# Ignore all of the loggers from django.security that are for user