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

Reduce Sentry trace sampling for dev, test and staging #289

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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
17 changes: 17 additions & 0 deletions request_a_govuk_domain/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,27 @@
if SENTRY_DSN is not None:
import sentry_sdk

def traces_sampler(sampling_context):
# Disable the health check and the email failure task sampling and
# also reduce the sampling for other events by 1/5, for the prod environment we sample 100%
if (
sampling_context["transaction_context"]["name"]
== "request_a_govuk_domain.request.tasks.check_email_failure_and_notify"
) or (
sampling_context["transaction_context"]["name"] == "generic WSGI request"
and sampling_context["wsgi_environ"]["HTTP_USER_AGENT"]
== "ELB-HealthChecker/2.0"
):
return 0.0 if ENVIRONMENT in ["dev", "test", "stage"] else 0.1
else:
# Any other traces reduce the rate for non-prod
return 0.2 if ENVIRONMENT in ["dev", "test"] else 1

sentry_sdk.init(
dsn=SENTRY_DSN,
enable_tracing=True,
environment=ENVIRONMENT,
traces_sampler=traces_sampler,
)

# Only enable S3 storage if it is explicitly enabled or on AWS
Expand Down