From aaeb44d729da62ae81a9ac683d009f8f25d0ace3 Mon Sep 17 00:00:00 2001 From: "Ph. SW." Date: Thu, 31 Oct 2024 00:53:17 +0100 Subject: [PATCH] =?UTF-8?q?N'envoie=20pas=20=C3=A0=20Sentry=20les=20`Keybo?= =?UTF-8?q?ardInterrupt`=20(#6678)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N'envoie pas à Sentry les KeyboardInterrupt * Typo --------- Co-authored-by: Situphen --- zds/settings/prod.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/zds/settings/prod.py b/zds/settings/prod.py index 3fdc86a2ed..8ddd89f6eb 100644 --- a/zds/settings/prod.py +++ b/zds/settings/prod.py @@ -1,6 +1,7 @@ +import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.logging import ignore_logger -import sentry_sdk +from sentry_sdk.types import Event, Hint from .abstract_base import * @@ -85,6 +86,15 @@ def _get_version(): return f"{__version__}/{git_version[:7]}" +def sentry_before_send(event: Event, hint: Hint) -> Event: + # Do not log KeyboardInterrupt exceptions: they can only be triggered from + # manage.py commands in an interactive shell, intentionally by the user. + if hint.get("exc_info", [None])[0] == KeyboardInterrupt: + return None + + return event + + sentry_sdk.init( dsn=config["sentry"]["dsn"], integrations=[DjangoIntegration()], @@ -102,6 +112,7 @@ def _get_version(): release=_get_version().replace("/", "#"), # /!\ It cannot contain slashes environment=config["sentry"]["environment"], + before_send=sentry_before_send, ) # Ignoring emarkdown logging because it is too noisy