opentelemetry-instrumentation-psycopg
OpenTelemetry psycopg instrumentation
What it is and what it does
This package integrates OpenTelemetry tracing into psycopg database connections, automatically instrumenting SQL queries to emit spans that capture execution details. It sits between your application and the psycopg driver, intercepting database operations and forwarding them to your configured OpenTelemetry exporters (e.g., Jaeger, Datadog, or any OTLP-compatible backend).
It is built on the OpenTelemetry instrumentation framework and depends on three core OpenTelemetry packages: opentelemetry-api, opentelemetry-instrumentation, and opentelemetry-instrumentation-dbapi. Once installed and initialized, it requires minimal code changes—typically a single call to PsycopgInstrumentor().instrument()—and then all psycopg queries become visible in your distributed tracing system. It is currently in Beta status and supports Python 3.10 through 3.14.
Use it for:
- Monitor slow database queries in production by capturing query spans and latency in your tracing backend.
- Debug application performance issues by correlating database operations with upstream HTTP requests in distributed traces.
- Audit database activity in compliance-sensitive applications by exporting query details to a centralized observability platform.
- Measure database connection pool utilization and query patterns across microservices.
- Integrate PostgreSQL query tracing into an existing OpenTelemetry observability stack.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds OpenTelemetry tracing instrumentation to psycopg database connections, automatically capturing SQL queries and performance metrics for observability.
Yes, if you are already using OpenTelemetry and need database observability for psycopg. The low install friction, active maintenance, permissive license, and zero known vulnerabilities make it a safe choice. The Beta status is acceptable for most observability use cases, though you should verify it covers your specific psycopg version and tracing requirements before deploying to production.
Install
opentelemetry-instrumentation-psycopg on PyPI
pip
pip install opentelemetry-instrumentation-psycopguv
uv add opentelemetry-instrumentation-psycopgpoetry
poetry add opentelemetry-instrumentation-psycopgInstalling opentelemetry-instrumentation-psycopg
Before you install
Low friction install with three lightweight OpenTelemetry runtime dependencies. Actively maintained with a recent release; last commit on 2026-08-14 and repository shows 1086 stars.
License in practice
Apache-2.0 permissive license allows use in most projects, including commercial ones, with minimal restrictions.
Quickstart
pip install opentelemetry-instrumentation-psycopg
from opentelemetry.instrumentation.psycopg import PsycopgInstrumentor
PsycopgInstrumentor().instrument()
Requires Python 3.10 or later; psycopg must already be installed in your environment.
Verify before relying
- Whether instrumentation works with both psycopg2 and psycopg3, or only one version.
- What specific span attributes and metrics are captured beyond basic query tracing.
- Whether there is performance overhead from instrumentation in high-throughput scenarios.
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-dbapi, opentelemetry-instrumentation |
| Maintenance | actively maintained — 29 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,710,065/month — #2,048 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: opentelemetry_instrumentation_psycopg-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
opentelemetry-instrumentation-psycopg2Adds distributed tracing instrumentation to…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-pymongoAdds automatic tracing and observability…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-pymssqlAdds automatic tracing and monitoring of…
permissive · top 15,000 on PyPI
opentelemetry-instrumentation-sqlite3Adds OpenTelemetry tracing instrumentation to…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-dbapiAdds automatic tracing and observability…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-pymysqlAdds OpenTelemetry tracing instrumentation to…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-asyncpgAdds distributed tracing to PostgreSQL queries…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-mysqlclientAdds OpenTelemetry tracing instrumentation to…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-system-metricsCollects system performance metrics (CPU,…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-aiopgAdds distributed tracing instrumentation for…
permissive · top 5,000 on PyPI