asyncpg

The AsyncPGIntegration captures queries from asyncpg, which can be viewed in Sentry's Performance page.

To get started, install sentry-sdk from PyPI.

Copied
pip install --upgrade sentry-sdk[asyncpg]

Add AsyncPGIntegration() to your integrations list, and enable tracing:

Copied
import sentry_sdk
from sentry_sdk.integrations.asyncpg import AsyncPGIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    enable_tracing=True,
    integrations=[
        AsyncPGIntegration(),
    ],
)

Copied
import asyncpg

async def main():
    sentry_sdk.init(...)  # same as above

    with sentry_sdk.start_transaction(name="testing_sentry"):
        conn = await asyncpg.connect(DATABASE_URL)
        await conn.fetch("SELECT * FROM pg_catalog.pg_tables;")
        await conn.close()

asyncio.run(main())

This will create a transaction called testing_sentry in the Performance section of sentry.io, and create spans for the connect and the SELECT operations.

It takes a couple of moments for the data to appear in sentry.io.

  • asyncpg: 0.23+
  • Python: 3.7+
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").