skillfed

opentelemetry-instrumentation-psycopg

OpenTelemetry psycopg instrumentation

opentelemetry-instrumentation-psycopg v0.65b0 5.7M downloads/30d#2,048 on PyPI1,086
Permissive license Apache-2.0 Active released

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-psycopg

uv

uv add opentelemetry-instrumentation-psycopg

poetry

poetry add opentelemetry-instrumentation-psycopg

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

psycopg tracing instrumentationopentelemetry database monitoringsql query observabilitypsycopg performance metricsdistributed tracing postgresqldatabase instrumentation opentelemetry
observabilitydistributed-tracingpostgresql

More Monitoring packages

tqdm

Wraps any iterable to display a real-time…

copyleft · top 100 on PyPI

opentelemetry-semantic-conventions

Provides generated Python code for…

permissive · top 100 on PyPI

opentelemetry-sdk

Provides the reference implementation of the…

permissive · top 100 on PyPI

opentelemetry-api

Provides the abstract API and interfaces for…

permissive · top 100 on PyPI

opentelemetry-exporter-otlp-proto-http

Exports OpenTelemetry observability data to an…

permissive · top 1,000 on PyPI

opentelemetry-instrumentation

Provides automatic instrumentation commands and…

permissive · top 1,000 on PyPI

opentelemetry-instrumentation-psycopg2

Adds distributed tracing instrumentation to…

permissive · top 1,000 on PyPI

opentelemetry-instrumentation-pymongo

Adds automatic tracing and observability…

permissive · top 5,000 on PyPI

opentelemetry-instrumentation-pymssql

Adds automatic tracing and monitoring of…

permissive · top 15,000 on PyPI

opentelemetry-instrumentation-sqlite3

Adds OpenTelemetry tracing instrumentation to…

permissive · top 5,000 on PyPI

opentelemetry-instrumentation-dbapi

Adds automatic tracing and observability…

permissive · top 1,000 on PyPI

opentelemetry-instrumentation-pymysql

Adds OpenTelemetry tracing instrumentation to…

permissive · top 5,000 on PyPI

opentelemetry-instrumentation-asyncpg

Adds distributed tracing to PostgreSQL queries…

permissive · top 5,000 on PyPI

opentelemetry-instrumentation-mysqlclient

Adds OpenTelemetry tracing instrumentation to…

permissive · top 5,000 on PyPI

opentelemetry-instrumentation-system-metrics

Collects system performance metrics (CPU,…

permissive · top 5,000 on PyPI

opentelemetry-instrumentation-aiopg

Adds distributed tracing instrumentation for…

permissive · top 5,000 on PyPI