express-statsd icon indicating copy to clipboard operation
express-statsd copied to clipboard

Make `sendStats` customizable

Open jfresco opened this issue 9 years ago • 0 comments

In order to be able to gain more control on what is being logged, the sendStats function should be configurable. In my case, I want to log more info than status_code and response_time. Also, the default client Lynx exposes methods like decrement ,gauge and set that a user may want to use.

My proposal is that the lib allows me to do something like this:

var expressStatsd = require('express-statsd')
var statsd = expressStatsd({
  host: 'localhost',
  port: 8125,
  sendStatus: function (req, res, client, options) {
    var key = req.myKey || req[options.requestKey];
    metrics.increment(key + '.node_test.int');
    metrics.decrement(key + '.node_test.int');
    metrics.timing(key + '.node_test.some_service.task.time', 500); // time in ms
    metrics.gauge(key + '.gauge.one', 100);
    metrics.set(key + '.set.one', 10);
  }
})

app.use(statsd)

app.get('/hello', function (req, res) {
  req.myKey = 'hello'
  // ... snip ...
})

jfresco avatar May 03 '16 17:05 jfresco