Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sentry/raven with django: how to ignore certain exceptions?

I'd like sentry/raven to ignore all exceptions from a certain function or django module, but looking into the docs and the code, I only saw an option to ignore a custom exception by adding an extra attribute to it. Is there a way to ignore exceptions by function name or module name? Thanks!

like image 740
Z. Lin Avatar asked Jul 17 '14 02:07

Z. Lin


1 Answers

Reading through the source of raven I saw that if you'd like to ignore a certain exceptions you can add them to IGNORE_EXCEPTIONS like this:

RAVEN_CONFIG = {
    'dsn': '...',
    'IGNORE_EXCEPTIONS': ['exceptions.ZeroDivisionError', 'some.other.module.CustomException'],
    ...
}

As for exclusion of certain modules/files the best way would probably be to write your own client and decide whether or not to send a message to sentry. It think you should override the send method since it has all the data in more accessible form.

You could do it like this:

from raven.contrib.django.client import DjangoClient


class MyClient(DjangoClient):

    def send(self, **kwargs):
        '''
        check if culprit (event name) should be skipped
        '''
        if kwargs.get('culprit', '').startswith('my.module.to.skip'):
            self.logger.info('Skipping entry')
        else:
            return super(MyClient, self).send(**kwargs)

and then set your custom client in settings.py:

SENTRY_CLIENT = 'path.to.module.MyClient'

If you want to implement more sophisticated rules for ignoring you should probably check what you can do with the given data (kwargs).

like image 117
slafs Avatar answered Oct 22 '22 21:10

slafs