Редактиране

Споделяне чрез


Enable the .NET Profiler for Azure App Service apps

Application Insights Profiler for .NET is preinstalled as part of the Azure App Service runtime. You can run Profiler on ASP.NET and ASP.NET Core apps running on App Service by using the Basic service tier or higher.

Codeless installation of Application Insights Profiler for .NET:

To enable .NET Profiler on Linux, walk through the ASP.NET Core Azure Linux web apps instructions.

Prerequisites

Verify the "Always on" setting is enabled

  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 pane.

  3. Select the General settings tab.

  4. Verify that Always on > On is selected.

    Note

    If the Always on toggle 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

You can enable Profiler either when:

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, select Monitoring > Application Insights.

  2. Under Application Insights, select Enable.

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

    Screenshot that shows enabling Application Insights on your app.

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

  5. Verify that Collection level > Recommended is selected.

  6. Under Profiler, select On.

    If you chose the Basic collection level earlier, the Profiler setting is disabled.

  7. Select Apply > Yes to confirm.

    Screenshot that shows enabling Profiler on your app.

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 by creating app settings for your App Service instance. You can automate the creation of these settings by using a template or other means. Here are the settings you need to enable Profiler.

App setting Value
APPINSIGHTS_INSTRUMENTATIONKEY iKey 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 only regions that require endpoint modifications are Azure Government and Microsoft Azure operated by 21Vianet.

App setting US Government Cloud China Cloud
ApplicationInsightsProfilerEndpoint https://profiler.monitor.azure.us https://profiler.monitor.azure.cn
ApplicationInsightsEndpoint https://dc.applicationinsights.us https://dc.applicationinsights.azure.cn

Enable Microsoft Entra authentication for profile ingestion

Application Insights Profiler for .NET supports Microsoft Entra authentication for profile ingestion. For all profiles of your application to be ingested, your application must be authenticated and provide the required application settings to the Profiler agent.

Profiler only supports Microsoft Entra authentication when you reference and configure Microsoft Entra ID by using the Application Insights SDK in your application.

To enable Microsoft Entra ID for profile ingestion:

  1. Create and add the managed identity to authenticate against your Application Insights resource to your App Service:

    1. System-assigned managed identity documentation

    2. User-assigned managed identity documentation

  2. Configure and enable Microsoft Entra ID in your Application Insights resource.

  3. Add the following application setting to let the Profiler agent know which managed identity to use.

    • For system-assigned identity:

      App setting Value
      APPLICATIONINSIGHTS_AUTHENTICATION_STRING Authorization=AAD
    • For user-assigned identity:

      App setting Value
      APPLICATIONINSIGHTS_AUTHENTICATION_STRING Authorization=AAD;ClientId={Client id of the User-Assigned Identity}

Disable the .NET Profiler

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

  1. Under Settings on the left pane, select WebJobs.

    Screenshot that shows selecting web jobs on the left pane.

  2. Select the webjob named ApplicationInsightsProfiler3.

  3. Select Stop.

    Screenshot that shows selecting stop for stopping the webjob.

  4. Select Yes to confirm.

We recommend that you have Profiler enabled on all your apps to discover any performance issues as early as possible.

You can delete Profiler's files when you use WebDeploy to deploy changes to your web application. You can prevent the deletion by excluding the App_Data folder from being deleted during deployment.

Next steps