Enable the .NET Profiler for Azure App Service apps in Windows

Application Insights Profiler for .NET captures traces of your live app to show which requests are slow and which lines of code cause the slowdown. When your app runs slower than expected in production, Profiler helps you find the bottleneck instead of guessing.

Profiler is preinstalled as part of the Azure App Service runtime. This article shows you how to enable it for ASP.NET and ASP.NET Core apps that run on App Service by using the Basic service tier or higher.

Codeless installation of Application Insights Profiler for .NET follows the .NET Core support policy. Azure supports it only on Windows-based web apps. To enable .NET Profiler on Linux, see Enable the .NET Profiler for Azure App Service apps in Linux.

Prerequisites

Verify the "Always on" setting is enabled

Profiler runs as a continuous WebJob, so your app must keep running even when it's idle. Verify that the Always On setting is enabled before you enable Profiler.

  1. In the Azure portal, go to your App Service instance.

  2. In the left menu, select Settings > Configuration.

    Screenshot that shows selecting Configuration on the left menu.

  3. Select General settings.

  4. Verify that Always on is set to On.

    Note

    If Always On is disabled, upgrade your App Service web app to run on Basic tier or higher.

    Screenshot that shows the General tab on the Configuration pane showing that Always On is enabled.

  5. Select Save if you made changes.

Enable Application Insights and the .NET Profiler

Enable Profiler in either of these scenarios:

For Application Insights and App Service in the same subscription

If your Application Insights resource is in the same subscription as your instance of App Service:

  1. In the left menu of your App Service instance, select Monitoring > Application Insights.

  2. Select Turn on Application Insights.

    Screenshot that shows turning on Application Insights for your app.

  3. In the Application Insights setting page, under Application Insights, select Enable.

  4. Verify that you connected an Application Insights resource to your app.

    Screenshot that shows enabling Application Insights on your app.

  5. Scroll down and select the .NET or .NET Core tab, depending on your app.

  6. For Collection level, select Recommended.

  7. Under Profiler and Code Optimizations, select On. If you chose the Basic collection level earlier, the Profiler setting is disabled.

    Screenshot that shows enabling Profiler on your app.

  8. Select Apply, and then Yes to confirm.

For Application Insights and App Service in different subscriptions

If your Application Insights resource is in a different subscription from your instance of App Service, you need to enable the Profiler for .NET manually. Enable it by creating app settings for your App Service instance. You can automate creating these settings by using a template or other means. Here are the settings you need to enable Profiler.

App setting Value
APPLICATIONINSIGHTS_CONNECTION_STRING Get this value from the Overview page for your Application Insights resource.
APPINSIGHTS_PROFILERFEATURE_VERSION 1.0.0
DiagnosticServices_EXTENSION_VERSION ~3

Set these values by using:

Enable .NET Profiler for regional clouds

Currently the regions in Azure operated by 21Vianet require endpoint modifications.

App setting Azure operated by 21Vianet
ApplicationInsightsProfilerEndpoint https://profiler.monitor.azure.cn
ApplicationInsightsEndpoint https://dc.applicationinsights.azure.cn

Disable the .NET Profiler

To stop or restart Profiler for an individual app's instance:

  1. In the Azure portal, go to your App Service instance.

  2. Under Settings on the left menu, select WebJobs.

    Screenshot that shows selecting web jobs on the left menu.

  3. Select the WebJob named ApplicationInsightsProfiler3.

  4. Select the Stop icon.

    Screenshot that shows selecting stop for stopping the webjob.

  5. Select Stop to confirm.

Keep Profiler enabled on all your apps to discover any performance issues as early as possible.

Prevent Profiler files from being deleted during Web Deploy

When you use Web Deploy to deploy changes to your web application, the deployment can delete Profiler's files. To prevent the deletion, exclude the App_Data folder from deletion during deployment.