add sentry id to 500 error page

parent caa97fc1
<p>You've encountered an error, oh noes!</p>
{% if request.sentry.id %}
<p>If you need assistance, you may reference this error as
<strong>{{ request.sentry.id }}</strong>.</p>
{% endif %}
...@@ -483,6 +483,11 @@ if os.environ.get('SENTRY_DSN'): ...@@ -483,6 +483,11 @@ if os.environ.get('SENTRY_DSN'):
'dsn': os.environ.get('SENTRY_DSN'), 'dsn': os.environ.get('SENTRY_DSN'),
'release': __version__, 'release': __version__,
} }
# add sentry ID to request for inclusion in templates
# https://docs.sentry.io/clients/python/integrations/django/#message-references
MIDDLEWARE_CLASSES = (
'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware',
) + MIDDLEWARE_CLASSES
# set javascript sentry token if provided # set javascript sentry token if provided
SENTRY_TOKEN = os.environ.get('SENTRY_TOKEN', 'https://a4f72b82fc0742bc82b82560b340006b@sentry.io/242170') SENTRY_TOKEN = os.environ.get('SENTRY_TOKEN', 'https://a4f72b82fc0742bc82b82560b340006b@sentry.io/242170')
...@@ -16,6 +16,7 @@ Including another URLconf ...@@ -16,6 +16,7 @@ Including another URLconf
from django.conf import settings from django.conf import settings
from django.conf.urls import include, url from django.conf.urls import include, url
from django.contrib import admin from django.contrib import admin
from django.template.response import TemplateResponse
# Django 1.10 http://stackoverflow.com/questions/38744285/ # Django 1.10 http://stackoverflow.com/questions/38744285/
# django-urls-error-view-must-be-a-callable-or-a-list-tuple-in-the-case-of-includ#38744286 # django-urls-error-view-must-be-a-callable-or-a-list-tuple-in-the-case-of-includ#38744286
...@@ -51,3 +52,17 @@ if settings.DEBUG: ...@@ -51,3 +52,17 @@ if settings.DEBUG:
# Nested inlines don't work with Django Jet (yet). # Nested inlines don't work with Django Jet (yet).
# urlpatterns += [url(r'^_nested_admin/', include('nested_admin.urls'))] # urlpatterns += [url(r'^_nested_admin/', include('nested_admin.urls'))]
# set a different page for 500 errors to include sentry event ID.
# https://docs.sentry.io/clients/python/integrations/django/#message-references
if settings.SENTRY_DSN:
def handler500(request):
"""500 error handler which includes ``request`` in the context.
Templates: `500.html`
Context: None
"""
context = {'request': request}
template_name = '500.html' # You need to create a 500.html template.
return TemplateResponse(request, template_name, context, status=500)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment