Skip to content

Commit 66dd162

Browse files
committed
using code snippets for samples
1 parent ad8ba09 commit 66dd162

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

docs/core/extensions/httpclient-latency-extensions.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,7 @@ For more information, see [dotnet package add](../tools/dotnet-package-add.md) o
9191

9292
To add HTTP client latency telemetry to your application, call the <xref:Microsoft.Extensions.DependencyInjection.HttpClientLatencyTelemetryExtensions.AddHttpClientLatencyTelemetry*> extension method when configuring your services:
9393

94-
```csharp
95-
using Microsoft.Extensions.DependencyInjection;
96-
97-
var builder = WebApplication.CreateBuilder(args);
98-
99-
// Add HTTP client factory
100-
builder.Services.AddHttpClient();
101-
102-
// Add HTTP client latency telemetry
103-
builder.Services.AddHttpClientLatencyTelemetry();
104-
```
94+
:::code language="csharp" source="snippets/http/latency/Program.Extensions.cs" id="extensions":::
10595

10696
This registration adds a `DelegatingHandler` to all HTTP clients created through <xref:System.Net.Http.IHttpClientFactory>, collecting detailed latency information for each request.
10797

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Http.Diagnostics;
4+
5+
6+
internal partial class Program
7+
{
8+
private static void ConfigureHttpClientLatency(HostApplicationBuilder builder)
9+
{
10+
// <extensions>
11+
var builder = WebApplication.CreateBuilder(args);
12+
13+
// Add HTTP client factory
14+
builder.Services.AddHttpClient();
15+
16+
// Add HTTP client latency telemetry
17+
builder.Services.AddHttpClientLatencyTelemetry();
18+
// </extensions>
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>true</ImplicitUsings>
7+
<OutputType>Exe</OutputType>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Remove="appsettings.json" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Content Include="appsettings.json">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</Content>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.Extensions.Http.Diagnostics" Version="9.10.0" />
22+
</ItemGroup>
23+
24+
</Project>

0 commit comments

Comments
 (0)