Tornado

The Tornado integration adds support for the Tornado Web Framework.

Install sentry-sdk from PyPI with the tornado extra:

Copied
pip install --upgrade sentry-sdk[tornado]

If you're on Python 3.6, you also need the aiocontextvars package:

Copied
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.

Copied
import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    enable_tracing=True,
)

class MainHandler(tornado.web.RequestHandler):
    # ...

Copied
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 send_default_pii to True.

  • 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: 6+
  • Python: 3.8+
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").