Request Metrics for Node.js

Our npm package can now send us request metrics for Connect, Express and other Node.js web frameworks (or you can roll your own!).

Today we're apathetically announcing that we now support monitoring request metrics for web apps written in Node.js. This change may give some Node customers (whatever) deeper insight into their web applica... SORRY (sry), I can't do this. We try to live up to our name and not care at Honeybadger, but the truth is that we DO care. Not only do we care, but we're unbelievably stoked to announce that we're bringing our performance monitoring tools to Node.

This week we released version v1.1 of our honeybadger npm package. This release is the next step forward for our Node.js monitoring suite, on the heels of version v1.0 which really stepped up our Node game.

In v1.0 we brought new tools for monitoring popular Node.js frameworks and platforms such as middlware for Connect and Express, built-in support for monitoring AWS Lambda, and more.

With v1.1, we've added a new middleware for Connect/Express apps called Honeybadger.metricsHandler(). A simple express app might look like this:

var express = require('express');
var Honeybadger = require('honeybadger');

var app = express();

app.use(Honeybadger.metricsHandler);
app.use(Honeybadger.requestHandler);

app.all('/fail', function (req, res) {
  throw(new Error('This was thrown in an Express app.'));
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

app.use(Honeybadger.errorHandler);

Notice that we're using the new metricsHandler middlware before the normal requestHandler (which ensures asynchonous errors are reported) and the errorHandler middleware (which actually reports the errors).

For Connect or Express, that's the only change required to see your request metrics in Honeybadger:

Node.js request metrics

For other frameworks, we've added a Honeybadger.timing() method which can be used to send us request metrics manually:

var startAt = process.hrtime();

// Process request here.

// Calculate the time difference in milliseconds.
var diff = process.hrtime(startAt);
var time = diff[0] * 1e3 + diff[1] * 1e-6;åç

Honeybadger.timing("app.request.200", time)

The format for request metrics is app.request.STATUS_CODE, where status code is the integer status code of the response (i.e. 200, 301, 500, etc.). Still pretty easy, right?

So that's it. In the coming months we'll be working to make performance monitoring for Node even better. In the meantime, we hope that monitoring your request metrics will help you keep your Node.js apps performing at their best. Let me know what you think!


Feedback is welcome! Have a comment, question, suggestion, or bug report? Email me, submit an issue, or send a pull request.

Need a Honeybadger account? Start your free trial and monitor your Node app today!

author photo

Joshua Wood

Josh is Honeybadger's resident bug hunter and technical debt collector. Once enthusiastically referred to as a "human exception tracker", he spends his days crafting the middleware, plugins, and gems which keep the 'badger fat and happy through a steady diet of fresh data.

“We’ve looked at a lot of error management systems. Honeybadger is head and shoulders above the rest and somehow gets better with every new release.”
Michael Smith
Try Error Monitoring Free for 15 Days