OpenTelemetry instrumentation for postgres.js (the PostgreSQL client for Node.js). Version 1.0.0 provides tracing and metrics (spans, histograms, counts) for database queries, connections, and performance insights. It captures query duration, SQL operation type, table names, parameter counts, and slow query detection. Configurable histogram buckets, parameter sanitization, and lifecycle hooks. Ships TypeScript types. Peer dependency on @opentelemetry/api ^1.9.0. Requires an OpenTelemetry SDK to be set up separately.
npm install otel-instrumentation-postgresNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up OpenTelemetry SDK with ConsoleSpanExporter and ConsoleMetricExporter, instruments postgres.js client using PostgresInstrumentation and createOTELEmitter, then runs a query.
Ensure you have set up an OpenTelemetry SDK and called sdk.start() before instrumenting your postgres client.
Set DATABASE_URL or provide serverAddress, serverPort, databaseName in configuration.
Use 'pg' with @opentelemetry/instrumentation-pg or a dedicated pg instrumentation.
Run 'npm install otel-instrumentation-postgres' and ensure the import matches exactly.
Use import { createOTELEmitter } from 'otel-instrumentation-postgres';Use ESM import syntax (import { PostgresInstrumentation } from 'otel-instrumentation-postgres';) or check bundler configuration.