Created
February 25, 2018 04:07
-
-
Save ketanbhatt/01f69978fd5a800924a8781e805bffb3 to your computer and use it in GitHub Desktop.
Custom Sentry Client for ignoring specific errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from raven.contrib.django.client import DjangoClient | |
ignore_exc_msg_prefixes = getattr(settings, 'CUSTOM_SENTRY_CLIENT_IGNORE_EXCEPTION_MESSAGE_PREFIXES', []) | |
class IgnoreExceptionsDjangoClient(DjangoClient): | |
""" | |
Overrides DjangoClient's `skip_error_for_logging` method.CUSTOM_SENTRY_CLIENT_IGNORE_EXCEPTION_MESSAGE_PREFIXES | |
Checks raised error message for prefixes defined in settings.CUSTOM_SENTRY_CLIENT_IGNORE_EXCEPTION_MESSAGE_PREFIXES | |
If the error message has any of the given prefix, skips logging the exception | |
""" | |
def skip_error_for_logging(self, exc_info): | |
skip_error = super(IgnoreExceptionsDjangoClient, self).skip_error_for_logging(exc_info) | |
if not skip_error and ignore_exc_msg_prefixes: | |
error_msg = exc_info[1].message | |
if isinstance(error_msg, basestring): | |
for prefix in ignore_exc_msg_prefixes: | |
if error_msg.startswith(prefix): | |
skip_error = True | |
break | |
return skip_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SENTRY_CLIENT = 'path.to.sentry_client.IgnoreExceptionsDjangoClient' | |
CUSTOM_SENTRY_CLIENT_IGNORE_EXCEPTION_MESSAGE_PREFIXES = [ | |
"Couldn't load object" # raised by celery_haystack task | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment