From f66e2c31128df929272ce9f0d2dadd85941cd698 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 10 Jul 2023 17:30:32 -0400 Subject: [PATCH] sentry: Remove dependence on get_current_request. Signed-off-by: Anders Kaseorg --- zerver/middleware.py | 6 +++++- zproject/sentry.py | 8 -------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/zerver/middleware.py b/zerver/middleware.py index 30df1fcfb0..23348aae18 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -22,7 +22,7 @@ from django.utils.translation import gettext as _ from django.views.csrf import csrf_failure as html_csrf_failure from django_scim.middleware import SCIMAuthCheckMiddleware from django_scim.settings import scim_settings -from sentry_sdk import capture_exception +from sentry_sdk import capture_exception, set_tag from sentry_sdk.integrations.logging import ignore_logger from typing_extensions import Concatenate, ParamSpec @@ -296,6 +296,8 @@ class LogRequests(MiddlewareMixin): request_notes.client_name = "Unparsable" request_notes.client_version = None + set_tag("client", request_notes.client_name) + request_notes.log_data = {} record_request_start_data(request_notes.log_data) @@ -563,6 +565,8 @@ class HostDomainMiddleware(MiddlewareMixin): return render(request, "zerver/invalid_realm.html", status=404) + set_tag("realm", request_notes.realm.string_id) + # Check that we're not using the non-canonical form of a REALM_HOSTS subdomain if subdomain in settings.REALM_HOSTS: host = request.get_host().lower() diff --git a/zproject/sentry.py b/zproject/sentry.py index e889710e3c..ff8850ddbf 100644 --- a/zproject/sentry.py +++ b/zproject/sentry.py @@ -24,7 +24,6 @@ def add_context(event: "Event", hint: "Hint") -> Optional["Event"]: return None from django.conf import settings - from zerver.lib.request import RequestNotes, get_current_request from zerver.models import get_user_profile_by_id with capture_internal_exceptions(): @@ -47,13 +46,6 @@ def add_context(event: "Event", hint: "Hint") -> Optional["Event"]: if "email" in user_info: del user_info["email"] - request = get_current_request() - if request: - request_notes = RequestNotes.get_notes(request) - if request_notes.client is not None: - event["tags"]["client"] = request_notes.client.name - if request_notes.realm is not None: - event["tags"].setdefault("realm", request_notes.realm.string_id) return event