You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/platforms/python/guides/starlette/index.mdx
+35-28Lines changed: 35 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,6 @@ description: "Learn about using Sentry with Starlette."
8
8
9
9
The Starlette integration adds support for the [Starlette Framework](https://www.starlette.io/).
10
10
11
-
The Sentry SDK automatically enables support for Starlette if you have the `starlette` Python package installed in your project. There are no configuration options you need to add when initializing the Sentry SDK, as everything works out of the box.
12
-
13
11
## Install
14
12
15
13
Install `sentry-sdk` from PyPI with the `starlette` extra:
To configure the SDK, initialize it with the integration before your app has been initialized:
21
+
If you have the `starlette` package in your dependencies, the Starlette integration will be enabled automatically when you initialize the Sentry SDK.
24
22
25
23
<SignInNote />
26
24
27
25
```python
28
26
from starlette.applications import Starlette
29
-
30
27
import sentry_sdk
31
28
32
-
33
29
sentry_sdk.init(
34
-
dsn="___PUBLIC_DSN___",
35
-
36
30
# Set traces_sample_rate to 1.0 to capture 100%
37
31
# of transactions for performance monitoring.
38
-
# We recommend adjusting this value in production,
39
32
traces_sample_rate=1.0,
33
+
dsn="___PUBLIC_DSN___",
40
34
)
41
35
42
36
app = Starlette(routes=[...])
43
37
```
44
38
45
39
## Verify
46
40
47
-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
48
-
49
41
```python
50
42
from starlette.applications import Starlette
51
43
from starlette.routing import Route
52
44
45
+
sentry_sdk.init(...) # same as above
53
46
54
47
asyncdeftrigger_error(request):
55
48
division_by_zero =1/0
@@ -59,7 +52,9 @@ app = Starlette(routes=[
59
52
])
60
53
```
61
54
62
-
Visiting `"/sentry-debug"` will trigger an error that will be captured by Sentry.
55
+
When you point your browser to [http://localhost:8000/sentry-debug](http://localhost:8000/sentry-debug) a transaction will be created in the Performance section of [sentry.io](https://sentry.io). Additionally, an error event will be sent to [sentry.io](https://sentry.io) and will be connected to the transaction.
56
+
57
+
It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).
63
58
64
59
## Behavior
65
60
@@ -71,33 +66,45 @@ Visiting `"/sentry-debug"` will trigger an error that will be captured by Sentry
71
66
72
67
## Options
73
68
74
-
If you want to change the default behavior of the Starlette integration, you need to instantiate the integration by hand and pass it to Sentry's `init` function.
75
-
76
-
You can pass the keyword argument `transaction_style` to `StarletteIntegration()`.
77
-
78
-
With this option, you can influence how the transactions are named in Sentry. For example:
69
+
By adding `StarletteIntegration` explicitly to your `sentry_sdk.init()` call you can set options for `StarletteIntegration` to change its behavior:
79
70
80
71
```python
81
72
from sentry_sdk.integrations.starlette import StarletteIntegration
0 commit comments