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. Available features, such as slow transaction traces, will vary based on account level.
As with any instrumentation tool, please test before using in production.
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
- Require the agent in your program
-
To install the agent for performance monitoring, use your favorite npm-based package manager and install the
newrelic
package into your application:$ npm install newrelic
-
Then, copy the stock configuration file to your program's base folder:
$ cp node_modules/newrelic/newrelic.js
-
Now, add your New Relic license key and application/service name to that file:
/* File: newrelic.js */
'use strict'
/**
* New Relic agent configuration.
*
* See lib/config/default.js 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 .. */
}
- Finally, load the
newrelic
module before any other module in your program.
const newrelic = require('newrelic')
/* ... the rest of your program ... */
If you're compiling your JavaScript and can't control the final require
order, the Node,js agent will work with node's -r/--require
flag.
$ node -r newrelic your-program.js
$ node --require newrelic your-program.js
For more information on getting started, check the Node.js docs.
The newrelic
module returns an object with the Node agent's API methods attached.
const newrelic = require('newrelic')
/* ... */
newrelic.addCustomAttribute('some-attribute', 'some-value')
You can read more about using the API over on the New Relic dcumentation site.
These are the steps to work on core agent features, with more detail below:
- Fork the agent
- Install its dependencies
- Run tests using
npm
-
Fork and clone this GitHub repository:
$ git clone git@github.com:your-user-name/node-newrelic.git $ cd node-newrelic
-
Install the project's dependences:
$ npm install
Then you're all set to start programming.
- Install Docker
- Start the Docker services:
$ npm run services
- Run all the tests using
$ npm run test
Available test suites include:
$ npm run unit
$ npm run integration
$ npm run versioned
$ npm run lint
$ npm run smoke
Here are some resources for learning more about the agent:
New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub. You can find this project's topic/threads here:
https://discuss.newrelic.com/c/support-products-agents/node-js-agent/
We encourage your contributions to improve the Node.js agent. Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant.
You only have to sign the CLA one time per project.
If you have any questions or need to execute our corporate CLA, (required if your contribution is on behalf of a company), please drop us an email at opensource@newrelic.com.
The Node.js agent is licensed under the Apache 2.0 License.
The Node.js agent also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.