Install the .NET agent on Azure Service Fabric

By installing the New Relic .NET agent, you can instrument your application hosted using Azure Service Fabric. Follow the procedures in this document to install the appropriate version of the agent.

Install the .NET agent

If you are upgrading the agent using NuGet, any changes you made in the newrelic.config will be overwritten. To preserve any changes, save your newrelic.config outside of your project, then restore it after upgrading.

The following procedures explain how to add the New Relic .NET agent to your applications using NuGet. For multi-project solutions, make sure you have selected the correct project (for example, a specific web app project) before installing the NuGet package.

To install the .NET agent:

  1. Open your application in Visual Studio, and install the New Relic NuGet package by running the appropriate command from the Package manager console:

    Install-Package NewRelic.Agent
  2. Build your application. The .NET agent gets placed in your application's build output directory.

Configure the agent for your environment

The following procedures explain how to configure the New Relic .NET agent for applications hosted in an Azure Service Fabric cluster.

The steps to configure the .NET agent differ based on whether your application targets .NET Framework or .NET Core. Make sure you verify the target framework of your application, and follow the correct procedures.

.NET Framework app configuration

The directory name for APP_DEPLOYMENT_DIRECTORY depends on how your application is published to your Service Fabric cluster. It can help to deploy your application and log into the cluster to determine the correct directory name. This directory must resolve to the location your application is deployed to or the agent will not work.

  1. Review the ServiceManifest.xml in your project and include the following changes nested under the CodePackage node:
    <CodePackage>
      ...
      <EnvironmentVariables>
        ...
        <EnvironmentVariable Name="COR_ENABLE_PROFILING" Value="1" />
        <EnvironmentVariable Name="COR_PROFILER" Value="{71DA0A04-7777-4EC6-9643-7D28B46A8A41}" />
        <EnvironmentVariable Name="COR_PROFILER_PATH" Value="..\APP_DEPLOYMENT_DIRECTORY\newrelic\NewRelic.Profiler.dll" />
        <EnvironmentVariable Name="NEWRELIC_HOME" Value="..\APP_DEPLOYMENT_DIRECTORY\newrelic" />
        <EnvironmentVariable Name="NEW_RELIC_LICENSE_KEY" Value="YOUR_LICENSE_KEY" />
        <EnvironmentVariable Name="NEW_RELIC_APP_NAME" Value="YOUR_APP_NAME" />
        ...
      </EnvironmentVariables>
      ...
    </CodePackage>
  2. Edit your web.config or app.config file and add the NewRelic.AgentEnabled app setting:

    <appSettings>
      ...
      <add key="NewRelic.AgentEnabled" value="true" />
      ...
    </appSettings>
.NET Core app configuration for Windows

The directory name for APP_DEPLOYMENT_DIRECTORY depends on how your application is published to your Service Fabric cluster. It can help to deploy your application and log into the cluster to determine the correct directory name. This directory must resolve to the location your application is deployed to or the agent will not work.

Review the ServiceManifest.xml in your project and include the following changes nested under the CodePackage node, then edit your web.config or app.config file and add the NewRelic.AgentEnabled app setting.

<CodePackage>
  ...
  <EnvironmentVariables>
    ...
    <EnvironmentVariable Name="CORECLR_ENABLE_PROFILING" Value="1" />
    <EnvironmentVariable Name="CORECLR_PROFILER" Value="{36032161-FFC0-4B61-B559-F6C5D41BAE5A}" />
    <EnvironmentVariable Name="CORECLR_PROFILER_PATH" Value="..\APP_DEPLOYMENT_DIRECTORY\newrelic\NewRelic.Profiler.dll" />
    <EnvironmentVariable Name="CORECLR_NEWRELIC_HOME" Value="..\APP_DEPLOYMENT_DIRECTORY\newrelic" />
    <EnvironmentVariable Name="NEW_RELIC_LICENSE_KEY" Value="YOUR_LICENSE_KEY" />
    <EnvironmentVariable Name="NEW_RELIC_APP_NAME" Value="YOUR_APP_NAME" />
    ...
  </EnvironmentVariables>
  ...
</CodePackage>
.NET Core app configuration for Linux

The directory name for APP_DEPLOYMENT_DIRECTORY depends on how your application is published to your Service Fabric cluster. It can help to deploy your application and log into the cluster to determine the correct directory name. This directory must resolve to the location your application is deployed to or the agent will not work.

Review the ServiceManifest.xml in your project and include the following changes nested under the CodePackage node, then edit your web.config or app.config file and add the NewRelic.AgentEnabled app setting.

<CodePackage>
  ...
  <EnvironmentVariables>
    ...
    <EnvironmentVariable Name="CORECLR_ENABLE_PROFILING" Value="1" />
    <EnvironmentVariable Name="CORECLR_PROFILER" Value="{36032161-FFC0-4B61-B559-F6C5D41BAE5A}" />
    <EnvironmentVariable Name="CORECLR_PROFILER_PATH" Value="../APP_DEPLOYMENT_DIRECTORY/newrelic/libNewRelicProfiler.so" />
    <EnvironmentVariable Name="CORECLR_NEWRELIC_HOME" Value="../APP_DEPLOYMENT_DIRECTORY/newrelic" />
    <EnvironmentVariable Name="NEW_RELIC_LICENSE_KEY" Value="YOUR_LICENSE_KEY" />
    <EnvironmentVariable Name="NEW_RELIC_APP_NAME" Value="YOUR_APP_NAME" />
    ...
  </EnvironmentVariables>
  ...
</CodePackage>

View your app's performance

Your application must receive traffic in order for you to view its performance in the New Relic UI. You may need to wait a few minutes for data to start appearing.

To view your app's performance in New Relic APM: Go to rpm.newrelic.com > (select an app). The APM Overview page automatically appears. You can also view detailed information about errors, database and instance performance issues, and more.

Troubleshooting

If no data appears after installing the agent, generating traffic for your app, and waiting a few minutes, try these troubleshooting steps:

  • Make sure that all files in the newrelic directory at the root of your app got published to Azure.
  • Make sure the environment variables are set correctly.

For more help

Recommendations for learning more: