Socket
Socket
Sign inDemoInstall

@opentelemetry/instrumentation-pg

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-pg

OpenTelemetry instrumentation for `pg` and `pg-pool` database client for PostgreSQL


Version published
Weekly downloads
2.2M
increased by13.44%
Maintainers
3
Weekly downloads
 
Created

What is @opentelemetry/instrumentation-pg?

@opentelemetry/instrumentation-pg is an npm package that provides automatic instrumentation for the 'pg' (node-postgres) module, enabling the collection of telemetry data such as traces and metrics for PostgreSQL database operations. This helps in monitoring and debugging database interactions in applications.

What are @opentelemetry/instrumentation-pg's main functionalities?

Automatic Tracing

This feature allows automatic tracing of PostgreSQL operations. The code sample demonstrates how to set up the NodeTracerProvider and register the PgInstrumentation to start collecting trace data.

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

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new PgInstrumentation(),
  ],
  tracerProvider: provider,
});

Custom Span Attributes

This feature allows adding custom attributes to spans. The code sample shows how to configure the PgInstrumentation to include additional information such as the number of rows returned in the response.

const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg');

const pgInstrumentation = new PgInstrumentation({
  enhancedDatabaseReporting: true,
  responseHook: (span, responseInfo) => {
    span.setAttribute('db.response.rows', responseInfo.rowCount);
  },
});

Error Handling

This feature allows capturing and reporting errors in database operations. The code sample demonstrates how to set the span status to error if an error occurs during the database operation.

const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg');

const pgInstrumentation = new PgInstrumentation({
  responseHook: (span, responseInfo) => {
    if (responseInfo.error) {
      span.setStatus({ code: 2, message: responseInfo.error.message });
    }
  },
});

Other packages similar to @opentelemetry/instrumentation-pg

Keywords

FAQs

Package last updated on 04 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc