Search Sreeni's Insights

Filter by content type
cloud January 16, 2018 7 min read

How to Configure New Relic Agent for Azure Web App?

Install and configure the New Relic agent for an Azure Web App from the Azure portal: app name, site extension, profiler settings and license key.

Share:

How to Configure New Relic Agent for Azure Web App?

An Application Performance Monitoring (APM) tool is only as good as the data its agent collects. For an application hosted in Azure Web App (App Service), we don’t have access to the server to run an installer, so the agent has to be installed and configured in a way which works with the platform. We can install the New Relic agent for an Azure Web App in three different ways. In this post, we are going to see how to install it through the Azure portal, which is the easiest way to get started. If you are new to APM, refer to Why we need an APM for better operations? - Part 1 and How to select an APM tool? - Part 3 before you start.

TL;DR Summary

  • Installing the New Relic agent through the Azure portal has three main steps: set the New Relic app name, install the New Relic extension and configure the agent settings.
  • Give every application a unique New Relic app name, and a separate name for each environment.
  • The agent is installed as a site extension, and it is enabled with the profiler settings in the Application Settings of the web app.
  • Keep the New Relic license key in the Application Settings, never in the source code.
  • Restart the web app after the configuration; the data takes 5 to 10 mins to appear in New Relic.

Prerequisites

  • An Azure Web App running an ASP.NET (.NET Framework) application
  • Access to the web app in the Azure portal
  • A New Relic account and its license key

Steps to configure the New Relic agent

The configuration has the following three main steps,

  1. Set the New Relic app name in web.config
  2. Install the New Relic extension
  3. Configure the New Relic agent settings

Step 1: Set the New Relic App Name

Every New Relic app should have a unique name, and it should be specified in the appSettings section of web.config as below,

<appSettings>
  <add key="NewRelic.AppName" value="<your app name>" />
</appSettings>

This is the name you will see in the list of applications in New Relic APM. Replace the input place holder with the actual value.

Info: Azure Web App replaces the values in the appSettings section of web.config with the Application Settings of the same key in the portal. So, you can also add NewRelic.AppName in the Application Settings (see Step 3) and use a different name for each environment, like MyApp-QA and MyApp-Production. Otherwise, the data from all environments will be mixed under one application in New Relic.

Step 2: Install the New Relic Extension

Follow the following steps to install the New Relic extension in the Azure portal.

  1. Login to the Azure portal (https://portal.azure.com).
  2. Go to the web app where you want to install the New Relic agent.
  3. Go to the Extensions tab.
  4. Click on the Add button, and it will take you to the Choose Extension tab.
  5. Select the New Relic extension in the list.
  6. It will take you to the Legal Terms page. Click on the OK button.
  7. It will go back to the Add Extension tab. Click on the OK button to install the agent.
  8. It will take one or more mins to install.
  9. You can see the New Relic extension in the list after it is successfully installed.

The extension copies the agent files into the newrelic folder under D:\Home\site\wwwroot of the web app. We will point the agent settings to this folder in the next step.

Step 3: Configure the New Relic Agent

Once you have done the above steps, you need to configure the New Relic agent specific settings in the Azure portal. Follow the following steps to configure the New Relic agent settings,

  1. Go to the web app where you want to configure the New Relic agent settings.
  2. Go to the Application Settings tab.
  3. Scroll down to the App Settings section.
  4. Add the following settings.
KeyValue
COR_ENABLE_PROFILING1
COR_PROFILER{71DA0A04-7777-4EC6-9643-7D28B46A8A41}
COR_PROFILER_PATHD:\Home\site\wwwroot\newrelic\NewRelic.Profiler.dll
NEWRELIC_HOMED:\Home\site\wwwroot\newrelic
NEW_RELIC_LICENSE_KEY<your new relic license key>
  1. Click on the Save button.

Let us understand what these settings do,

  • COR_ENABLE_PROFILING - It tells the .NET runtime (CLR) to load a profiler when the application starts.
  • COR_PROFILER - The unique identifier (CLSID) of the New Relic profiler, so the CLR knows which profiler to load.
  • COR_PROFILER_PATH - The location of the New Relic profiler DLL installed by the extension.
  • NEWRELIC_HOME - The folder where the agent finds its configuration and writes its logs.
  • NEW_RELIC_LICENSE_KEY - The license key which connects the agent to your New Relic account.

The New Relic agent uses the CLR profiling API to instrument the application without any code change, and these settings are how we switch it on.

Note: These settings are for ASP.NET applications on the .NET Framework. ASP.NET Core applications on .NET Core use a different set of profiler settings; refer to the New Relic documentation for them.

How to get the license key?

Follow the following steps to get the license key,

  1. Login to your New Relic account.
  2. Open your profile menu and click on Account Settings.
  3. In the Account Settings page, you can find the License Key section at the right-hand side.
  4. Copy the available license key and update it in the App Settings.

Must Do: Keep the license key only in the Application Settings of the web app. Don’t add it to web.config or any other file in the source control.

Step 4: Restart and verify

Once you have done all the above steps, restart the web app to start the New Relic agent. The agent is loaded only when the application starts, so the settings don’t take effect until the restart.

Just to pulse check,

  1. Browse a few pages of your application, so the agent has some transactions to report.
  2. Login to New Relic and open APM.
  3. You should see your application with the name you set in Step 1.

It will take 5 to 10 mins to reflect in the New Relic site.

Troubleshooting

If you can’t see your application in New Relic after 10 to 15 mins, check the following,

  • Did you restart the web app? The profiler settings take effect only after a restart.
  • Are all five settings correct? A typo in COR_PROFILER or COR_PROFILER_PATH silently disables the agent. Compare them with the table above.
  • Does the agent folder exist? Open the Kudu console (Advanced Tools in the portal) and check that D:\Home\site\wwwroot\newrelic has NewRelic.Profiler.dll.
  • What do the agent logs say? Check the logs folder under NEWRELIC_HOME in the Kudu console. The log shows whether the agent started, which app name it used and whether it could connect to New Relic.
  • Is the license key correct? An invalid key is reported in the agent logs.

Must Be Aware: The agent files live in the wwwroot\newrelic folder of the web app. If your deployment removes the additional files at the destination (for example, the “remove additional files” option of Web Deploy), it deletes the agent as well, and New Relic stops receiving data after the next restart. Exclude the newrelic folder from the cleanup, or reinstall the extension after such deployments.

Wrap up

In this post, we have looked at how to configure the New Relic agent for an Azure Web App through the Azure portal: setting the New Relic app name, installing the New Relic extension, configuring the agent settings, getting the license key, verifying the setup and troubleshooting the common issues. I really appreciate that you took the time to read this post. For more information, refer to the New Relic documentation on installing the .NET agent for Azure Web Apps.

Related Posts