Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N'envoie pas à Sentry les KeyboardInterrupt #6678

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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