From 78ff2b6eb46d2d1ca6fd46a9a0dd81ba200d8cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 3 Sep 2013 17:50:34 +0200 Subject: [PATCH] make it possible to send crashes to sentry (#3527) --- wcs/qommon/publisher.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py index ed7cc4b..18ba8ec 100644 --- a/wcs/qommon/publisher.py +++ b/wcs/qommon/publisher.py @@ -46,6 +46,11 @@ except ImportError: except ImportError: ET = None +try: + import raven +except ImportError: + raven = None + from quixote.publish import Publisher, get_request, get_response, get_publisher, redirect from http_request import HTTPRequest from http_response import HTTPResponse, AfterJob @@ -235,6 +240,9 @@ class QommonPublisher(Publisher): exc_type, exc_value, tb) + self.notify_sentry(exc_tuple, request=self.get_request(), + context=context) + try: self.logger.log_internal_error(error_summary, plain_error_msg) except socket.error: @@ -245,6 +253,21 @@ class QommonPublisher(Publisher): # this could happen on file descriptor exhaustion pass + def notify_sentry(self, exc_tuple, request=None, context=None): + if not self.get_site_option('sentry-dsn'): + return + + client = raven.Client(self.get_site_option('sentry-dsn')) + extra = {} + tags = {} + if context: + extra['context'] = context + if request: + extra['request'] = request.dump() + tags['url'] = request.get_url() + + client.captureException(exc_tuple, extra=extra, tags=tags) + def finish_successful_request(self): Publisher.finish_successful_request(self) self.statsd.increment('successful-request') @@ -260,6 +283,8 @@ class QommonPublisher(Publisher): (exc_type, exc_value, tb) = sys.exc_info() + self.notify_sentry((exc_type, exc_value, tb), request) + if exc_type is NotImplementedError: get_response().set_header('Content-Type', 'text/html') # set back content-type return template.error_page( -- 1.8.4.rc3