From 69d015eb705c94b49079516c866fbed53da6b046 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 14 Feb 2023 10:57:49 -0800 Subject: [PATCH] [HttpClient and ASP.NET Core] Add note for relying on activity duration for metric data (#4183) * add note on activity duration * Update src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs Co-authored-by: Reiley Yang * add todo * re --------- Co-authored-by: Reiley Yang --- .../Implementation/HttpInMetricsListener.cs | 3 +++ .../Implementation/HttpHandlerMetricsDiagnosticListener.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs index 52699a12a..cd9ec3c7b 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs @@ -110,6 +110,9 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation } } + // We are relying here on ASP.NET Core to set duration before writing the stop event. + // https://github.com/dotnet/aspnetcore/blob/d6fa351048617ae1c8b47493ba1abbe94c3a24cf/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L449 + // TODO: Follow up with .NET team if we can continue to rely on this behavior. this.httpServerDuration.Record(Activity.Current.Duration.TotalMilliseconds, tags); } } diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs index 124e4351d..d8306a843 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs @@ -62,6 +62,9 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation tags.Add(new KeyValuePair(SemanticConventions.AttributeNetPeerPort, request.RequestUri.Port)); } + // We are relying here on HttpClient library to set duration before writing the stop event. + // https://github.com/dotnet/runtime/blob/90603686d314147017c8bbe1fa8965776ce607d0/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L178 + // TODO: Follow up with .NET team if we can continue to rely on this behavior. this.httpClientDuration.Record(activity.Duration.TotalMilliseconds, tags); } }