Skip to content

Commit 535bcb2

Browse files
authored
feat(python): Document default span attrs in Tornado, update for 3.0 (#14366)
Document what span attributes will be attached to transactions by default by our builtin integrations. This PR updates Tornado. Rest will follow. I created a new 3.x page for this since it's new behavior in 3.0.
1 parent cac2dc2 commit 535bcb2

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Tornado
3+
description: "Learn about using Sentry with Tornado."
4+
---
5+
6+
The Tornado integration adds support for the [Tornado web framework](https://www.tornadoweb.org/).
7+
8+
## Install
9+
10+
Install `sentry-sdk` from PyPI with the `tornado` extra:
11+
12+
```bash {tabTitle:pip}
13+
pip install "sentry-sdk[tornado]"
14+
```
15+
```bash {tabTitle:uv}
16+
uv add "sentry-sdk[tornado]"
17+
```
18+
19+
## Configure
20+
21+
If you have the `tornado` package in your dependencies, the Tornado integration will be enabled automatically when you initialize the Sentry SDK.
22+
23+
<PlatformContent includePath="getting-started-config" />
24+
25+
## Verify
26+
27+
```python
28+
import asyncio
29+
import tornado
30+
31+
sentry_sdk.init(...) # same as above
32+
33+
class MainHandler(tornado.web.RequestHandler):
34+
def get(self):
35+
1 / 0 # raises an error
36+
self.write("Hello, world")
37+
38+
def make_app():
39+
return tornado.web.Application([
40+
(r"/", MainHandler),
41+
])
42+
43+
async def main():
44+
app = make_app()
45+
app.listen(8888)
46+
await asyncio.Event().wait()
47+
48+
asyncio.run(main())
49+
```
50+
51+
When you point your browser to [http://localhost:8888/](http://localhost:8888/) a transaction in the Performance section of [sentry.io](https://sentry.io) will be created. Additionally, an error event will be sent to [sentry.io](https://sentry.io) and will be connected to the transaction.
52+
53+
It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).
54+
55+
## Behavior
56+
57+
- The Tornado integration will be installed for all of your apps and handlers.
58+
- All exceptions leading to a Internal Server Error are reported.
59+
- 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`.
60+
- 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.
61+
- Logging with any logger will create breadcrumbs when the [Logging](/platforms/python/integrations/logging/) integration is enabled (done by default).
62+
63+
### Tracing
64+
65+
A set of predefined span attributes will be attached to Tornado transactions by default. These can also be used for sampling since they will also be accessible via the `sampling_context` dictionary in the [`traces_sampler`](/platforms/python/configuration/options/#traces_sampler).
66+
67+
- `url.path`
68+
- `url.query`
69+
- `url.scheme`
70+
- `url.full`
71+
- `http.request.method`
72+
- `http.request.header.{header}`
73+
- `server.address`
74+
- `server.port`
75+
- `network.protocol.name`
76+
- `network.protocol.version`
77+
78+
These attributes will also be sent to Sentry. If you don't want that, you can filter them out using a custom [`before_send`](/platforms/python/configuration/options/#before_send) function.
79+
80+
## Supported Versions
81+
82+
- Tornado: 6+
83+
- Python: 3.8+
84+
85+
<Include name="python-use-older-sdk-for-legacy-support.mdx" />

0 commit comments

Comments
 (0)