Read on to learn about special considerations for using Microsoft Azure Web Apps as a hosting service with New Relic's Node.js agent.
What you need
In addition to the Compatibility and requirements for the Node.js agent, this tutorial assumes you have a working installation of Node.js and the Windows Azure SDK for Node.js for your platform:
- Install the Azure SDK for Node.js.
- Ensure Git is installed.
Installing the Node.js agent
To add the New Relic Node.js agent to your Azure application:
In your app's root, verify that there is a
package.json
file. If there is not, create one via the command line:touch package.jsonAdd the following to your
package.json
file:{"name": "node","version": "0.0.1","dependencies" : {"newrelic" : "*"},"engine": {"node": "10.18"}}Add
require('newrelic');
to the top of theserver.js
file. For example:require('newrelic');var http = require('http')var port = process.env.PORT || 1337;http.createServer(function(req, res) {res.writeHead(200, { 'Content-Type': 'text/plain' });res.end('Hello New Relic Node.js agent!\n');}).listen(port);
Adding app settings in Azure
After installation, you must configure your app in Azure Web Apps:
Sign in to portal.azure.com.
Select App Services > (select a Node.js app) > Configure.
Add the following to the app settings:
new_relic_app_name
: Your Windows Azure website namenew_relic_license_key
: Your New Relic license key
Save your settings.
Restart your Node.js app.
Generate some traffic to your app and wait a few minutes. After waiting, see your data by going to one.newrelic.com > APM > (select your app).
Optional: Adding app settings with the CLI
Optional: Here is an example of how to add the app settings by using the CLI (Node SDK):
azure account download "YOUR_SUBSCRIPTION_NAME"
azure account import "PATH_TO_PUBLISH_SETTINGS_FILE"
azure site config add "new_relic_app_name=REPLACE_WITH_YOUR_APP_NAME"
azure site config add "new_relic_license_key=REPLACE_WITH_YOUR_LICENSE_KEY"
azure site restart AZURE_WEB_APP_NAME
Using environment variables
If your agent runs in PaaS environments such as Heroku or Azure Web Apps, all of the configuration variables in newrelic.js
have counterparts that can be set as environment variables. You can freely mix and match variables in the configuration file. Environment variables override your configuration file settings.
For example, as a convenience to Azure users, the agent will use APP_POOL_ID
as the application name (NEW_RELIC_APP_NAME
) if it's set, so you can use the name you chose without setting it twice. For more information, see Configuring Node.js with environment variables.
For more help
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's and and documentation.