getsentry / raven-python

Raven is the legacy Python client for Sentry (getsentry.com) — replaced by sentry-python
https://sentry.io
BSD 3-Clause "New" or "Revised" License
1.68k stars 657 forks source link

Django logs shell exceptions (with Django > 2.0) #1179

Open mjtamlyn opened 6 years ago

mjtamlyn commented 6 years ago

I'm not completely sure whether this is a change in Django or in Raven.

I've started seeing typos in the manage.py shell log to Sentry since I upgraded to django 2.0, raven 6.4.0 and Python 3.6. I've come up with a hacky work around, but it did clarify that there's no easy way to disable the sentry client that I could find documented.

Is there any change at this end which might have caused this?

ashwoods commented 6 years ago

Hi marc! Can't think of any change, my guess is this is on the django end. Which django version exactly are you using? The only recent changes I see after a quick view is the usage of contextlib.supress

ashwoods commented 6 years ago

And the revert to try-except

mjtamlyn commented 6 years ago
$ python --version
Python 3.6.3
$ django-admin --version
2.0.1

I didn't see this behaviour on Django 1.11.X with Python 2.7.

I'm using a settings.LOGGING config to connect Sentry - https://gist.github.com/mjtamlyn/f640dfac2a4f4a2568f2ca13ba178390

I've also got 'raven.contrib.django.raven_compat' in my INSTALLED_APPS

Ivaylo-Bachvarov commented 6 years ago

Hey,

I am using python 3.6.3 with django 1.11.5 and raven 6.2.1.

Heaving the same problem. Everytime someone misspells something in the shell we receive the error in sentry. @mjtamlyn Can you share you hacky solution?

mjtamlyn commented 6 years ago

Haven't managed to find a good one unfortunately. I think there's some default raven logging to catch all fatal errors now, or Django has started catching shell errors and reporting them (although I can't find any code for the latter).

dbarbeau commented 6 years ago

I'm having this problem with Django 1.11.x, Raven 6.3.0 and Python 3.6.3. The same thing but with Python 3.5 doesn't seem to show the error. Setups running on Raven 5.X and Python 2.7 do not have this issue.

hjkelly commented 6 years ago

I'm having this problem too, with Python 3.4.7, Django 1.10.4, and Raven 6.5.0.

I saw that when in ./manage.py shell, __name__ == 'builtins', so I tried updating my Django settings' LOGGING to have the 'builtins' logger only handled by console, but it still goes to Sentry.

tobami commented 6 years ago

We are also having this problem with Python 3.6 and Django 1.11

It's an issue that prevents us form directly hooking Sentry directly to alert systems.

iyawnis commented 6 years ago

Also having the issue where shell errors are showing in sentry, which is something that did not used to happen. Django==1.11.9 raven==6.6.0

jacobwegner commented 6 years ago

I think I've tracked this down to the (good!) change that happened between 6.0.0 and 6.1.0:

fix registration of hooks for Django

PR: https://github.com/getsentry/raven-python/pull/966

Original issue: https://github.com/getsentry/raven-python/issues/884

Since install_sys_hook is working correctly, exceptions raised within a manage.py|django-admin.py session are handled by Sentry.

Here is a basic workaround I've settled on (YMMV):

# in settings.py
import sys
SHELL = "shell" in sys.argv
...
RAVEN_CONFIG = {
    "ignore_exceptions": ("*") if SHELL else ()
}

In should_capture, the wildcard"*" will match any exception.

Other manage.py commands that don't have a "shell" argument will continue to send exceptions to Sentry.

tobami commented 6 years ago

I can confirm that the RAVEN_CONFIG described by @jacobwegner works well. Many thanks!

rowanseymour commented 6 years ago

@jacobwegner it still works (thanks!), but I think in your solution you meant ("*",) instead of ("*")?