From 765c10d4406db7b27816823680dfcd9e5eab433b Mon Sep 17 00:00:00 2001 From: JonasBa Date: Wed, 25 Oct 2023 13:49:42 -0400 Subject: [PATCH 1/3] react: check browser profiling organization flag --- src/sentry/web/frontend/react_page.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sentry/web/frontend/react_page.py b/src/sentry/web/frontend/react_page.py index edd91a7c8ac4e..781bdccfd5d2c 100644 --- a/src/sentry/web/frontend/react_page.py +++ b/src/sentry/web/frontend/react_page.py @@ -90,7 +90,10 @@ def handle_react(self, request: Request, **kwargs) -> HttpResponse: return HttpResponseRedirect(redirect_url) response = render_to_response("sentry/base-react.html", context=context, request=request) - if "x-sentry-browser-profiling" in request.headers: + if "x-sentry-browser-profiling" in request.headers or ( + getattr(request, "organization", None) is not None + and features.has("organizations:profiling-browser", request.orgnization) + ): response["Document-Policy"] = "js-profiling" return response From bab4a6ae7677aeccfda923fbc618778fd39604a8 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 25 Oct 2023 14:22:30 -0400 Subject: [PATCH 2/3] Update src/sentry/web/frontend/react_page.py Co-authored-by: Mark Story --- src/sentry/web/frontend/react_page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/web/frontend/react_page.py b/src/sentry/web/frontend/react_page.py index 781bdccfd5d2c..a9355b6c4ee23 100644 --- a/src/sentry/web/frontend/react_page.py +++ b/src/sentry/web/frontend/react_page.py @@ -92,7 +92,7 @@ def handle_react(self, request: Request, **kwargs) -> HttpResponse: response = render_to_response("sentry/base-react.html", context=context, request=request) if "x-sentry-browser-profiling" in request.headers or ( getattr(request, "organization", None) is not None - and features.has("organizations:profiling-browser", request.orgnization) + and features.has("organizations:profiling-browser", request.organization) ): response["Document-Policy"] = "js-profiling" return response From d682142917c485e96d7f5282423531e51e223905 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Wed, 25 Oct 2023 16:27:03 -0400 Subject: [PATCH 3/3] test(react_page): add header test --- src/sentry/web/frontend/react_page.py | 16 ++++++++---- tests/sentry/web/frontend/test_react_page.py | 27 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/sentry/web/frontend/react_page.py b/src/sentry/web/frontend/react_page.py index a9355b6c4ee23..6f2a7b02b8a9d 100644 --- a/src/sentry/web/frontend/react_page.py +++ b/src/sentry/web/frontend/react_page.py @@ -1,5 +1,6 @@ from fnmatch import fnmatch +import sentry_sdk from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.http import HttpResponse, HttpResponseRedirect @@ -90,11 +91,16 @@ def handle_react(self, request: Request, **kwargs) -> HttpResponse: return HttpResponseRedirect(redirect_url) response = render_to_response("sentry/base-react.html", context=context, request=request) - if "x-sentry-browser-profiling" in request.headers or ( - getattr(request, "organization", None) is not None - and features.has("organizations:profiling-browser", request.organization) - ): - response["Document-Policy"] = "js-profiling" + + try: + if "x-sentry-browser-profiling" in request.headers or ( + getattr(request, "organization", None) is not None + and features.has("organizations:profiling-browser", request.organization) + ): + response["Document-Policy"] = "js-profiling" + except Exception as error: + sentry_sdk.capture_exception(error) + return response diff --git a/tests/sentry/web/frontend/test_react_page.py b/tests/sentry/web/frontend/test_react_page.py index 902ab30f74f2b..1b0b8de644841 100644 --- a/tests/sentry/web/frontend/test_react_page.py +++ b/tests/sentry/web/frontend/test_react_page.py @@ -338,3 +338,30 @@ def test_customer_domain_org_deletion_in_progress(self): ("http://testserver/organizations/new/", 302), ] assert "activeorg" not in self.client.session + + def test_document_policy_header_when_flag_is_enabled(self): + org = self.create_organization(owner=self.user) + + self.login_as(self.user) + + with self.feature({"organizations:profiling-browser": [org.slug]}): + response = self.client.get( + "/issues/", + SERVER_NAME=f"{org.slug}.testserver", + follow=True, + ) + assert response.status_code == 200 + assert response.headers["Document-Policy"] == "js-profiling" + + def test_document_policy_header_when_flag_is_disabled(self): + org = self.create_organization(owner=self.user) + + self.login_as(self.user) + + response = self.client.get( + "/issues/", + SERVER_NAME=f"{org.slug}.testserver", + follow=True, + ) + assert response.status_code == 200 + assert "Document-Policy" not in response.headers