Skip to content

Commit

Permalink
feat(sentry): setup before_send to ignore global id errors by message
Browse files Browse the repository at this point in the history
KK-1395.

The ignore_messages option in sentry_sdk would be great, but since the
Graphene raises a general Exception from invalid global ids, we need to
follow the exception message instead of class.
  • Loading branch information
nikomakela committed Jan 10, 2025
1 parent 24b03ca commit d4b9074
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kukkuu/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from datetime import datetime

import environ
from jose import ExpiredSignatureError
import sentry_sdk
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import gettext_lazy as _
from jose import ExpiredSignatureError
from sentry_sdk.integrations.django import DjangoIntegration

from kukkuu.consts import CSP
Expand Down Expand Up @@ -149,16 +149,23 @@
def sentry_before_send(event, hint):
"""
Ignore certain errors from being sent to Sentry.
Some Graphene errors are generic Exceptions that are not useful to log.
Since they are generic, we need to ignore them by their message.
NOTE: The `ignore_errors` option is actually deprecated,
nevertheless it's included in the init configuration.
See https://github.com/getsentry/sentry-python/issues/149
"""

IGNORED_ERRORS_CLASSES = (ExpiredSignatureError, AuthenticationExpiredError)
IGNORED_ERROR_MESSAGES = [
"Unable to parse global ID",
]
if "exc_info" in hint:
exc_type, exc_value, tb = hint["exc_info"]
if isinstance(exc_value, IGNORED_ERRORS_CLASSES):
return None
if any(msg in exc_value.args[0] for msg in IGNORED_ERROR_MESSAGES):
return None
return event


Expand Down
2 changes: 2 additions & 0 deletions kukkuu/tests/test_sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from kukkuu.settings import sentry_before_send

test_cases = [
(Exception("Unable to parse global ID."), True),
(Exception('Unable to parse global ID "some_id".'), True),
(ExpiredSignatureError("Expired signature"), True),
(AuthenticationExpiredError("Authentication expired"), True),
(Exception("Some other error"), False),
Expand Down

0 comments on commit d4b9074

Please sign in to comment.