Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react: check browser profiling organization flag on react render #58781

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/sentry/web/frontend/react_page.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -90,8 +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:
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


Expand Down
27 changes: 27 additions & 0 deletions tests/sentry/web/frontend/test_react_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading