From d2cfb76a7c65032332e1d0b3e23ccdbbaca9615b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 20 Feb 2023 21:32:35 +0100 Subject: [PATCH] root: don't trace websockets to sentry Signed-off-by: Jens Langhammer --- authentik/lib/sentry.py | 15 +++------------ authentik/root/websocket.py | 5 ++--- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/authentik/lib/sentry.py b/authentik/lib/sentry.py index d4cedd339..6166d0342 100644 --- a/authentik/lib/sentry.py +++ b/authentik/lib/sentry.py @@ -36,18 +36,6 @@ from authentik.lib.utils.reflection import class_to_path, get_env LOGGER = get_logger() -class SentryWSMiddleware(BaseMiddleware): - """Sentry Websocket middleweare to set the transaction name based on - consumer class path""" - - async def __call__(self, scope, receive, send): - transaction: Optional[Transaction] = Hub.current.scope.transaction - class_path = class_to_path(self.inner.consumer_class) - if transaction: - transaction.name = class_path - return await self.inner(scope, receive, send) - - class SentryIgnoredException(Exception): """Base Class for all errors that are suppressed, and not sent to sentry.""" @@ -94,9 +82,12 @@ def sentry_init(**sentry_init_kwargs): def traces_sampler(sampling_context: dict) -> float: """Custom sampler to ignore certain routes""" path = sampling_context.get("asgi_scope", {}).get("path", "") + _type = sampling_context.get("asgi_scope", {}).get("type", "") # Ignore all healthcheck routes if path.startswith("/-/health") or path.startswith("/-/metrics"): return 0 + if _type == "websocket": + return 0 return float(CONFIG.y("error_reporting.sample_rate", 0.1)) diff --git a/authentik/root/websocket.py b/authentik/root/websocket.py index 8a8bc1d86..d53b52a12 100644 --- a/authentik/root/websocket.py +++ b/authentik/root/websocket.py @@ -2,11 +2,10 @@ from channels.auth import AuthMiddlewareStack from django.urls import path -from authentik.lib.sentry import SentryWSMiddleware from authentik.outposts.channels import OutpostConsumer from authentik.root.messages.consumer import MessageConsumer websocket_urlpatterns = [ - path("ws/outpost//", SentryWSMiddleware(OutpostConsumer.as_asgi())), - path("ws/client/", AuthMiddlewareStack(SentryWSMiddleware(MessageConsumer.as_asgi()))), + path("ws/outpost//", OutpostConsumer.as_asgi()), + path("ws/client/", AuthMiddlewareStack(MessageConsumer.as_asgi())), ]