Bottle
The Bottle integration adds support for the Bottle Web Framework. Currently it works well with the stable version of Bottle (0.12). However the integration with the development version (0.13) doesn't work properly.
Install sentry-sdk
from PyPI with the bottle
extra:
pip install --upgrade 'sentry-sdk[bottle]'
If you have the bottle
package in your dependencies, the Bottle integration will be enabled automatically when you initialize the Sentry SDK.
from bottle import Bottle
import sentry_sdk
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
enable_tracing=True
)
app = Bottle()
from bottle import Bottle, run
sentry_sdk.init(...) # same as above
app = Bottle()
@app.route('/')
def hello():
1/0
return "Hello World!"
run(app, host='localhost', port=8000)
When you point your browser to http://localhost:8000/ a transaction in the Performance section of sentry.io will be created. Additionally, an error event 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.
uWSGI and Sentry SDK
If you're using uWSGI, note that it doesn't support threads by default. This might lead to unexpected behavior when using the Sentry SDK, from features not working properly to uWSGI workers crashing.
To enable threading support in uWSGI, make sure you have both --enable-threads
and --py-call-uwsgi-fork-hooks
on.
The Sentry Python SDK will install the Bottle integration for all of your apps. The integration hooks into base Bottle class.
All exceptions leading to an Internal Server Error are reported.
Request data is attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set
send_default_pii
toTrue
.Each request has a separate scope. Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request being handled.
If you add BottleIntegration
explicitly to your sentry_sdk.init()
call you can set options for BottleIntegration
to change its behavior:
import sentry_sdk
from sentry_sdk.integrations.bottle import BottleIntegration
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
enable_tracing=True,
integrations=[
BottleIntegration(
transaction_style="endpoint",
),
],
)
You can pass the following keyword arguments to BottleIntegration()
:
transaction_style
:Copied@app.route("/myurl/<foo>") def myendpoint(): return "ok"
In the above code, you would set the transaction to:
/myurl/<foo>
if you settransaction_style="url"
.myendpoint
if you settransaction_style="endpoint"
The default is
"endpoint"
.
- Bottle: 0.12.13+
- Python: 2.7+
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").
- Package:
- pypi:sentry-sdk
- Version:
- 1.45.0
- Repository:
- https://github.com/getsentry/sentry-python
- API Documentation:
- https://getsentry.github.io/sentry-python/