Sentinel / raven with django: how to ignore some exceptions?

I would like watchry / raven to ignore all exceptions from a particular function or django module, but when studying documents and code, I saw only the ability to ignore a custom exception by adding an additional attribute to it. Is there a way to ignore exceptions by function name or module name? Thanks!

+7
python django exception sentry
source share
1 answer

Reading through the source of the raven, I saw that if you want to ignore some exceptions, you can add them to IGNORE_EXCEPTIONS as follows:

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

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

You can do it as follows:

 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 user client in settings.py :

 SENTRY_CLIENT = 'path.to.module.MyClient' 

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

+5
source share

All Articles