Skip to content

Instantly share code, notes, and snippets.

@ketanbhatt
Created February 25, 2018 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketanbhatt/01f69978fd5a800924a8781e805bffb3 to your computer and use it in GitHub Desktop.
Save ketanbhatt/01f69978fd5a800924a8781e805bffb3 to your computer and use it in GitHub Desktop.
Custom Sentry Client for ignoring specific errors
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
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