express-hot-shots

raw JSON →
1.0.2 verified Sat Apr 25 auth: no javascript maintenance

Simple Express/Connect middleware for StatsD route monitoring that sends status codes and response times per route. Version 1.0.2 is the latest stable release (last updated in 2018). Key differentiators: lightweight, fork of uber/express-statsd with support for tags and per-route keys via req.statsdKey and req.statsdTags. Works with plain HTTP servers, not just Express. Release cadence: sporadic, no updates since initial release.

error Cannot find module 'hot-shots'
cause hot-shots is not listed as a dependency of express-hot-shots.
fix
Install hot-shots: npm install hot-shots
error TypeError: statsdMiddleware is not a function
cause Using the import as a constructor or not calling the factory function.
fix
Call the default export: statsdMiddleware(options) or import as default: import statsdMiddleware from 'express-hot-shots'
error req.statsdKey is not set, metrics have generic names
cause Failing to set req.statsdKey before response.
fix
Set req.statsdKey in a middleware before the route handler, e.g., req.statsdKey = 'http.get.home';
gotcha If you don't set req.statsdKey, metrics will use a generic 'status_code' and 'response_time' key without route context.
fix Always set req.statsdKey before the response is sent, e.g., in a per-route middleware.
gotcha express-hot-shots requires the 'hot-shots' package to be installed separately; it is not included as a dependency.
fix Run: npm install hot-shots
deprecated This package has not been updated since 2018 and may have compatibility issues with modern Express versions.
fix Consider using alternatives like 'express-statsd' or direct integration with 'hot-shots'.
gotcha The middleware only sends metrics after the response is finished; setting req.statsdKey in the route handler after calling next may not apply if the response is sent later.
fix Set req.statsdKey in a middleware that runs before any other middleware that sends the response.
npm install express-hot-shots
yarn add express-hot-shots
pnpm add express-hot-shots

Shows how to set up express-hot-shots with Express, configure StatsD host/port, and use per-route keys via req.statsdKey.

import express from 'express';
import statsdMiddleware from 'express-hot-shots';
const app = express();
app.use(statsdMiddleware({
  hotShots: {
    host: process.env.STATSD_HOST || 'localhost',
    port: parseInt(process.env.STATSD_PORT || '8125')
  }
}));
app.get('/api/hello', (req, res) => {
  req.statsdKey = ['http', req.method.toLowerCase(), 'hello'].join('.');
  res.send('Hello World!');
});
app.listen(3000);