A RequestHandler mixin for sending exceptions to Sentry

class sprockets.mixins.sentry.SanitizeEmailsProcessor(client)

Remove all email addresses from the payload sent to sentry.

class sprockets.mixins.sentry.SentryMixin(*args, **kwargs)

Report unexpected exceptions to Sentry.

Mix this in over a tornado.web.RequestHandler to report unhandled exceptions to Sentry so that you can figure out what went wrong. In order to use this mix-in, all that you have to do is define the SENTRY_DSN environment variable that contains your projects Sentry DSN. Whenever a request comes it and the environment variable is set, this mix-in will create a new raven.base.Client instance and make it available via the sentry_client property.

If an exception is caught by _handle_request_exception(), then it will be reported to Sentry in all it’s glory.


The raven.base.Client instance or None if sentry reporting is disabled. You can modify attributes of the client as required for your application – for example, you can add new modules by adding to self.sentry_client.include_paths.


A dict of extra information to pass to sentry when an exception is reported.


A dict of tag and value pairs to associated with any reported exceptions.


Retrieve the sentry client for application.

Parameters:application (tornado.web.Application) – application to retrieve the sentry client for.
Returns:a raven.base.Client instance or None
Return type:raven.base.Client
sprockets.mixins.sentry.install(application, **kwargs)

Call this to install a sentry client into a Tornado application.


True if the client was installed by this call and False otherwise.

This function should be called to initialize the Sentry client for your application. It will be called automatically with the default parameters by SentryMixin if you do not call it during the creation of your application. You should install the client explicitly so that you can set at least the following properties:

  • include_paths list of python modules to include in tracebacks. This function ensures that raven, sprockets, sys, and tornado are included but you probably want to include additional packages.
  • release the version of the application that is running

See the raven documentation for additional information.


The following application will report errors to sentry if you export the SENTRY_DSN environment variable and make a request to http://localhost:8000/whatever provided that whatever is not an integer.

import sys
import signal

from tornado import ioloop, web

from sprockets.mixins import sentry

class Handler(sentry.SentryMixin, web.RequestHandler):

    def initialize(self, **kwargs):
        tags = kwargs.pop('tags', dict())

    def get(self, status_code):

def make_application(app_tags):
    application = web.Application([(r'/(\S+)', Handler)])
    sentry.install(application, include_paths=[__name__], tags=app_tags)
    return application

def stop(signo, frame):
    iol = ioloop.IOLoop.current()

if __name__ == '__main__':
    app_tags = {}
    for arg in sys.argv[1:]:
        name, _, value = arg.partition('=')
        app_tags[name] = value

    signal.signal(signal.SIGINT, stop)
    app = make_application(app_tags)