From d596df9512ba47960a95ce93630f8fbbd74bf03b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 14 Sep 2026 20:59:01 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(backend)=20allow=20configuring=20trac?= =?UTF-8?q?e=20sampling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a configuration knob for the trace sampling rate, so we can enable tracing on middleware and cache spans when debugging slow requests in production. Sampling is set to 0 by default, so tracing stays fully off unless explicitly enabled. Copied from suitenumerique/meet#1690 --- documentation/env.md | 1 + src/backend/impress/settings.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/documentation/env.md b/documentation/env.md index 18a42cbfb..c8c88e624 100644 --- a/documentation/env.md +++ b/documentation/env.md @@ -143,6 +143,7 @@ These are the environment variables you can set for the `impress-backend` contai | SEARCH_INDEXER_SECRET | Token required for indexation queries | | | INDEXING_URL | Find application endpoint for indexation | | | SENTRY_DSN | Sentry host | | +| SENTRY_TRACES_SAMPLE_RATE | The `traces_sample_rate` used when the sentry sdl is configured. Value is between `0` and `1` | 0.0 | | SESSION_COOKIE_AGE | duration of the cookie session | 60*60*12 | | SIGNUP_NEW_USER_TO_MARKETING_EMAIL | Register new user to the marketing onboarding. If True, see env LASUITE_MARKETING_* system | False | | SILK_ENABLED | Enable the django-silk request/SQL/cProfile profiler and its /silk/ UI. OFF by default; never enable against production with real users. See documentation/profiling.md | False | diff --git a/src/backend/impress/settings.py b/src/backend/impress/settings.py index 8ce02952b..3a5948058 100755 --- a/src/backend/impress/settings.py +++ b/src/backend/impress/settings.py @@ -532,6 +532,9 @@ class Base(Configuration): # Sentry SENTRY_DSN = values.Value(None, environ_name="SENTRY_DSN", environ_prefix=None) + SENTRY_TRACES_SAMPLE_RATE = values.FloatValue( + 0.0, environ_name="SENTRY_TRACES_SAMPLE_RATE", environ_prefix=None + ) # Collaboration COLLABORATION_API_URL = values.Value( @@ -1242,7 +1245,14 @@ class Base(Configuration): dsn=cls.SENTRY_DSN, environment=cls.__name__.lower(), release=get_release(), - integrations=[DjangoIntegration()], + traces_sample_rate=cls.SENTRY_TRACES_SAMPLE_RATE, + integrations=[ + DjangoIntegration( + transaction_style="url", + middleware_spans=True, + cache_spans=True, + ) + ], ) sentry_sdk.set_tag("application", "backend")