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. Profiler is now available for ASP.NET core web apps hosted in Linux on App Services. This guide provides step-by-step instruction on how profiler traces can be collected for ASP.NET core Linux web apps.
After completing this walkthrough, your app will collect profiler traces similar to the screenshot below. In this example, the profiler trace indicates a particular web request is slow because most time is spent on waiting. The hot path in the code that slowed down the app is preceded by the flame icon. This example shows
About method in
HomeController slowed down the web app because it was calling
Instructions below applied to all of Windows, Linux, and Mac development environments:
Setup project locally
Open a command prompt on your machine. The instructions below works for all of Windows, Linux, and Mac development environments.
Create an ASP.NET core MVC web application
dotnet new mvc -n LinuxProfilerTest
Change directory in command prompt to the project root folder
Add Nuget package for collecting profiler traces.
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore
Add a line of code to randomly delay a few seconds in HomeController.cs
using System.Threading; ... public IActionResult About() Random r = new Random(); int delay = r.Next(5000, 10000); Thread.Sleep(delay); return View();
Save and commit your changes to the local repository
git init git add . git commit -m "first commit"
Create Azure App Service for hosting your project
Create an App Services Linux environment
Create deployment credential. Take a note of your password as you will need this later when deploying your app.
Choose deployment option. Set up a local Git repository in the web app following instructions on Azure portal. A Git repository will automatically be created.
More deployment options are available here
Deploy your project
In your Command prompt, navigate to your project root folder. Add Git remote repository to point to the one on App Services:
git remote add azure https://<username>@<app_name>.scm.azurewebsites.net:443/<app_name>.git
- Use the ‘username’ from the step of “create deployment credential.”
- Use the ‘app name’ from the step of “create app service.”
Deploy the project by pushing the changes to Azure
git push azure master
You will see output similar to the following:
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
- Create an Application Insights resource
Copy the iKey of the Application Insights resource and set the following settings in your App services
APPINSIGHTS_INSTRUMENTATIONKEY: [YOUR_APPINSIGHTS_KEY] ASPNETCORE_HOSTINGSTARTUPASSEMBLIES: Microsoft.ApplicationInsights.Profiler.AspNetCore
Changing app settings will automatically restart the site. Once the new settings are applied, the profiler will start to run for 2 minutes immediately. then it will run for 2 minutes every hour.
Generate some traffic to your website. You can refresh the site
Aboutpage for a few times.
Wait for 2-5 minutes so the events can be aggregated to Application Insights.
Navigate to Application Insights performance pane in Azure portal. You will see profiler traces available in the bottom right corner.
If you are using custom containers hosted by App Services, follow instructions from
Enable Service Profiler for containerized ASP.NET Core application to enable App Insights Profiler
If you have any issues or suggestions, please report to our github repository: