The Tornado integration adds support for the Tornado Web Framework.
sentry-sdk from PyPI with the
pip install --upgrade sentry-sdk[tornado]
If you're on Python 3.6, you also need the
pip install --upgrade aiocontextvars
If you have the
tornado package in your dependencies, the Tornado integration will be enabled automatically when you initialize the Sentry SDK.
import sentry_sdk sentry_sdk.init( dsn="https://examplePublicKey@o0.ingest.sentry.io/0", # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. traces_sample_rate=1.0, ) class MainHandler(tornado.web.RequestHandler): # ...
import asyncio import tornado sentry_sdk.init(...) # same as above class MainHandler(tornado.web.RequestHandler): def get(self): 1/0 # raises an error self.write("Hello, world") def make_app(): return tornado.web.Application([ (r"/", MainHandler), ]) async def main(): app = make_app() app.listen(8888) await asyncio.Event().wait() asyncio.run(main())
When you point your browser to http://localhost:8888/ a transaction in the Performance section of sentry.io will be created. Additionally, an error event will be sent to sentry.io and will be connected to the transaction.
It takes a couple of moments for the data to appear in sentry.io.
The Tornado integration will be installed for all of your apps and handlers.
All exceptions leading to a Internal Server Error are reported.
Request data is attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set
Each request has a separate scope. Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request being handled.
Logging with any logger will create breadcrumbs when the Logging integration is enabled (done by default).
- Tornado: 5+
- Python: 2.7+