SQLAlchemy
The SQLAlchemy integration captures queries from SQLAlchemy as breadcrumbs and spans.
Install sentry-sdk
from PyPI with the sqlalchemy
extra.
Copied
pip install --upgrade 'sentry-sdk[sqlalchemy]'
Copied
import sentry_sdk
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
enable_tracing=True,
)
The SQLAlchemy integration is enabled automatically if you have the sqlalchemy
package installed.
Copied
from sqlalchemy import create_engine
from sqlalchemy.sql import text
def main():
sentry_sdk.init(...) # same as above
engine = create_engine(DATABASE_URL, echo=True)
statement = text("SELECT 'Hello World'")
with engine.connect() as conn:
with sentry_sdk.start_transaction(name="testing_sentry"):
result = conn.execute(statement)
main()
This will create a transaction called testing_sentry
in the Performance section of sentry.io and will create a span for the SELECT
statement.
It takes a couple of moments for the data to appear in sentry.io.
- SQLAlchemy: 1.2+
- Python: 2.7+ (SQLAlchemy 1.2, 1.3, and 1.4), 3.7+ (SQLAlchemy 2.0+)
Help improve this content
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").
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/