From d06f7e3ebe5ef391ed873b64f496acc3b30ac457 Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Wed, 30 Oct 2024 22:27:29 +0100 Subject: [PATCH 1/2] =?UTF-8?q?N'envoie=20pas=20=C3=A0=20Sentry=20les=20Ke?= =?UTF-8?q?yboardInterrupt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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..e02ff73635 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, intentionnally 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 From 6652f625a9383a83b7f7509e4922fc1a92bdc2ee Mon Sep 17 00:00:00 2001 From: Situphen Date: Thu, 31 Oct 2024 00:46:43 +0100 Subject: [PATCH 2/2] Typo --- zds/settings/prod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zds/settings/prod.py b/zds/settings/prod.py index e02ff73635..8ddd89f6eb 100644 --- a/zds/settings/prod.py +++ b/zds/settings/prod.py @@ -88,7 +88,7 @@ def _get_version(): 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, intentionnally by the user. + # manage.py commands in an interactive shell, intentionally by the user. if hint.get("exc_info", [None])[0] == KeyboardInterrupt: return None