Getting Elastic APM set up for your Restify app is easy,
and there are various ways you can tweak it to fit your needs.
Follow the guide below to get started, and for more advanced topics,
check out the API Reference.

In the above example we initialize the agent by calling the start() function.
This function takes an optional options object used to configure the agent.
Any option not supplied via the options object can instead be configured using environment variables.
So if you prefer, you can set the same configuration options using environment variables:

Spans are grouped in transactions - by default one for each incoming HTTP request.
But it’s possible to create custom transactions not associated with an HTTP request.
See the Custom Transactions section for details.

When viewing the performance metrics of your application in Elastic APM,
you might see some transactions named "unknown route".
This indicates that the agent detected an incoming HTTP request to your application,
but didn’t know which route in your Restify app the HTTP request matched.

This might simply be 404 requests,
which by definition don’t match any route,
or it might be a symptom that the agent wasn’t installed correctly.
If you see this or can’t get any meaningful metrics to show up,
please follow the Troubleshooting Guide.

By default, the Node.js agent will watch for uncaught exceptions and send them to Elastic APM automatically.
But in most cases, errors are not thrown but returned via a callback,
caught by a promise,
or simply manually created.
Those errors will not automatically be sent to Elastic APM.
To manually send an error to Elastic APM,
simply call apm.captureError() with the error:

The Node.js agent will keep track of the active HTTP request and will link it to errors and recorded transaction metrics when they are sent to the Elastic APM server.
This allows you to see details about which request resulted in a particular error or which requests cause a certain HTTP endpoint to be slow.

But in many cases,
information about the HTTP request itself isn’t enough.
To add even more metadata to errors and transactions,
use one of the functions below:

apm.setUserContext() - Call this to enrich collected performance data and errors with information about the user/client

apm.setCustomContext() - Call this to enrich collected performance data and errors with any information that you think will help you debug performance issues and errors (this data is only stored, but not indexed in Elasticsearch)

apm.setTag() - Call this to enrich collected performance data and errors with simple key/value strings that you think will help you debug performance issues and errors (tags are indexed in Elasticsearch)