Skip to content

Commit

Permalink
Merge pull request #33 from etalab/sentry
Browse files Browse the repository at this point in the history
Make sentry a core feature but optionnal
  • Loading branch information
noirbizarre committed Jun 1, 2015
2 parents 668989f + 0ff359d commit 16655eb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def dependency_links(filename):
tests_require=tests_require,
extras_require={
'test': tests_require,
'sentry': ['raven[flask]>=5.3.0'],
},
entry_points={
'console_scripts': [
Expand Down
3 changes: 2 additions & 1 deletion udata/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def init_logging(app):

def register_extensions(app):
from udata import (
models, routing, tasks, mail, i18n, auth, theme, search, sitemap
models, routing, tasks, mail, i18n, auth, theme, search, sitemap, sentry
)
i18n.init_app(app)
models.init_app(app)
Expand All @@ -171,4 +171,5 @@ def register_extensions(app):
mail.init_app(app)
search.init_app(app)
sitemap.init_app(app)
sentry.init_app(app)
return app
37 changes: 37 additions & 0 deletions udata/sentry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

from werkzeug.exceptions import HTTPException

log = logging.getLogger(__name__)


def init_app(app):
if 'SENTRY_DSN' in app.config:
try:
from raven.contrib.flask import Sentry
except:
log.error('raven[flask] is required to use sentry')
return

sentry = Sentry()

app.config.setdefault('SENTRY_USER_ATTRS', ['slug', 'email', 'fullname'])
app.config.setdefault('SENTRY_LOGGING', 'WARNING')

log_level_name = app.config.get('SENTRY_LOGGING')
if log_level_name:
log_level = getattr(logging, log_level_name.upper())
if log_level:
sentry.logging = True
sentry.level = log_level

# Do not send HTTPExceptions
exceptions = app.config.get('RAVEN_IGNORE_EXCEPTIONS', [])
if HTTPException not in exceptions:
exceptions.append(HTTPException)
app.config['RAVEN_IGNORE_EXCEPTIONS'] = exceptions

sentry.init_app(app)
3 changes: 3 additions & 0 deletions udata/templates/errors/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

{% block details %}
<p class="lead">{{ _("The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.") }}</p>
{% if g.sentry_event_id %}
<p>{{ _('The error identifier is {id}').format(id=g.sentry_event_id) }}</p>
{% endif %}
{% endblock %}

0 comments on commit 16655eb

Please sign in to comment.