Skip to content

Latest commit

 

History

History
174 lines (118 loc) · 7.57 KB

app-insights-profiler-aspnetcore-linux.md

File metadata and controls

174 lines (118 loc) · 7.57 KB
title description services documentationcenter author manager ms.service ms.workload ms.tgt_pltfrm ms.topic ms.date ms.author
Profile ASP.NET Core Azure Linux web apps with Application Insights Profiler | Microsoft Docs
A conceptual overview and step-by-step tutorial on how to use Application Insights Profiler.
application-insights
mrbullwinkle
carmonm
application-insights
tbd
ibiza
conceptual
02/23/2018
mbullwin

Profile ASP.NET Core Azure Linux web apps with Application Insights Profiler

This feature is currently in preview.

Find out how much time is spent in each method of your live web application when using Application Insights. Application Insights Profiler is now available for ASP.NET Core web apps that are hosted in Linux on Azure App Service. This guide provides step-by-step instructions on how the Profiler traces can be collected for ASP.NET Core Linux web apps.

After you complete this walkthrough, your app can collect Profiler traces like the traces that are shown in the image. In this example, the Profiler trace indicates that a particular web request is slow because of time spent waiting. The hot path in the code that's slowing the app is marked by a flame icon. The About method in the HomeController section is slowing the web app because the method is calling the Thread.Sleep function.

Profiler traces

Prerequisites

The following instructions apply to all Windows, Linux, and Mac development environments:

Set up the project locally

  1. Open a Command Prompt window on your machine. The following instructions work for all Windows, Linux, and Mac development environments.

  2. Create an ASP.NET Core MVC web application:

    dotnet new mvc -n LinuxProfilerTest
    
  3. Change the working directory to the root folder for the project.

  4. Add the NuGet package to collect the Profiler traces:

    dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore
    
  5. Add a line of code in the HomeController.cs section to randomly delay a few seconds:

        using System.Threading;
        ...
    
        public IActionResult About()
            {
                Random r = new Random();
                int delay = r.Next(5000, 10000);
                Thread.Sleep(delay);
                return View();
            }
  6. Save and commit your changes to the local repository:

        git init
        git add .
        git commit -m "first commit"
    

Create the Linux web app to host your project

  1. Create the web app environment by using App Service on Linux:

    Create the Linux web app

  2. Create the deployment credentials:

    [!NOTE] Record your password to use later when deploying your web app.

    Create the deployment credentials

  3. Choose the deployment options. Set up a local Git repository in the web app by following the instructions on the Azure portal. A Git repository is automatically created.

    Set up the Git repository

For more deployment options, see this article.

Deploy your project

  1. In your Command Prompt window, browse to the root folder for your project. Add a Git remote repository to point to the repository on App Service:

    git remote add azure https://<username>@<app_name>.scm.azurewebsites.net:443/<app_name>.git
    
    • Use the username that you used to create the deployment credentials.
    • Use the app name that you used to create the web app by using App Service on Linux.
  2. Deploy the project by pushing the changes to Azure:

    git push azure master
    

You should see output similar to the following example:

```
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 1.78 KiB | 911.00 KiB/s, done.
Total 9 (delta 3), reused 0 (delta 0)
remote: Updating branch 'master'.
remote: Updating submodules.
remote: Preparing deployment for commit id 'd7369a99d7'.
remote: Generating deployment script.
remote: Running deployment command...
remote: Handling ASP.NET Core Web Application deployment.
remote: ......
remote:   Restoring packages for /home/site/repository/EventPipeExampleLinux.csproj...
remote: .
remote:   Installing Newtonsoft.Json 10.0.3.
remote:   Installing Microsoft.ApplicationInsights.Profiler.Core 1.1.0-LKG
…

```

Add Application Insights to monitor your web apps

  1. Create an Application Insights resource.

  2. Copy the iKey value of the Application Insights resource and set the following settings in your web apps:

    APPINSIGHTS_INSTRUMENTATIONKEY: [YOUR_APPINSIGHTS_KEY]
    ASPNETCORE_HOSTINGSTARTUPASSEMBLIES: Microsoft.ApplicationInsights.Profiler.AspNetCore
    

    Configure the app settings

    When the app settings are changed, the site automatically restarts. After the new settings are applied, the Profiler immediately runs for two minutes. The Profiler then runs for two minutes every hour.

  3. Generate some traffic to your website. You can generate traffic by refreshing the site About page a few times.

  4. Wait two to five minutes for the events to aggregate to Application Insights.

  5. Browse to the Application Insights Performance pane in the Azure portal. You can view the Profiler traces at the bottom right of the pane.

    View Profiler traces

Known issues

The Enable action in the Profiler Configuration pane doesn't work

Note

If you host your app by using App Service on Linux, you don't need to re-enable the Profiler in the Performance pane in the Application Insights portal. You can include the NuGet package in your project and set the Application Insights iKey value in your web app settings to enable the Profiler.

If you follow the enablement workflow for Application Insights Profiler for Windows and select Enable in the Configure Profiler pane, you receive an error. The enable action tries to install the Windows version of the Profiler agent on the Linux environment.

We're working on a resolution for this issue.

Don't try to re-enable the Profiler in the Performance pane

Next steps

If you use custom containers that are hosted by Azure App Service, follow the instructions in Enable Service Profiler for a containerized ASP.NET Core application to enable Application Insights Profiler.

Report any issues or suggestions to the Application Insights GitHub repository: ApplicationInsights-Profiler-AspNetCore: Issues.