Datadog Middleware for Express/Connect

raw JSON →
0.0.9 verified Thu Apr 23 auth: no javascript deprecated

The `connect-datadog` package, currently at version 0.0.9 and last updated over seven years ago, provides a basic middleware for Express.js and Connect-compatible Node.js applications to send HTTP request metrics to a local Datadog Agent via the DogStatsD protocol. This middleware captures essential request telemetry such as response times, HTTP status codes, and request paths, allowing for rudimentary monitoring within Datadog dashboards. However, this library is officially deprecated and its GitHub repository is auto-archived due to inactivity. Datadog strongly recommends migrating to its comprehensive Application Performance Monitoring (APM) solutions, which offer advanced features, continuous updates, and broader integration capabilities for modern Node.js environments. There is no active release cadence for `connect-datadog`, marking it as an unmaintained and historical tool, superseded by Datadog's more robust and actively developed APM offerings. It uses `node-dogstatsd` internally, which itself has more modern alternatives.

error ReferenceError: require is not defined
cause Attempting to use `require()` in an ES module (ESM) context when `package.json` specifies `"type": "module"` or the file has a `.mjs` extension.
fix
This package is CommonJS-only. To use it in an ESM project, you might need a wrapper or dynamic import, but it's strongly recommended to migrate to a modern, ESM-compatible Datadog APM client (e.g., dd-trace) instead.
error Metrics are not appearing in Datadog dashboards for my Express application.
cause The Datadog Agent with DogStatsD might not be running, or there's a network issue preventing the application from sending UDP packets to the agent.
fix
Verify the Datadog Agent is installed and running on your host. Check the Agent's logs for DogStatsD errors. Confirm that UDP port 8125 (default) is open and reachable by your application. Ensure the dogstatsd client configured in connect-datadog points to the correct host and port if not using defaults.
error TypeError: app.router is deprecated, you should probably just remove it.
cause The quickstart example `app.use(app.router);` is an outdated practice from older Express.js versions.
fix
Remove the line app.use(app.router); from your application. In modern Express, routing is handled automatically and this line is unnecessary and can cause warnings or errors.
breaking The `connect-datadog` library is officially deprecated and its GitHub repository is auto-archived. Datadog strongly recommends migrating to Datadog APM for Node.js for comprehensive monitoring, as this library will receive no further updates and may not be compatible with future Node.js or Express versions.
fix Migrate to Datadog's official APM client for Node.js (e.g., `dd-trace`) which provides automatic instrumentation and richer features. Refer to the Datadog APM documentation for Node.js.
gotcha This package has not been updated in over seven years (last published version 0.0.9). It may have compatibility issues with modern Node.js versions (e.g., Node.js 14+) and recent Express.js versions, potentially leading to unexpected behavior or runtime errors.
fix It is strongly advised to use Datadog APM or a more actively maintained StatsD client for Node.js (like `hot-shots`) for new projects and consider migrating existing ones.
gotcha The middleware relies on a running Datadog Agent with DogStatsD enabled on the host machine or a reachable network address. If the agent is not running or misconfigured, metrics will not be collected by Datadog.
fix Ensure the Datadog Agent is installed, running, and DogStatsD is enabled. Verify network connectivity between your application and the DogStatsD UDP port (default 8125). Refer to Datadog Agent and DogStatsD setup documentation.
deprecated The usage pattern `app.use(app.router);` shown in the original README is deprecated in modern Express.js versions. Routing middleware should typically be registered directly after global middleware, before defining specific routes.
fix Remove the line `app.use(app.router);` from your application. In modern Express, routing is handled automatically and this line is unnecessary and can cause warnings or errors.
npm install connect-datadog
yarn add connect-datadog
pnpm add connect-datadog

Demonstrates integrating the `connect-datadog` middleware into a basic Express application to send HTTP request metrics to a Datadog Agent.

const express = require('express');
const connectDatadog = require('connect-datadog');
const app = express();
const port = process.env.PORT || 3000;

// Datadog middleware options
const ddOptions = {
  stat: 'node.express.router',
  tags: ['app:my-old-express-app', 'environment:development'],
  path: true, // Include path tag
  method: true, // Include http method tag
  response_code: true // Include http response code tag
};

// Add middleware immediately before your router, as per original instructions.
// NOTE: The example `app.use(app.router)` is deprecated in modern Express.
// Instead, place this middleware before your route definitions.
app.use(connectDatadog(ddOptions));

app.get('/', (req, res) => {
  res.send('Hello from Datadog-monitored Express App!');
});

app.get('/data', (req, res) => {
  res.json({ message: 'Some data' });
});

app.listen(port, () => {
  console.log(`Server listening at http://localhost:${port}`);
  console.log('Ensure Datadog Agent with DogStatsD is running on the host.');
});