Connect Bottle to Bugsink
When a Bottle request fails, Bugsink shows you the exception, the application frame that raised it, and the HTTP request that reached the route.
This guide covers the initial setup and Bottle’s automatic capture of unhandled route 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 Bottle support 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[bottle]"python -m pip install --upgrade "sentry-sdk[bottle]"
Configure Bottle
Import the SDK and Bottle integration where you create the application:
import os import sentry_sdk from bottle import Bottle, response, run from sentry_sdk.integrations.bottle import BottleIntegrationimport os import sentry_sdk from bottle import Bottle, response, run from sentry_sdk.integrations.bottle import BottleIntegration
Initialize the SDK before creating the Bottle application. Reading the DSN
from the environment keeps it out of source control:
sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[BottleIntegration()], )sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[BottleIntegration()], )
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 Bottle route raises an exception and does not catch it, the integration reports it automatically. There is no SDK call inside the route. To verify the setup, this checkout route raises an exception when a product is missing:
@app.get("/checkout/<sku>") def checkout(sku): try: product = inventory[sku] except KeyError: raise ProductNotFound(f"Product {sku} is not in inventory") from None response.content_type = "application/json" return {"reserved": product["name"]}@app.get("/checkout/<sku>") def checkout(sku): try: product = inventory[sku] except KeyError: raise ProductNotFound(f"Product {sku} is not in inventory") from None response.content_type = "application/json" return {"reserved": product["name"]}
Start the application as usual, then request a product that does not exist through that URL:
python app.py :::bash curl http://127.0.0.1:8080/checkout/bottle-missingpython app.py :::bash curl http://127.0.0.1:8080/checkout/bottle-missing
Bottle 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 route and includes the GET request.
ProductNotFound
That’s it: unhandled Bottle route exceptions will now be reported to Bugsink.
The integration runs around Bottle’s request handling, so your routes stay ordinary application code. An unhandled exception includes its Python stack, the application source frame, and the HTTP request that reached the route.
If your application catches an exception itself, report it explicitly with
capture_exception().
