Connect Litestar to Bugsink
When a Litestar request fails, Bugsink shows you the exception, the application frame that raised it, and the HTTP request that reached the handler.
This guide covers the initial setup and Litestar’s automatic capture of unhandled ASGI handler exceptions. You’ll connect an existing application, then make one request fail to confirm that it reaches Bugsink.
To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the SDK
Install the open-source Sentry SDK with its Litestar integration in the environment your application uses. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project.
python -m pip install --upgrade "sentry-sdk[litestar]" uvicornpython -m pip install --upgrade "sentry-sdk[litestar]" uvicorn
Configure Litestar
Import the SDK and Litestar integration where you create the application:
import sentry_sdk from litestar import Litestar, get from sentry_sdk.integrations.litestar import LitestarIntegrationimport sentry_sdk from litestar import Litestar, get from sentry_sdk.integrations.litestar import LitestarIntegration
Initialize the SDK before creating the Litestar application. Reading the DSN
from the environment keeps it out of source control:
sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[LitestarIntegration()], )sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[LitestarIntegration()], )
Set SENTRY_DSN in the environment where the application runs:
export SENTRY_DSN=https://key@bugsink.example/1export SENTRY_DSN=https://key@bugsink.example/1
Trigger an unhandled exception
If a Litestar handler raises an exception and does not catch it, the integration reports it automatically. There is no SDK call inside the handler. To verify the setup, this checkout handler raises an exception for an unknown product:
@get("/checkout/{sku:str}") async def checkout(sku: str) -> dict[str, str]: try: product = inventory[sku] except KeyError: raise ProductNotFound(f"Product {sku} is not in inventory") from None return {"reserved": product["name"]}@get("/checkout/{sku:str}") async def checkout(sku: str) -> dict[str, str]: try: product = inventory[sku] except KeyError: raise ProductNotFound(f"Product {sku} is not in inventory") from None return {"reserved": product["name"]}
Start the ASGI application with Uvicorn, then request a product that does not exist:
uvicorn app:app :::bash curl http://127.0.0.1:8000/checkout/litestar-missinguvicorn app:app :::bash curl http://127.0.0.1:8000/checkout/litestar-missing
Litestar returns an HTTP 500 response and the integration reports the exception.
See the error in Bugsink
Open your Bugsink project and select the new ProductNotFound issue. Its event
points to the failing line in the handler and includes the GET request.
ProductNotFound
That’s it: unhandled Litestar handler exceptions will now be reported to Bugsink.
The integration runs around Litestar’s request handling, so your handlers stay ordinary application code. An unhandled exception includes its Python stack, the application source frame, and the HTTP request that reached the handler.
If your application catches an exception itself, report it explicitly with
capture_exception().
