Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .NET8.0 HttpClient metrics #4931

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@
`http.client.request.duration` metrics on .NET Framework for `HttpWebRequest`.
([#4870](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4870))

* Following `HttpClient` metrics will now be enabled by default when targeting
`.NET8.0` framework.
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved

* **Meter** : `System.Net.Http`
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
* `http.client.request.duration`
* `http.client.active_requests`
* `http.client.open_connections`
* `http.client.connection.duration`
* `http.client.request.time_in_queue`

* **Meter** : `System.Net.NameResolution`
* `dns.lookup.duration`

**NOTE**: Users can opt-out of metrics that are not required using
[views](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/metrics/customizing-the-sdk#view).
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
[#4931](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4931)

## 1.5.1-beta.1

Released 2023-Jul-20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation;
internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler
{
internal const string OnStopEvent = "System.Net.Http.HttpRequestOut.Stop";
internal static readonly bool IsNet8OrGreater;

internal static readonly AssemblyName AssemblyName = typeof(HttpClientMetrics).Assembly.GetName();
internal static readonly string MeterName = AssemblyName.Name;
Expand All @@ -45,6 +46,18 @@ internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler
private readonly bool emitOldAttributes;
private readonly bool emitNewAttributes;

static HttpHandlerMetricsDiagnosticListener()
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
IsNet8OrGreater = typeof(HttpClient).Assembly.GetName().Version.Major >= 8;
}
catch (Exception)
{
IsNet8OrGreater = false;
}
}

public HttpHandlerMetricsDiagnosticListener(string name, HttpClientMetricInstrumentationOptions options)
: base(name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ public static MeterProviderBuilder AddHttpClientInstrumentation(
});
}
#else
builder.AddMeter(HttpHandlerMetricsDiagnosticListener.MeterName);
if (HttpHandlerMetricsDiagnosticListener.IsNet8OrGreater)
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
{
builder.AddMeter("System.Net.Http");
builder.AddMeter("System.Net.NameResolution");
}
else
{
builder.AddMeter(HttpHandlerMetricsDiagnosticListener.MeterName);

builder.AddInstrumentation(sp => new HttpClientMetrics(
sp.GetRequiredService<IOptionsMonitor<HttpClientMetricInstrumentationOptions>>().Get(Options.DefaultName)));
builder.AddInstrumentation(sp => new HttpClientMetrics(
sp.GetRequiredService<IOptionsMonitor<HttpClientMetricInstrumentationOptions>>().Get(Options.DefaultName)));
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
}
#endif
return builder;
}
Expand Down
Loading