Skip to content

Commit 446588e

Browse files
antonpirkergetsantry[bot]shanamatthews
authored
Getting Started: starlette (#7835)
* Getting Started: starlette * fix * style(lint): Auto commit lint changes * style(lint): Auto commit lint changes * Apply suggestions from code review Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com> --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com>
1 parent bf21e6f commit 446588e

File tree

1 file changed

+35
-28
lines changed
  • src/platforms/python/guides/starlette

1 file changed

+35
-28
lines changed

src/platforms/python/guides/starlette/index.mdx

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ description: "Learn about using Sentry with Starlette."
88

99
The Starlette integration adds support for the [Starlette Framework](https://www.starlette.io/).
1010

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-
1311
## Install
1412

1513
Install `sentry-sdk` from PyPI with the `starlette` extra:
@@ -20,36 +18,31 @@ pip install --upgrade 'sentry-sdk[starlette]'
2018

2119
## Configure
2220

23-
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.
2422

2523
<SignInNote />
2624

2725
```python
2826
from starlette.applications import Starlette
29-
3027
import sentry_sdk
3128

32-
3329
sentry_sdk.init(
34-
dsn="___PUBLIC_DSN___",
35-
3630
# Set traces_sample_rate to 1.0 to capture 100%
3731
# of transactions for performance monitoring.
38-
# We recommend adjusting this value in production,
3932
traces_sample_rate=1.0,
33+
dsn="___PUBLIC_DSN___",
4034
)
4135

4236
app = Starlette(routes=[...])
4337
```
4438

4539
## Verify
4640

47-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
48-
4941
```python
5042
from starlette.applications import Starlette
5143
from starlette.routing import Route
5244

45+
sentry_sdk.init(...) # same as above
5346

5447
async def trigger_error(request):
5548
division_by_zero = 1 / 0
@@ -59,7 +52,9 @@ app = Starlette(routes=[
5952
])
6053
```
6154

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).
6358

6459
## Behavior
6560

@@ -71,33 +66,45 @@ Visiting `"/sentry-debug"` will trigger an error that will be captured by Sentry
7166

7267
## Options
7368

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:
7970

8071
```python
8172
from sentry_sdk.integrations.starlette import StarletteIntegration
8273

8374
sentry_sdk.init(
84-
# ...
75+
dsn="___PUBLIC_DSN___",
76+
# Set traces_sample_rate to 1.0 to capture 100%
77+
# of transactions for performance monitoring.
78+
traces_sample_rate=1.0,
8579
integrations=[
86-
StarletteIntegration(transaction_style="endpoint"),
80+
StarletteIntegration(
81+
transaction_style="endpoint",
82+
)
8783
],
8884
)
85+
```
8986

90-
async def product_detail(request):
91-
return JSONResponse({...})
87+
You can pass the following keyword arguments to `StarletteIntegration()`:
9288

93-
app = Starlette(routes=[
94-
Route('/catalog/product/{product_id}', product_detail),
95-
])
96-
```
89+
- `transaction_style`:
90+
91+
```
92+
async def product_detail(request):
93+
return JSONResponse({...})
94+
95+
app = Starlette(routes=[
96+
Route('/catalog/product/{product_id}', product_detail),
97+
])
98+
```
99+
100+
In the above code, the transaction name will be:
101+
102+
- `"/catalog/product/{product_id}"` if you set `transaction_style="url"`.
103+
- `"product_detail"` if you set `transaction_style="endpoint"`
97104

98-
In the above code, the transaction name will be:
105+
The default is `"url"`.
99106

100-
- `"/catalog/product/{product_id}"` if you set `transaction_style="url"`.
101-
- `"product_detail"` if you set `transaction_style="endpoint"`
107+
## Supported Versions
102108

103-
The default is `"url"`.
109+
- Starlette: 0.19.1+
110+
- Python: 3.7+

0 commit comments

Comments
 (0)