Guide to using the Node.js agent API

The New Relic Node.js agent API allows you to extend the agent's standard functionality. You can use this API to:

Customize your app name

Create custom transaction parameters

Report custom errors and metrics

You can also use the API for custom instrumentation. For supported frameworks, the agent instruments most activity automatically. Custom instrumentation lets you extend that monitoring to frameworks without default instrumentation.

Requirements

Instrument missing sections of your code with transactions

To instrument your app, New Relic separates each path through your code into its own transaction. New Relic times (or "instruments") the parent method in these transactions to measure your app's overall performance, and collects transaction traces from long-running transactions for additional detail.

Use these methods when New Relic is not instrumenting a particular part of your code at all:

Time specific methods using segments

If a transaction is already visible in the New Relic UI, but you don't have enough data about a particular method that was called during that transaction, you can create segments to time those individual methods in greater detail. For example, you might want to time a particularly critical method with complex logic.

Use this method when you want to instrument a method within an existing transaction:

Instrument asynchronous work

For supported frameworks and supported Node.js versions, New Relic's Node.js agent usually correctly instruments async work. However, if your app uses another framework, or if the default async instrumentation is inaccurate, you can explicitly track async work.

Instrument calls to external services

Once the request naming API loads, New Relic's Node.js agent can automatically identify external service calls. You can also use these methods to collect data about your app's connections to other apps or databases:

If you want to...

Do this...

Time a call to an external resource (such as an external service, database server, or message queue)

Control the New Relic Browser agent

Usually the Browser agent is added automatically to your pages or deployed by copy/pasting the JavaScript snippet. For more information about these recommended methods, see Add apps to New Relic Browser.