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
To configure the Sentry SDK, initialize it before your app has been initialized:
21
+
If you have the `fastapi` package in your dependencies, the FastAPI integration will be enabled automatically when you initialize the Sentry SDK.
22
22
23
23
<SignInNote />
24
24
25
25
```python
26
26
from fastapi import FastAPI
27
-
28
27
import sentry_sdk
29
28
30
-
31
29
sentry_sdk.init(
32
30
dsn="___PUBLIC_DSN___",
33
-
34
31
# Set traces_sample_rate to 1.0 to capture 100%
35
32
# of transactions for performance monitoring.
36
-
# We recommend adjusting this value in production,
37
33
traces_sample_rate=1.0,
38
34
)
39
35
@@ -42,21 +38,21 @@ app = FastAPI()
42
38
43
39
## Verify
44
40
45
-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
46
-
47
41
```python
48
42
from fastapi import FastAPI
49
43
44
+
sentry_sdk.init(...) # same as above
50
45
51
46
app = FastAPI()
52
47
53
48
@app.get("/sentry-debug")
54
49
asyncdeftrigger_error():
55
50
division_by_zero =1/0
56
-
57
51
```
58
52
59
-
Visiting `"/sentry-debug"` will trigger an error that will be captured by Sentry.
53
+
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.
54
+
55
+
It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).
60
56
61
57
## Behaviour
62
58
@@ -88,43 +84,59 @@ The parameter `traces_sample_rate` needs to be set when initializing the Sentry
88
84
89
85
</Note>
90
86
91
-
## Integration Options
92
-
93
-
If you want to change the default behavior of the FastAPI integration, you need to instantiate the integration manually and then pass it to Sentry's `init` function. Because FastAPI is based on the Starlette framework, both integrations, `StarletteIntegration` and `FastApiIntegration`, must be instantiated.
94
-
95
-
<ConfigKeyname="transaction_style">
87
+
## Options
96
88
97
-
You can pass the keyword argument `transaction_style` to `StarletteIntegration()` and `FastApiIntegration()`.
98
-
99
-
With this option, you can influence how the transactions are named in Sentry. For example:
89
+
By adding `FastApiIntegration` to your `sentry_sdk.init()` call explicitly, you can set options for `FastApiIntegration` to change its behavior.
90
+
Because FastAPI is based on the Starlette framework, both integrations, `StarletteIntegration` and `FastApiIntegration`, must be instantiated.
100
91
101
92
```python
102
93
from sentry_sdk.integrations.starlette import StarletteIntegration
103
94
from sentry_sdk.integrations.fastapi import FastApiIntegration
0 commit comments