forked from CGM_Public/pretix_original
Fix raven integration
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class PretixBaseConfig(AppConfig):
|
||||
@@ -17,6 +18,10 @@ class PretixBaseConfig(AppConfig):
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
if hasattr(settings, 'RAVEN_CONFIG'):
|
||||
from ..sentry import initialize
|
||||
initialize()
|
||||
|
||||
|
||||
default_app_config = 'pretix.base.PretixBaseConfig'
|
||||
try:
|
||||
|
||||
@@ -6,6 +6,15 @@
|
||||
<h1>{% trans "Internal Server Error" %}</h1>
|
||||
<p>{% trans "We had trouble processing your request." %}</p>
|
||||
<p>{% trans "If this problem persists, please contact us." %}</p>
|
||||
{% if request.sentry.id %}
|
||||
<p>
|
||||
{% blocktrans trimmed %}
|
||||
If you contact us, please send us the following code:
|
||||
{% endblocktrans %}
|
||||
<br>
|
||||
{{ request.sentry.id }}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>{{ exception }}</p>
|
||||
<p class="links">
|
||||
<a id='goback' href='#'>{% trans "Take a step back" %}</a>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from django.http import HttpResponseForbidden, HttpResponseNotFound
|
||||
from django.http import (
|
||||
HttpResponseForbidden, HttpResponseNotFound, HttpResponseServerError,
|
||||
)
|
||||
from django.middleware.csrf import REASON_NO_CSRF_COOKIE, REASON_NO_REFERER
|
||||
from django.template import TemplateDoesNotExist, loader
|
||||
from django.template.loader import get_template
|
||||
from django.utils.functional import Promise
|
||||
from django.utils.translation import ugettext as _
|
||||
@@ -53,3 +56,14 @@ def page_not_found(request, exception):
|
||||
template = get_template('404.html')
|
||||
body = template.render(context, request)
|
||||
return HttpResponseNotFound(body)
|
||||
|
||||
|
||||
@requires_csrf_token
|
||||
def server_error(request):
|
||||
try:
|
||||
template = loader.get_template('500.html')
|
||||
except TemplateDoesNotExist:
|
||||
return HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html')
|
||||
return HttpResponseServerError(template.render({
|
||||
'request': request
|
||||
}))
|
||||
|
||||
@@ -9,10 +9,3 @@ from django.conf import settings
|
||||
app = Celery('pretix')
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
||||
|
||||
|
||||
if hasattr(settings, 'RAVEN_CONFIG'):
|
||||
# Celery signal registration
|
||||
from raven.contrib.celery import register_signal
|
||||
from raven.contrib.django.models import client
|
||||
register_signal(client, ignore_expected=True)
|
||||
|
||||
@@ -49,3 +49,4 @@ plugin_patterns = [
|
||||
urlpatterns = common_patterns + plugin_patterns + presale_patterns_main
|
||||
|
||||
handler404 = 'pretix.base.views.errors.page_not_found'
|
||||
handler500 = 'pretix.base.views.errors.server_error'
|
||||
|
||||
@@ -42,3 +42,4 @@ plugin_patterns = [
|
||||
urlpatterns = common_patterns + plugin_patterns + presale_patterns
|
||||
|
||||
handler404 = 'pretix.base.views.errors.page_not_found'
|
||||
handler500 = 'pretix.base.views.errors.server_error'
|
||||
|
||||
41
src/pretix/sentry.py
Normal file
41
src/pretix/sentry.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from threading import Lock
|
||||
|
||||
from raven.contrib.celery import SentryCeleryHandler
|
||||
from raven.contrib.django.apps import RavenConfig
|
||||
from raven.contrib.django.models import (
|
||||
SentryDjangoHandler, client, get_client, install_middleware,
|
||||
register_serializers,
|
||||
)
|
||||
|
||||
_setup_lock = Lock()
|
||||
|
||||
_initialized = False
|
||||
|
||||
|
||||
class CustomSentryDjangoHandler(SentryDjangoHandler):
|
||||
def install_celery(self):
|
||||
self.celery_handler = SentryCeleryHandler(client, ignore_expected=True).install()
|
||||
|
||||
|
||||
def initialize():
|
||||
global _initialized
|
||||
|
||||
with _setup_lock:
|
||||
if _initialized:
|
||||
return
|
||||
|
||||
register_serializers()
|
||||
install_middleware()
|
||||
|
||||
handler = CustomSentryDjangoHandler()
|
||||
handler.install()
|
||||
|
||||
# instantiate client so hooks get registered
|
||||
get_client() # NOQA
|
||||
|
||||
_initialized = True
|
||||
|
||||
|
||||
class App(RavenConfig):
|
||||
def ready(self):
|
||||
initialize()
|
||||
@@ -226,18 +226,6 @@ for entry_point in iter_entry_points(group='pretix.plugin', name=None):
|
||||
PLUGINS.append(entry_point.module_name)
|
||||
INSTALLED_APPS.append(entry_point.module_name)
|
||||
|
||||
if config.has_option('sentry', 'dsn'):
|
||||
INSTALLED_APPS += [
|
||||
'raven.contrib.django.raven_compat',
|
||||
]
|
||||
DISABLE_SENTRY_INSTRUMENTATION = True # see celery.py for more, we use this differently
|
||||
RAVEN_CONFIG = {
|
||||
'dsn': config.get('sentry', 'dsn'),
|
||||
'transport': 'raven.transport.threaded_requests.ThreadedRequestsHTTPTransport',
|
||||
'release': __version__,
|
||||
'environment': SITE_URL,
|
||||
}
|
||||
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
@@ -487,6 +475,17 @@ LOGGING = {
|
||||
},
|
||||
}
|
||||
|
||||
if config.has_option('sentry', 'dsn'):
|
||||
INSTALLED_APPS += [
|
||||
'pretix.sentry.App',
|
||||
]
|
||||
RAVEN_CONFIG = {
|
||||
'dsn': config.get('sentry', 'dsn'),
|
||||
'transport': 'raven.transport.threaded_requests.ThreadedRequestsHTTPTransport',
|
||||
'release': __version__,
|
||||
'environment': SITE_URL,
|
||||
}
|
||||
|
||||
CELERY_TASK_SERIALIZER = 'json'
|
||||
CELERY_RESULT_SERIALIZER = 'json'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user