Skip to content

Commit

Permalink
N'envoie pas à Sentry les KeyboardInterrupt (zestedesavoir#6678)
Browse files Browse the repository at this point in the history
* N'envoie pas à Sentry les KeyboardInterrupt

* Typo

---------

Co-authored-by: Situphen <[email protected]>
  • Loading branch information
philippemilink and Situphen authored Oct 30, 2024
1 parent f183502 commit aaeb44d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion zds/settings/prod.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -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()],
Expand All @@ -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
Expand Down

0 comments on commit aaeb44d

Please sign in to comment.