Skip to content

Commit 1d7cb4a

Browse files
author
Kai Nawroth
authored
Adding .NET 6 version of enabling AI and Profiler
1 parent 3a17dcd commit 1d7cb4a

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

articles/azure-monitor/profiler/profiler-containers.md

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ In this article, you'll learn the various ways you can:
3333
git clone https://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore.git
3434
```
3535

36-
1. Navigate to the Container App example:
36+
2. Navigate to the Container App example:
3737

3838
```bash
3939
cd examples/EnableServiceProfilerForContainerAppNet6
4040
```
4141

42-
1. This example is a bare bone project created by calling the following CLI command:
42+
3. This example is a bare bone project created by calling the following CLI command:
4343

4444
```powershell
4545
dotnet new mvc -n EnableServiceProfilerForContainerApp
4646
```
4747

4848
We've added delay in the `Controllers/WeatherForecastController.cs` project to simulate the bottleneck.
4949
50-
```CSharp
50+
```csharp
5151
[HttpGet(Name = "GetWeatherForecast")]
5252
public IEnumerable<WeatherForecast> Get()
5353
{
@@ -62,22 +62,40 @@ In this article, you'll learn the various ways you can:
6262
}
6363
```
6464
65-
1. Add the NuGet package to collect the Profiler traces:
65+
4. Add the NuGet package to collect the Profiler traces:
6666
6767
```console
6868
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore
6969
```
7070
71-
1. Enable Application Insights and Profiler in `Startup.cs`:
71+
5. Enable Application Insights and Profiler
72+
73+
### [ASP.NET Core 6 and later](#tab/net-core-new)
74+
75+
Add `builder.Services.AddApplicationInsightsTelemetry()` and `builder.Services.AddServiceProfiler()` after the `WebApplication.CreateBuilder()` method in `Program.cs`:
76+
77+
```csharp
78+
var builder = WebApplication.CreateBuilder(args);
79+
80+
builder.Services.AddApplicationInsightsTelemetry(); // Add this line of code to enable Application Insights.
81+
builder.Services.AddServiceProfiler(); // Add this line of code to enable Profiler
82+
builder.Services.AddControllersWithViews();
83+
84+
var app = builder.Build();
85+
```
86+
87+
### [ASP.NET Core 5 and earlier](#tab/net-core-old)
88+
89+
Add `services.AddApplicationInsightsTelemetry()` and `services.AddServiceProfiler()` to the `ConfigureServices()` method in `Startup.cs`:
7290
73-
```csharp
74-
public void ConfigureServices(IServiceCollection services)
75-
{
76-
services.AddApplicationInsightsTelemetry(); // Add this line of code to enable Application Insights.
77-
services.AddServiceProfiler(); // Add this line of code to Enable Profiler
78-
services.AddControllersWithViews();
79-
}
80-
```
91+
```csharp
92+
public void ConfigureServices(IServiceCollection services)
93+
{
94+
services.AddApplicationInsightsTelemetry(); // Add this line of code to enable Application Insights.
95+
services.AddServiceProfiler(); // Add this line of code to enable Profiler
96+
services.AddControllersWithViews();
97+
}
98+
```
8199
82100
## Pull the latest ASP.NET Core build/runtime images
83101
@@ -87,7 +105,7 @@ In this article, you'll learn the various ways you can:
87105
cd examples/EnableServiceProfilerForContainerAppNet6
88106
```
89107
90-
1. Pull the latest ASP.NET Core images
108+
2. Pull the latest ASP.NET Core images
91109
92110
```shell
93111
docker pull mcr.microsoft.com/dotnet/sdk:6.0
@@ -103,7 +121,7 @@ In this article, you'll learn the various ways you can:
103121
104122
:::image type="content" source="./media/profiler-containerinstances/application-insights-key.png" alt-text="Screenshot of finding instrumentation key in Azure portal.":::
105123
106-
1. Open `appsettings.json` and add your Application Insights instrumentation key to this code section:
124+
2. Open `appsettings.json` and add your Application Insights instrumentation key to this code section:
107125
108126
```json
109127
{
@@ -118,13 +136,13 @@ In this article, you'll learn the various ways you can:
118136
119137
1. Review the `Dockerfile`.
120138
121-
1. Build the example image:
139+
2. Build the example image:
122140
123141
```bash
124142
docker build -t profilerapp .
125143
```
126144
127-
1. Run the container:
145+
3. Run the container:
128146
129147
```bash
130148
docker run -d -p 8080:80 --name testapp profilerapp
@@ -162,8 +180,8 @@ Service Profiler session finished. # A profiling session is complet
162180
## View the Service Profiler traces
163181
164182
1. Wait for 2-5 minutes so the events can be aggregated to Application Insights.
165-
1. Open the **Performance** blade in your Application Insights resource.
166-
1. Once the trace process is complete, you'll see the Profiler Traces button like it below:
183+
2. Open the **Performance** blade in your Application Insights resource.
184+
3. Once the trace process is complete, you'll see the Profiler Traces button like it below:
167185

168186
:::image type="content" source="./media/profiler-containerinstances/profiler-traces.png" alt-text="Screenshot of Profile traces in the performance blade.":::
169187

0 commit comments

Comments
 (0)