Litestar
Learn about using Sentry with Litestar.
The Litestar integration adds support for the Litestar framework.
Install sentry-sdk
from PyPI with the litestar
extra:
pip install --upgrade 'sentry-sdk[litestar]' uvicorn
If you have the litestar
package in your dependencies, the Litestar integration will be enabled automatically when you initialize the Sentry SDK.
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
import sentry_sdk
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
)
from litestar import Litestar, get
sentry_sdk.init(...) # same as above
@get("/hello")
async def hello_world() -> str:
1 / 0
return "Hello!"
app = Litestar(route_handlers=[hello_world])
Save the file above as app.py
and start the development server with:
uvicorn app:app
When you point your browser to http://localhost:8000/hello a transaction will be created in the Performance section of sentry.io. Additionally, the ZeroDivisionError
we've snuck into our hello_world
handler 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.
Note
Litestar was renamed from Starlite with the release of version 2.0. We support different integrations for each one. This guide applies to Litestar. See Starlite integration for the guide that applies to Starlite.
- Litestar: 2.0.0+
- Python: 3.8+
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").