Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Sentry reporting when using djangos `manage.py shell`

I am using sentry to report errors ocurring in my django app.

Is there a way to disable sentry error reporting when using a command like

python manage.py shell

like image 462
David Schumann Avatar asked Sep 04 '18 15:09

David Schumann


2 Answers

For ignoring some or all types of exceptions in Sentry you can use ignore_exceptions option for RAVEN_CONFIG in your settings.py file. ignore_exceptions accepts a list of Exception Classes or String Paths. You can read more about ignoring exceptions in Sentry docs here: https://docs.sentry.io/clients/python/advanced/

To ignore all exceptions, you can pass ['*'] to ignore_exceptions, but you want to do this only when the django process has been started with the mentioned command in question, which could be known from sys.argv. So, your desired outcome could be achieved by adding following codes to your django settings.py file:

import sys
SHOULD_IGNORE_EXCEPTIONS = " ".join(sys.argv).endswith("run python manage.py shell")

RAVEN_CONFIG = {
    'dsn': '...',
    'ignore_exceptions': ['*'] if SHOULD_IGNORE_EXCEPTIONS else [],
}
like image 170
ar-m-an Avatar answered Sep 22 '22 23:09

ar-m-an


There is an undocumented but definetly stable setting for that:

RAVEN_CONFIG = {
    'install_sys_hook': False
}
like image 34
Markus Unterwaditzer Avatar answered Sep 22 '22 23:09

Markus Unterwaditzer