I'd like to log 404 Not Found errors codes to Sentry in Django 1.7.
What hooks Django provides so I could push logger.error()
message for these?
Any other ideas how one should monitor non-500 missing / weirdly behaving pages with Django and Sentry?
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page. Let's do that by turning off Django debug mode. For this, we need to update the settings.py file.
Sentry's Django integration enables automatic reporting of errors and exceptions. Sentry's Django integration reports all exceptions leading to an Internal Server Error and creates a separate scope for each request. The integration supports Django Web Framework from Version 1.6 and above .
Checkout the Reporting other status codes section of the Sentry Docs for Django:
If you want to report 404 Not Found and other errors besides uncaught exceptions (500 Internal Server Error) to Sentry, you need to write your own Django view for those status codes. For example:
# in the root URL conf urls.py
handler404 = 'myapp.views.my_custom_page_not_found_view'
# myapp/views.py
from django.http import HttpResponseNotFound
from sentry_sdk import capture_message
def my_custom_page_not_found_view(*args, **kwargs):
capture_message("Page not found!", level="error")
# return any response here, e.g.:
return HttpResponseNotFound("Not found")
For more information on customizing errors, read the relevant Django Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With