Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
By using Application Insights Profiler for .NET, you can track how much time is spent in each method of your live ASP.NET Core web apps. This article focuses on web apps hosted in Linux. You can also experiment by using Windows and Mac development environments.
In this article, you:
- Set up an ASP.NET Core web application hosted on Linux on your local computer.
- Create an App Service using the Azure portal.
- Deploy your local ASP.NET Core project to Azure using local Git.
- Add the Profiler to the ASP.NET Core web application.
Note
Review the Application Insights SDK support guidance for the Classic API SDK support policy.
Caution
For new applications, use the Azure Monitor OpenTelemetry Distro. It provides a similar experience and comparable functionality to the Application Insights SDK. To migrate to an OpenTelemetry based offering, review the migration guidance.
Prerequisites
- Install the latest .NET Core SDK.
- Install Git by following the instructions at Getting started: Installing Git.
- Review the Enable Azure Monitor Profiler for an ASP.NET Core Web API sample for context.
Set up the project locally
Open a command prompt window on your computer.
Create an ASP.NET Core MVC web application:
dotnet new mvc -n LinuxProfilerTestChange the working directory to the root folder for the project.
Add the NuGet packages to collect the Profiler traces:
dotnet add package Azure.Monitor.OpenTelemetry.AspNetCore --prerelease dotnet add package Azure.Monitor.OpenTelemetry.Profiler --prerelease
Enable the .NET Profiler
In your preferred code editor, verify that you added the two packages for the Azure Monitor OpenTelemetry Profiler for .NET to
Program.cs. Add custom Profiler settings, if applicable.In your project's
.csprojfile, verify that you added the following lines:<ItemGroup> <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="[1.*-*, 2.0.0)" /> <PackageReference Include="Azure.Monitor.OpenTelemetry.Profiler" Version="[1.*-*, 2.0.0)" /> </ItemGroup>In your
Program.csfile, verify that you added the following lines:using Azure.Monitor.OpenTelemetry.AspNetCore; using Azure.Monitor.OpenTelemetry.Profiler; /// builder.Services.AddOpenTelemetry() .UseAzureMonitor() // Enable Azure Monitor OpenTelemetry distro for ASP.NET Core .AddAzureMonitorProfiler(); // Add Azure Monitor ProfilerSave 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
In the Azure portal, search for and select App Services, and then select Create > Web App.
Create a web app environment by using App Service on Linux.
Go to your new web app resource. In the left menu, select Deployment > Deployment Center, and then select FTPS Credentials to create the deployment credentials. Make a note of your credentials to use later.
Select Save.
Select the Settings tab.
To set up a local Git repository in the web app, select Source, and then select Local Git.
Select Save to create a Git repository with a Git clone URI.
For more deployment options, see the App Service documentation.
Deploy your project
You can deploy code to Azure App Service in various ways. The simplest way is to deploy by using local Git. For more information, see Deploy to Azure App Service by using local Git.
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>.gitFor this value, go to the Overview page for your web app. Copy Git clone url.
Deploy the project by pushing the changes to Azure:
git push azure main
Add Application Insights to monitor your web app
You can enable Application Insights while creating an App Service, which sets the connection string automatically.
Copy and paste your connection string from your Application Insights resource to monitor your web app.
Troubleshooting
If you can't find traces from your app, try the steps in this troubleshooting guide.
If you are unable to find traces from your app, consider following the steps in this troubleshooting guide.