{"library":"opentelemetry-node-metrics","title":"OpenTelemetry Node.js Process Metrics","description":"opentelemetry-node-metrics is a Node.js library that adapts the widely used `prom-client` metric set to the OpenTelemetry ecosystem, specifically for capturing process-level metrics. It currently stands at version 3.0.0, which dropped support for `@opentelemetry/api-metrics` older than v0.33, continuing a pattern of major version releases aligning with significant OpenTelemetry API updates. This library provides a direct translation of common system and runtime metrics (like CPU usage, memory, event loop lag, garbage collection statistics, and network/file descriptor usage) into OpenTelemetry-compatible instruments. Its primary differentiator is leveraging the `prom-client`'s established metric definitions, which can ease migration for projects already familiar with Prometheus-style monitoring, while integrating seamlessly into an OpenTelemetry-based observability pipeline. Notably, it does not offer Node.js cluster support, a limitation inherited from the underlying OpenTelemetry metrics API. The release cadence is directly tied to the evolution of the OpenTelemetry JavaScript SDK, leading to breaking changes primarily driven by API shifts.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install opentelemetry-node-metrics"],"cli":null},"imports":["import registerProcessMetrics from 'opentelemetry-node-metrics';","const registerProcessMetrics = require('opentelemetry-node-metrics');","import { MeterProvider } from '@opentelemetry/sdk-metrics';","import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const { MeterProvider } = require('@opentelemetry/sdk-metrics');\nconst { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');\n\n// Configure the Prometheus exporter\nconst exporter = new PrometheusExporter(\n  { startServer: true }, // Starts an HTTP server for Prometheus to scrape\n  () => {\n    console.log(\n      `Prometheus scrape endpoint: http://localhost:${PrometheusExporter.DEFAULT_OPTIONS.port}${PrometheusExporter.DEFAULT_OPTIONS.endpoint}`,\n    );\n  },\n);\n\n// Configure the MeterProvider\nconst meterProvider = new MeterProvider({\n  readers: [exporter], // Use `readers` for SDK v1.0+ instead of `exporter`\n  interval: 2000,\n});\n\n// Register process metrics\nconst registerProcessMetrics = require('opentelemetry-node-metrics');\nregisterProcessMetrics(meterProvider);\n\n// Ensure graceful shutdown (optional but recommended)\nprocess.on('SIGTERM', () => {\n  meterProvider.shutdown().then(() => console.log('Metrics shutdown complete.'));\n});\nprocess.on('SIGINT', () => {\n  meterProvider.shutdown().then(() => console.log('Metrics shutdown complete.'));\n});","lang":"javascript","description":"Initializes OpenTelemetry metrics for the Node.js process and exposes them via a Prometheus-compatible HTTP endpoint. This example sets up a `MeterProvider` with a `PrometheusExporter` and registers the `opentelemetry-node-metrics` plugin.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}