sprockets.mixins.sentry¶
A RequestHandler mixin for sending exceptions to Sentry
Installation¶
sprockets.mixins.sentry is available on the
Python Package Index
and can be installed via pip or easy_install:
pip install sprockets.mixins.sentry
API Documentation¶
mixins.sentry
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.RequestHandlerto 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 newraven.base.Clientinstance and make it available via thesentry_clientproperty.If an exception is caught by
_handle_request_exception(), then it will be reported to Sentry in all it’s glory.-
sentry_client¶ The
raven.base.Clientinstance orNoneif 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 toself.sentry_client.include_paths.
A
dictof tag and value pairs to associated with any reported exceptions.
-
-
sprockets.mixins.sentry.get_client(application)¶ Retrieve the sentry client for application.
Parameters: application (tornado.web.Application) – application to retrieve the sentry client for. Returns: a raven.base.Clientinstance orNoneReturn type: raven.base.Client
-
sprockets.mixins.sentry.install(application, **kwargs)¶ Call this to install a sentry client into a Tornado application.
Parameters: - application (tornado.web.Application) – the application to install the client into.
- kwargs – keyword parameters to pass to the
raven.base.Clientinitializer.
Returns: Trueif the client was installed by this call andFalseotherwise.This function should be called to initialize the Sentry client for your application. It will be called automatically with the default parameters by
SentryMixinif 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, andtornadoare 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.
Examples¶
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())
super(Handler, self).initialize(**kwargs)
self.sentry_tags.update(tags)
def get(self, status_code):
self.set_status(int(status_code))
def make_application(app_tags):
application = web.Application([web.url(r'/(\S+)', Handler)])
sentry.install(application, include_paths=[__name__], tags=app_tags)
return application
def stop(signo, frame):
iol = ioloop.IOLoop.current()
iol.add_callback_from_signal(iol.stop)
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)
app.listen(8000)
ioloop.IOLoop.current().start()
Version History¶
- 1.2.0
- Extend raven pin so that we can use python 3.7
- Advertise python 3.7 support
- Drop python 3.4 from support matrix
- Remove unused import of urllib.parse
- 1.1.2
- Add email sanitization processor
- 1.1.1
- Fix password scrubbing in URLs.
- Remove support for python 2.6, 3.2, and 3.3
- 1.1.0
- Move raven client initialization into
sprockets.mixins.sentry.install - Add support for setting raven.Client options when calling
installon the application. - The sentry “environment” is set to the
$ENVIRONMENTenvironment variable if it is set.
- Move raven client initialization into
- 1.0.0
- Work around getsentry/raven-python#735
- 0.4.0 (16-Dec-2015)
- Ignore web.Finish exceptions
- 0.3.0 (13-Jul-2015)
- Add
sprockets.mixins.sentry.SentryMixin.sentry_extra - Add
sprockets.mixins.sentry.SentryMixin.sentry_tags - Improve module reporting in Sentry messages
- Improved documentation
- Add
- 0.2.0 (22-Jun-2015)
- Stop reporting
tornado.web.HTTPError
- Stop reporting
- 0.1.0 (13-May-2015)
- Initial public release
Issues¶
Please report any issues to the Github project at https://github.com/sprockets/sprockets.mixins.sentry/issues
Source¶
sprockets.mixins.sentry source is available on Github at https://github.com/sprockets/sprockets.mixins.sentry
License¶
sprockets.mixins.sentry is released under the 3-Clause BSD license.