Skip to content

Instantly share code, notes, and snippets.

@mosquito
Created August 28, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosquito/9cfbcde98def12af5a4eb523c0eb7de1 to your computer and use it in GitHub Desktop.
Save mosquito/9cfbcde98def12af5a4eb523c0eb7de1 to your computer and use it in GitHub Desktop.
Sentry tornado async client
# encoding: utf-8
from tornado.gen import Return, coroutine
from tornado.ioloop import IOLoop
import tornado.web
from raven.contrib.tornado import SentryMixin
class SentryHandler(SentryMixin, tornado.web.RequestHandler):
@coroutine
def _execute(self, transforms, *args, **kwargs):
try:
result = yield super(SentryHandler, self)._execute(transforms, *args, **kwargs)
except Exception as e:
if not self.application.settings['debug']:
self.captureException(e)
raise e
else:
raise Return(result)
def _handle_request_exception(self, e):
if not self.application.settings['debug']:
IOLoop.current().add_callback(self.captureException, e)
return super(SentryHandler, self)._handle_request_exception(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment