diff --git a/dmutils/flask_init.py b/dmutils/flask_init.py index e9ee4927..2c132815 100644 --- a/dmutils/flask_init.py +++ b/dmutils/flask_init.py @@ -4,7 +4,7 @@ import jinja2 import flask_featureflags -from . import config, logging, force_https, request_id, formats, filters +from . import config, logging, force_https, request_id, formats, filters, rollbar_agent from flask import Markup, redirect, request, session, current_app, abort from flask.ext.script import Manager, Server from flask_login import current_user @@ -40,6 +40,7 @@ def init_app( ProxyFix(application) request_id.init_app(application) force_https.init_app(application) + rollbar_agent.init_app(application) flask_featureflags.FeatureFlag(application) diff --git a/dmutils/rollbar_agent.py b/dmutils/rollbar_agent.py new file mode 100644 index 00000000..e6b21f2c --- /dev/null +++ b/dmutils/rollbar_agent.py @@ -0,0 +1,20 @@ +import os +import rollbar +import rollbar.contrib.flask +from flask import got_request_exception + + +def init_app(app): + if app.config.get('ROLLBAR_TOKEN'): + rollbar.init( + # access token for the demo app: https://rollbar.com/demo + app.config['ROLLBAR_TOKEN'], + # environment name + app.config['DM_ENVIRONMENT'], + # server root directory, makes tracebacks prettier + root=os.path.dirname(os.path.realpath(__file__)), + # flask already sets up logging + allow_logging_basic_config=False) + + # send exceptions from `app` to rollbar, using flask's signal system. + got_request_exception.connect(rollbar.contrib.flask.report_exception, app) diff --git a/requirements_for_test.txt b/requirements_for_test.txt index b1d212d1..3e4ad515 100644 --- a/requirements_for_test.txt +++ b/requirements_for_test.txt @@ -10,3 +10,5 @@ cffi tox flake8 responses +blinker +rollbar \ No newline at end of file