From 85784f796c900ab6ebded297e58fa2da1017af23 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 10 Jun 2022 20:10:27 +0200 Subject: [PATCH] root: ignore healthcheck routes in sentry tracing Signed-off-by: Jens Langhammer --- authentik/lib/sentry.py | 10 +++++++++- authentik/root/test_runner.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/authentik/lib/sentry.py b/authentik/lib/sentry.py index 0868bd7e3..94b48b8aa 100644 --- a/authentik/lib/sentry.py +++ b/authentik/lib/sentry.py @@ -56,7 +56,6 @@ def sentry_init(**sentry_init_kwargs): """Configure sentry SDK""" sentry_env = CONFIG.y("error_reporting.environment", "customer") kwargs = { - "traces_sample_rate": float(CONFIG.y("error_reporting.sample_rate", 0.5)), "environment": sentry_env, "send_default_pii": CONFIG.y_bool("error_reporting.send_pii", False), } @@ -71,6 +70,7 @@ def sentry_init(**sentry_init_kwargs): ThreadingIntegration(propagate_hub=True), ], before_send=before_send, + traces_sampler=traces_sampler, release=f"authentik@{__version__}", **kwargs, ) @@ -83,6 +83,14 @@ def sentry_init(**sentry_init_kwargs): ) +def traces_sampler(sampling_context: dict) -> float: + """Custom sampler to ignore certain routes""" + # Ignore all healthcheck routes + if sampling_context.get("asgi_scope", {}).get("path", "").startswith("/-/health/"): + return 0 + return float(CONFIG.y("error_reporting.sample_rate", 0.5)) + + def before_send(event: dict, hint: dict) -> Optional[dict]: """Check if error is database error, and ignore if so""" # pylint: disable=no-name-in-module diff --git a/authentik/root/test_runner.py b/authentik/root/test_runner.py index 9cbbf7bb3..2f3f7716f 100644 --- a/authentik/root/test_runner.py +++ b/authentik/root/test_runner.py @@ -33,8 +33,8 @@ class PytestTestRunner: # pragma: no cover "outposts.container_image_base", f"ghcr.io/goauthentik/dev-%(type)s:{get_docker_tag()}", ) + CONFIG.y_set("error_reporting.sample_rate", 1.0) sentry_init( - sample_rate=1.0, environment="testing", send_default_pii=True, )