NodeJS Express
Installation
Following are the steps to install the New Relic agent and connect it with CubeAPM. If New Relic agent is already installed, you can jump to step 5.
-
Install dependencies
npm install newrelic
-
(Optional) From
node_modules/newrelic
, copynewrelic.js
into the root directory of your application. -
Configure the agent.
- newrelic.js
- Environment Variables
exports.config = {
app_name: ["<app_name>"],
license_key: "ABC4567890ABC4567890ABC4567890ABC4567890",
};NEW_RELIC_APP_NAME=<app_name>
NEW_RELIC_LICENSE_KEY=ABC4567890ABC4567890ABC4567890ABC4567890 -
Load the agent when the application starts.
- Code
- Environment Variables
- Startup Command
Add the following line at the top of your project's main file.
const newrelic = require("newrelic");
NODE_OPTIONS=--require newrelic
Add
--require newrelic
to your application run command, e.g.,node --require newrelic app.js
-
Tell the agent to connect with CubeAPM instead of New Relic.
- newrelic.js
- Environment Variables
exports.config = {
app_name: ["<app_name>"],
license_key: "ABC4567890ABC4567890ABC4567890ABC4567890",
host: "<domain_of_cubeapm_server>",
};NEW_RELIC_APP_NAME=<app_name>
NEW_RELIC_LICENSE_KEY=ABC4567890ABC4567890ABC4567890ABC4567890
NEW_RELIC_HOST=<domain_of_cubeapm_server>tipSee Using CubeAPM with New Relic agents for details on how to set up
<domain_of_cubeapm_server>
.
Sample App
A working example is available at https://github.com/cubeapm/sample_app_nodejs_express/tree/newrelic
Troubleshooting
The following can be used for troubleshooting:
- newrelic.js
- Environment Variables
exports.config = {
logging: {
// Print New Relic agent logs on screen
filepath: "stdout",
// Set New Relic agent log level to debug if needed to see detailed logs
level: "debug",
},
};
# Print New Relic agent logs on screen
NEW_RELIC_LOG=stdout
# Set New Relic agent log level to debug if needed to see detailed logs
NEW_RELIC_LOG_LEVEL=debug