OpenTelemetry postgres automatic instrumentation package.

Downloads in past


347950.31.110 days ago2 years agoMinified + gzip package size for @opentelemetry/instrumentation-pg in KB


OpenTelemetry Postgres Instrumentation for Node.js
!NPM Published Versionnpm-imgnpm-url !Apache Licenselicense-imagelicense-image
This module provides automatic instrumentation for the pgmodule, which may be loaded using the @opentelemetry/sdk-trace-node package and is included in the @opentelemetry/auto-instrumentations-node bundle.
If total installation size is not constrained, it is recommended to use the @opentelemetry/auto-instrumentations-node bundle with @opentelemetry/sdk-node for the most seamless instrumentation experience.
Compatible with OpenTelemetry JS API and SDK 1.0+.


npm install --save @opentelemetry/instrumentation-pg

Supported Versions

  • >=7 <9


const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const provider = new NodeTracerProvider();

  instrumentations: [
    new PgInstrumentation(),

PgInstrumentation contains both pg and pg.Pool so it will be instrumented automatically.
See examples/postgres for a short example.

PostgreSQL Instrumentation Options

PostgreSQL instrumentation has few options available to choose from. You can set the following:
| Options | Type | Description | | ------- | ---- | ----------- | | enhancedDatabaseReporting | boolean | If true, additional information about query parameters and results will be attached (as attributes) to spans representing database operations | | responseHook | PgInstrumentationExecutionResponseHook (function) | Function for adding custom attributes from db response |

Useful links

  • For more information on OpenTelemetry, visit:
  • For more about OpenTelemetry JavaScript:
  • For help or feedback on this project, join us in GitHub Discussionsdiscussions-url


Apache 2.0 - See LICENSElicense-url for more information.