opentelemetry-instrumentation-asyncpg
OpenTelemetry instrumentation for AsyncPG
What it is and what it does
This package integrates asyncpg, an async PostgreSQL driver, with OpenTelemetry's distributed tracing framework. When installed and initialized, it automatically wraps asyncpg database calls to emit spans containing query details, execution time, and connection metadata. These spans flow into your OpenTelemetry collector pipeline, enabling centralized observability of database activity across microservices.
The instrumentation is designed to be lightweight and non-intrusive: it hooks into asyncpg at import time and requires only a single initialization call. It depends on three core OpenTelemetry packages (api, instrumentation, and semantic-conventions) and is currently in beta, meaning the API may evolve but the core functionality is stable enough for production use in applications that can tolerate minor version changes.
Use it for:
- Trace slow PostgreSQL queries in async Python services to identify bottlenecks.
- Correlate database queries with HTTP requests and other spans in a distributed system.
- Export asyncpg activity to observability platforms (Jaeger, Datadog, etc.) for centralized monitoring.
- Debug connection pool exhaustion and query timing issues in high-concurrency async applications.
- Build service dependency maps by analyzing which services query which databases.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds distributed tracing to PostgreSQL queries executed via the asyncpg library, capturing query details and timing as OpenTelemetry spans.
Yes, if you run asyncpg in a service that already uses OpenTelemetry or are building observability infrastructure. The low install friction, active maintenance, and zero known vulnerabilities make it safe to adopt. Beta status is not a blocker—it reflects the project's maturity model, not instability. Skip it if you have no observability pipeline or don't need query-level tracing.
Install
opentelemetry-instrumentation-asyncpg on PyPI
pip
pip install opentelemetry-instrumentation-asyncpguv
uv add opentelemetry-instrumentation-asyncpgpoetry
poetry add opentelemetry-instrumentation-asyncpgInstalling opentelemetry-instrumentation-asyncpg
Before you install
Low friction: pure Python wheel with three lightweight OpenTelemetry dependencies. Actively maintained with a recent release (29 days old) and steady commit activity. Beta status reflects ongoing development but no known stability issues.
License in practice
Apache-2.0 permissive license allows use in most commercial and open-source projects with minimal restrictions; attribution required.
Quickstart
pip install opentelemetry-instrumentation-asyncpg
from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor
AsyncPGInstrumentor().instrument()
Requires Python 3.10 or later; asyncpg must be installed separately for instrumentation to function.
Verify before relying
- Whether instrumentation works with all asyncpg versions or has specific version constraints.
- Performance overhead of tracing on high-volume query workloads.
- Compatibility with specific OpenTelemetry exporters and backends.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — opentelemetry-api, opentelemetry-instrumentation, opentelemetry-semantic-conventions |
| Maintenance | actively maintained — 29 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 9,877,194/month — #1,496 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: opentelemetry_instrumentation_asyncpg-0.65b0-py3-none-any.whl
Tags
More Monitoring packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
opentelemetry-semantic-conventionsProvides generated Python code for…
permissive · top 100 on PyPI
opentelemetry-sdkProvides the reference implementation of the…
permissive · top 100 on PyPI
opentelemetry-apiProvides the abstract API and interfaces for…
permissive · top 100 on PyPI
opentelemetry-exporter-otlp-proto-httpExports OpenTelemetry observability data to an…
permissive · top 1,000 on PyPI
opentelemetry-instrumentationProvides automatic instrumentation commands and…
permissive · top 1,000 on PyPI
asyncpgasyncpg is an asyncio-native PostgreSQL client…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-aiopgAdds distributed tracing instrumentation for…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-psycopg2Adds distributed tracing instrumentation to…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-mysqlAdds distributed tracing to MySQL database…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-psycopgAdds OpenTelemetry tracing instrumentation to…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-tortoiseormAdds distributed tracing to Tortoise ORM…
permissive · top 5,000 on PyPI
asyncpg-stubsProvides type stubs for asyncpg to enable…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-aiokafkaAdds distributed tracing instrumentation to…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-sqlalchemyAdds distributed tracing to SQLAlchemy database…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-asyncclickAdds OpenTelemetry tracing to asyncclick CLI…
permissive · top 15,000 on PyPI