+0
日增长
+0
周增长
1,000
stars
428
forks
37
watchers
2,843
prs
1,630
issues
232
releases
README
New Relic's Node.js agent
[![npm status badge][1]][2] [![Server Smoke Tests][3]][4] [![Node Agent CI][5]][6] [![codecov][7]][8]
This package instruments your application for performance monitoring with New Relic.
In order to take full advantage of this package, make sure you have a New Relic account before starting.
As with any instrumentation tool, please test before using in production.
Installation
To use New Relic's Node.js agent entails these three steps, which are described in detail below:
- Install the newrelic package
- Create a base configuration file
- Load the agent in your program
1. To install the agent for performance monitoring, use your favorite npm-based package manager and install the newrelic package into your application:
sh
$ npm install newrelic
2. Then, copy the stock configuration file to your program's base folder:
sh
$ cp ./node_modules/newrelic/newrelic.js ./
3. Now, add your New Relic license key and application/service name to that file:
js
/ File: newrelic.js /
'use strict'
/
New Relic agent configuration.
See lib/config/schemas/ in the agent distribution for a more complete
description of configuration variables and their potential values.
/
exports.config = {
app_name: ['Your application or service name'],
license_key: 'your new relic license key',
/ ... rest of configuration .. /
}
You can validate your configuration file is valid by using the included
configuration validator:
sh
$ npx newrelic validate-config --config-file ./newrelic.js
4. Finally, run your program with the newrelic module loaded first by using node's -r/--require flag.
sh
$ node -r newrelic your-program.js
If you cannot control how your program is run, you can load the newrelic module _before any other module_ in your program.
js
const newrelic = require('newrelic')
/ ... the rest of your program ... /
Next.js instrumentation
We recommend using the hybrid agent functionality to setup Next.js. Please read our Next.js instrumentation with hybrid agent document for more information. The following example applications show how to load the newrelic hybrid agent instrumentation, inject browser agent, and deploying to Vercel:
App Router example
ECMAScript Modules
If your application is written with import and export statements in javascript, you are using ES Modules and must bootstrap the agent in a different way.
The New Relic Node.js agent includes support for ES Modules.
Setup
1. If you rely on a configuration file to run the agent, you must rename the file from newrelic.js to newrelic.cjs so it can be properly loaded. All the contents of the configuration file will behave the same once you rename. See CommonJS modules in ESM for more details.
sh
$ mv newrelic.js newrelic.cjs
2. To use the newrelic ESM loader, start your program with node Top issues
#1727Deno support20 comments · 2023-07-15#598Support knex/thenables13 comments · 2021-01-22#3282Remove `npm i -g` in test6 comments · 2025-08-06#1788In cases where a SQL query does not contain an explicit FROM clause, table name appears as 'unknown'6 comments · 2023-09-27#647Neo4J instrumentation6 comments · 2021-03-03#3483`addCustomAttribute()` adds the attribute to the wrong `Span`5 comments · 2025-11-01#3201ESM support4 comments · 2025-07-02#2176Assign attributes to a transaction from a different async context4 comments · 2024-04-30
Latest release
v14.13.0 v14.13.0 2026-11-16v14.13.0 (2026-11-16) Features Added event.name to logs when eventName exist on opentelemetry log record (4486) (19ad0f8) Bug fixes Corrected protocol and port of outbound http/https requests (4473) (ab1b4b8) Fixed capturing of response headers for writeHead (4477) (fab8012) Returned the application handler promise from the kafkajs eachMessage wrapper (4488) (3263f9a) Code refactoring Migrated http client (including http-outbound) instrumentation to subscriber-based (4472) (191a052) Migrated http server instrumentation to subscriber-based (4472) (04a3101) Docu