Skip to content

Commit 72042da

Browse files
committed
feat(sentry): setup before_send to ignore global id errors by message
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.
1 parent bc6e627 commit 72042da

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

kukkuu/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,18 @@ def sentry_before_send(event: Event, hint: Hint):
167167
"""
168168

169169
IGNORED_ERRORS_CLASSES = (ExpiredSignatureError, AuthenticationExpiredError)
170+
IGNORED_ERROR_MESSAGES = [
171+
# This is raised when an id in URL or form input does not match.
172+
# It is easily triggered by the user when URL is modified
173+
# and does not need to be reported.
174+
"Unable to parse global ID",
175+
]
170176
if "exc_info" in hint:
171177
exc_type, exc_value, traceback = hint["exc_info"]
172178
if isinstance(exc_value, IGNORED_ERRORS_CLASSES):
173179
return None
180+
if any(msg in str(exc_value) for msg in IGNORED_ERROR_MESSAGES):
181+
return None
174182
return event
175183

176184

kukkuu/tests/test_sentry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from kukkuu.settings import sentry_before_send
66

77
test_cases = [
8+
(Exception("Unable to parse global ID."), True),
9+
(Exception('Unable to parse global ID "some_id".'), True),
810
(ExpiredSignatureError("Expired signature"), True),
911
(AuthenticationExpiredError("Authentication expired"), True),
1012
(Exception("Some other error"), False),

0 commit comments

Comments
 (0)