datadog-metrics is a Node.js library designed for buffering and reporting application metrics to Datadog via its HTTP API. It supports common metric types including gauges, increments, histograms, and distributions. The current stable version is 0.12.1, with a pre-release (0.13.0-pre.1) indicating a future focus on reducing the bundle size and resource footprint by decoupling from heavier official Datadog clients. The library features automatic metric flushing before process exit (since v0.12.1), automatic retries for failed submissions (since v0.12.0), and includes built-in TypeScript definitions (since v0.11.0). Its release cadence is moderate, with significant feature updates often accompanied by breaking changes.
npm install datadog-metricsVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the global metrics reporter and sending various metric types (gauge, increment, histogram, distribution). Also shows how to create and use a separate BufferedMetricsLogger instance for isolated metric collection, and how to perform an explicit flush operation.
Ensure your Node.js environment is at least v14.0.0 before upgrading to v0.13.0 or later.
Update any error handling logic that inspects the `code` property of `AuthorizationError` instances to use the new string literal.
For critical metrics or specific exit scenarios, explicitly call `metrics.flush()` and await its completion before `process.exit()` or when `flushIntervalSeconds` is zero.
Refactor any asynchronous operations to use Promise-based syntax (e.g., `async/await` or `.then/.catch`) instead of passing callback functions.
If you are directly using `new DatadogReporter(...)`, update your constructor call to pass a single options object.
Remove `@types/datadog-metrics` from your `package.json` and `npm install` or `yarn install`.
Ensure you are using the `aggregates` option when configuring histogram behavior, not `aggregations`.
Set the `DD_API_KEY` environment variable or explicitly pass an `apiKey` string in the options object to `metrics.init()` or `new BufferedMetricsLogger()`.
Ensure `metrics.init()` is called and completes successfully before any other metric reporting functions are invoked on the global `metrics` object.
Ensure `metrics.init()` is called only once in your application's lifecycle. If you need multiple independent loggers, use `new BufferedMetricsLogger()` instead.