raven-python icon indicating copy to clipboard operation
raven-python copied to clipboard

Integration with cherrypy

Open caulagi opened this issue 7 years ago • 2 comments

I wonder if there is any interest to add the following snippet which allows a cherrypy application to send exceptions to sentry

import cherrypy
import raven


def register_sentry():
    cherrypy.tools.report_to_sentry = cherrypy.Tool('before_error_response', report_to_sentry)
    cherrypy.config.update({
        'tools.report_to_sentry.on': True
    })


def report_to_sentry():
    sentry_dsn = settings.sentry_dsn
    if not sentry_dsn:
        return

    client = raven.Client(dsn=sentry_dsn)
    client.http_context({
        'method': cherrypy.request.method,
        'url': '{}/{}'.format(cherrypy.request.base, cherrypy.request.path_info),
        'method': cherrypy.request.method,
        'data': dict(cherrypy.request.body),
        'query_string': cherrypy.request.query_string,
        'headers': dict(cherrypy.request.headers),
    })
    client.captureException()

The register_sentry method should be called before the application starts, of course.

caulagi avatar Mar 12 '18 19:03 caulagi

We can add it to the docs, though theres quite a heavy cost to add more 'frameworks' to the core integration. They quickly end up out of date, not tested well, etc. Docs at least are more of the "heres a rough idea of how to do it yourself".

dcramer avatar Mar 12 '18 19:03 dcramer

Yes, of course. I should have been clearer. I meant adding to the docs as an example.

caulagi avatar Mar 12 '18 19:03 caulagi