{ "html": "
If you haven’t already, start by downloading Raven. The easiest way is\nwith pip:
\npip install raven --upgrade\n
The first thing you’ll need to do is to initialize sentry client under\nyour application
\nimport tornado.web\nfrom raven.contrib.tornado import AsyncSentryClient\n\nclass MainHandler(tornado.web.RequestHandler):\n def get(self):\n self.write("Hello, world")\n\napplication = tornado.web.Application([\n (r"/", MainHandler),\n])\napplication.sentry_client = AsyncSentryClient(\n '___DSN___'\n)\n
Once the sentry client is attached to the application, request handlers\ncan automatically capture uncaught exceptions by inheriting the SentryMixin class.
\nimport tornado.web\nfrom raven.contrib.tornado import SentryMixin\n\nclass UncaughtExceptionExampleHandler(\n SentryMixin, tornado.web.RequestHandler):\n def get(self):\n 1/0\n
You can also send events manually using the shortcuts defined in SentryMixin.\nThe shortcuts can be used for both asynchronous and synchronous usage.
\nimport tornado.web\nimport tornado.gen\nfrom raven.contrib.tornado import SentryMixin\n\nclass AsyncMessageHandler(SentryMixin, tornado.web.RequestHandler):\n @tornado.web.asynchronous\n @tornado.gen.engine\n def get(self):\n self.write("You requested the main page")\n yield tornado.gen.Task(\n self.captureMessage, "Request for main page served"\n )\n self.finish()\n\nclass AsyncExceptionHandler(SentryMixin, tornado.web.RequestHandler):\n @tornado.web.asynchronous\n @tornado.gen.engine\n def get(self):\n try:\n raise ValueError()\n except Exception as e:\n response = yield tornado.gen.Task(\n self.captureException, exc_info=True\n )\n self.finish()\n
Tip
\nThe value returned by the yield is a HTTPResponse
object.
To dynamically use Python if configuration DSN available, change your base handler on fly and make sure all concrete handlers are imported after this.
\n\n\n\n\nfrom raven.contrib.tornado import SentryMixin\napp.sentry_client = AsyncSentryClient(dsn)\nBaseHandler.__bases__ = (SentryMixin, ) + BaseHandler.__bases__\n
import tornado.web\nfrom raven.contrib.tornado import SentryMixin\n\nclass AsyncExampleHandler(SentryMixin, tornado.web.RequestHandler):\n def get(self):\n self.write("You requested the main page")\n self.captureMessage("Request for main page served")\n