From 2f724592e0b74349f859154c40c0d12fd08daca3 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 25 May 2021 12:40:16 +0200 Subject: [PATCH] Sentry: Add trace tokens --- doc/admin/config.rst | 4 ++++ src/pretix/settings.py | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/admin/config.rst b/doc/admin/config.rst index dfc4160e2..08219fad9 100644 --- a/doc/admin/config.rst +++ b/doc/admin/config.rst @@ -351,6 +351,7 @@ application. If you want to use sentry, you need to set a DSN in the configurati [sentry] dsn=https://:@sentry.io/ traces_sample_rate=0.5 + traces_sample_token=xyz ``dsn`` You will be given this value by your sentry installation. @@ -358,6 +359,9 @@ application. If you want to use sentry, you need to set a DSN in the configurati ``traces_sample_rate`` Sample rate for performance monitoring. +``traces_sample_token`` + If this token is found in a query string, a trace will always be sampled. + Caching ------- diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 147bb4f20..1316fda71 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -712,6 +712,14 @@ if config.has_option('sentry', 'dsn') and not any(c in sys.argv for c in ('shell from .sentry import PretixSentryIntegration, setup_custom_filters + SENTRY_TOKEN = config.get('sentry', 'traces_sample_token', fallback='') + + def traces_sampler(sampling_context): + qs = sampling_context.get('wsgi_environ', {}).get('QUERY_STRING', '') + if SENTRY_TOKEN and SENTRY_TOKEN in qs: + return 1.0 + return config.getfloat('sentry', 'traces_sample_rate', fallback=0.0) + SENTRY_ENABLED = True sentry_sdk.init( dsn=config.get('sentry', 'dsn'), @@ -723,7 +731,7 @@ if config.has_option('sentry', 'dsn') and not any(c in sys.argv for c in ('shell event_level=logging.CRITICAL ) ], - traces_sample_rate=config.getfloat('sentry', 'traces_sample_rate', fallback=0.0), + traces_sampler=traces_sampler, environment=urlparse(SITE_URL).netloc, release=__version__, send_default_pii=False,