Skip to content

Commit

Permalink
[HttpClient and ASP.NET Core] Add note for relying on activity durati…
Browse files Browse the repository at this point in the history
…on for metric data (#4183)

* add note on activity duration

* Update src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs

Co-authored-by: Reiley Yang <reyang@microsoft.com>

* add todo

* re

---------

Co-authored-by: Reiley Yang <reyang@microsoft.com>
  • Loading branch information
vishweshbankwar and reyang committed Feb 14, 2023
1 parent 3ad2830 commit 69d015e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Expand Up @@ -110,6 +110,9 @@ public override void OnEventWritten(string name, object payload)
}
}

// 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);
}
}
Expand Down
Expand Up @@ -62,6 +62,9 @@ public override void OnEventWritten(string name, object payload)
tags.Add(new KeyValuePair<string, object>(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);
}
}
Expand Down

0 comments on commit 69d015e

Please sign in to comment.