-
Upgrade to 2.7.0. Reduced the telemetry noise. Check out the details in the release notes.
-
Running inside Azure Fucntion? Follow this example.
- Worker service support is in beta testing now.
- Check out the example for package info and the instructions.
Welcome to the home page of Microsoft Application Insights Profiler for ASP.NET Core
. You can find the NuGet packages here.
⚠️ These instructions are for ASP.NET Core applications. For Worker Services, refer to this example.
-
Create a New Application
For example:
dotnet new webapi
-
Add NuGet Packages
dotnet add package Microsoft.ApplicationInsights.AspNetCore dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore
-
Enable Application Insights Profiler
Modify Startup.cs or Program.cs to include:
public void ConfigureServices(IServiceCollection services) { ... // Add Application Insights and Profiler services.AddApplicationInsightsTelemetry(); services.AddServiceProfiler(); }
-
Optionally, Add a Bottleneck
-
Add a reference to
HeavyArrayForcast
, for example, in QuickStart3_1.csproj:<ItemGroup> <ProjectReference Include="..\PerfIssueLib\HeavyArrayForecast\HeavyArrayForecast.csproj" /> </ItemGroup>
-
Use it in WeatherForecastController.cs:
using HeavyArrayForecast; ... [HttpGet] public IEnumerable<WeatherForecast> Get() { return WeatherForecastHelper.GetForecasts(); }
Note: Check WeatherForecastHelper.cs for details on the issue. If you prefer not to use project-to-project references, you can copy the code from this file directly into your project.
-
-
Set Up Connection String:
In appsettings.Development.json, add:
{ ... "ApplicationInsights": { "ConnectionString": "replace-with-your-connection-string" } ... }
-
Run and Profile the Application
Start your application:
dotnet run
The profiler will automatically start for 2 minutes. Access the endpoint during this period:
https://localhost:5001/weatherforecast
-
Analyze Traces in Azure Portal
Wait a few minutes for data ingestion. In the Azure Portal, navigate to your Application Insights resource, go to the Performance blade, and click
Profiler
to view profiling sessions:Tip: Click on a trace to open the trace analyzer.
-
Review Code Optimizations
Once Profiler traces are available in the Azure portal for your application, they are automatically analyzed by an AI-based service known as
Code Optimizations
. This service helps detect and remediate performance bottlenecks at the code level for your running .NET applications. This analysis does not incur any additional overhead on your server or costs to your bill.To review the available Code Optimizations:
- Navigate to the Performance blade.
- You might see the top 3 recommendations in the Insights card.
- Alternatively, click on the Code Optimizations button.
Note that it may take a few hours for Code Optimizations to appear.
For more information, refer to the Code Optimizations Documentation.
- Profiler Configurations - Customize profiler settings.
- Dockerize with Profiler
- Profiler Sessions - Details on profiler operations.
- Trace Analysis - Learn about trace analysis. For example, what does
AWAIT TIME
,Blocked time
,Unmanaged Async
means, etc. - Diagnosing High CPU Usage.
- Call tree filter.
Refer to the Support Matrix to determine the appropriate profiler version.
-
Enable Service Profiler for containerized ASP.NET Core application (.NET Core 3.x).
-
Enable Service Profiler for ASP.NET Core application in Visual Studio.
This is a documentation/sample repository. The LICENSE covers the content in this repository but does NOT cover the use of the product of Microsoft.ApplicationInsights.Profiler.AspNetCore. Please reference EULA-prerelease.md for any prerelease product and EULA-GA.md for any non-prerelease product.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.