From ef380fa13da5735d7db8d00851f86da3e1021fd0 Mon Sep 17 00:00:00 2001 From: Dharshana Vanderbona Date: Wed, 13 Nov 2024 13:41:03 +0000 Subject: [PATCH] Reduce Sentry trace sampling for dev, test and staging We have a couple of known endpoints, that constantly hit the application making the sampling quote full. Change the code so that we do not sample the known events as well as reduce sampling for other events on dev + stage. --- request_a_govuk_domain/settings.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/request_a_govuk_domain/settings.py b/request_a_govuk_domain/settings.py index c1f1f7b8..baf2d4e2 100644 --- a/request_a_govuk_domain/settings.py +++ b/request_a_govuk_domain/settings.py @@ -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