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 13, 2025
1 parent e3c4e4c commit 6be690a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kukkuu/settings.py
Original file line number Diff line number Diff line change
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, traceback = hint["exc_info"]
if isinstance(exc_value, IGNORED_ERRORS_CLASSES):
return None
if any(msg in str(exc_value) 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 6be690a

Please sign in to comment.