-
Notifications
You must be signed in to change notification settings - Fork 8
Enable with Azure Monitor OpenTelemetry Distro
This is the most common setup: you already call UseAzureMonitor() from the
Azure Monitor OpenTelemetry distro
(Azure.Monitor.OpenTelemetry.AspNetCore), and you want to add the profiler to
it.
In addition to the Get Started prerequisites: this profiler works with the Azure Monitor OpenTelemetry distro.
Assuming you are building an ASP.NET Core application:
-
Create a .NET Application (skip if you have one already)
dotnet new web
-
Add NuGet Packages
dotnet add package Azure.Monitor.OpenTelemetry.AspNetCore --prerelease dotnet add package Azure.Monitor.OpenTelemetry.Profiler --prerelease
Tip: use floating versions to stay on the latest package:
<ItemGroup> <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="[1.*-*, 2.0.0)" /> <PackageReference Include="Azure.Monitor.OpenTelemetry.Profiler" Version="[1.*-*, 2.0.0)" /> </ItemGroup>
-
Enable Application Insights with OpenTelemetry
Follow the instructions to enable Azure Monitor OpenTelemetry for .NET, then verify that data is flowing.
-
Enable Profiler
Append the call to
AddAzureMonitorProfiler()in your code:using Azure.Monitor.OpenTelemetry.AspNetCore; // Import the Azure.Monitor.OpenTelemetry.Profiler namespace. using Azure.Monitor.OpenTelemetry.Profiler; ... builder.Services.AddOpenTelemetry() .UseAzureMonitor() .AddAzureMonitorProfiler(); // Add Azure Monitor Profiler ...
-
Run Your Application
Run your application and verify the profiler starts. Look for this in the log output:
info: Azure.Monitor.OpenTelemetry.Profiler.ServiceProfilerAgentBootstrap[0] Starting application insights profiler with connection string: InstrumentationKey=5d… info: Azure.Monitor.OpenTelemetry.Profiler.Core.DumbTraceControl[0] Start writing trace file C:\Users\aaa\AppData\Local\Temp\SPTraces\... -
View Profiler Data
After a few minutes, profiler traces will appear in Application Insights. Follow these instructions to view them.
📖 Full example: aspnetcore-webapi
-
Enable the profiler with a manual OpenTelemetry setup
— when you do not call
UseAzureMonitor(). - Enable the profiler with the Application Insights SDK
- Service Profiler Configuration Guide