Tech Topics

Elastic APM Node.js Agent: Now with Restify Instrumentation

With the 1.12.0 release of the Elastic APM Node.js agent, we now have the ability to identify routes and collect errors for the restify server framework. See the CHANGELOG.md for the full list of changes in this release.

Getting started with restify

Using restify with Elastic APM requires no special configuration. Here’s a simple app to demonstrate tracing:

require('elastic-apm-node').start()
var restify = require('restify')

var app = restify.createServer()

app.get('/hello/:name', (req, res, next) => {
  res.send('hello ' + req.params.name)
  next()
})

app.listen(3000)

With this app, a request to /hello/world will produce a transaction with the name GET /hello/:name.

Error reporting

There is also no configuration necessary to benefit from reporting of restify errors. Any error given to the next method in a route will be reported.

app.get('/fail', (req, res, next) => {
  return next(new restify.errors.NotFoundError('fail'))
})

A request to the /fail route will record the NotFoundError.

Give it a try!

If you are already using the Elastic APM Node.js agent, all you need to do is upgrade to the latest version and your restify servers will start naming transaction with route names and will report errors — no configuration needed.

If you haven’t yet taken Elastic APM for a spin, get started by reading our Getting Started Guide.

What’s next?

There’s always something new and exciting in the pipeline, but right now we’re working hard to enable distributed tracing. With distributed tracing, Elastic APM will be able to correlate requests between multiple servers to form a unified trace across multiple servers, revealing what part of the entire user-facing request lifecycle would benefit the most from performance improvements.

Please give the agent a try and give some feedback in the discussion forum. We are also always open for contributions, so feel free to check out the source code over at GitHub and to open a pull request.