-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vishwesh Bankwar
committed
Dec 12, 2023
1 parent
b6baffc
commit f28654f
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/OpenTelemetry.Instrumentation.Http/HttpClientMeterProviderBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#if !NET8_0_OR_GREATER | ||
#if !NETFRAMEWORK | ||
using OpenTelemetry.Instrumentation.Http; | ||
#endif | ||
using OpenTelemetry.Instrumentation.Http.Implementation; | ||
#endif | ||
|
||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Metrics; | ||
|
||
/// <summary> | ||
/// Extension methods to simplify registering of HttpClient instrumentation. | ||
/// </summary> | ||
public static class HttpClientMeterProviderBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Enables HttpClient instrumentation. | ||
/// </summary> | ||
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param> | ||
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns> | ||
public static MeterProviderBuilder AddHttpClientInstrumentation( | ||
this MeterProviderBuilder builder) | ||
{ | ||
Guard.ThrowIfNull(builder); | ||
|
||
#if NET8_0_OR_GREATER | ||
return builder | ||
.AddMeter("System.Net.Http") | ||
.AddMeter("System.Net.NameResolution"); | ||
#else | ||
// Note: Warm-up the status code and method mapping. | ||
_ = TelemetryHelper.BoxedStatusCodes; | ||
_ = RequestMethodHelper.KnownMethods; | ||
|
||
#if NETFRAMEWORK | ||
builder.AddMeter(HttpWebRequestActivitySource.MeterName); | ||
#else | ||
builder.AddMeter(HttpHandlerMetricsDiagnosticListener.MeterName); | ||
|
||
builder.AddInstrumentation(new HttpClientMetrics()); | ||
#endif | ||
return builder; | ||
#endif | ||
} | ||
} |