Datadog Middleware for Express/Connect
raw JSON →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.
Common errors
error ReferenceError: require is not defined ↓
dd-trace) instead. error Metrics are not appearing in Datadog dashboards for my Express application. ↓
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. ↓
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. Warnings
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. ↓
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. ↓
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. ↓
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. ↓
Install
npm install connect-datadog yarn add connect-datadog pnpm add connect-datadog Imports
- connectDatadog wrong
import connectDatadog from 'connect-datadog'; // ESM not supportedcorrectconst connectDatadog = require('connect-datadog'); app.use(connectDatadog({})); - DatadogOptions wrong
import { DatadogOptions } from 'connect-datadog'; // No types, no named exportscorrectconst connectDatadog = require('connect-datadog'); const ddOptions = { stat: 'web.requests', tags: ['env:production'], response_code: true }; app.use(connectDatadog(ddOptions)); - StatsDClientOverride wrong
const customDogstatsdClient = new SomeOtherClient(); // Must be node-dogstatsd compatiblecorrectconst connectDatadog = require('connect-datadog'); const StatsD = require('node-dogstatsd').StatsD; const customDogstatsdClient = new StatsD({ host: '127.0.0.1', port: 8125 }); app.use(connectDatadog({ dogstatsd: customDogstatsdClient }));
Quickstart
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.');
});