Skip to content

Commit

Permalink
activity duration or stopwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-hensley committed Sep 18, 2023
1 parent bed7b2b commit 48c354a
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,24 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC

if (HttpClientDuration.Enabled)
{
double duration = 0;

if (activity != null)
{
duration = activity.Duration.TotalMilliseconds;
}
else
{
var endTimestamp = Stopwatch.GetTimestamp();
var durationS = (endTimestamp - startTimestamp) / Stopwatch.Frequency;
var durationMs = durationS * 1000;
duration = durationMs;
}

if (httpStatusCode.HasValue)
{
HttpClientDuration.Record(
activity.Duration.TotalMilliseconds,
duration,
new(SemanticConventions.AttributeHttpFlavor, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.ProtocolVersion)),
new(SemanticConventions.AttributeHttpMethod, request.Method),
new(SemanticConventions.AttributeHttpScheme, request.RequestUri.Scheme),
Expand All @@ -419,7 +433,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
else
{
HttpClientDuration.Record(
activity.Duration.TotalMilliseconds,
duration,
new(SemanticConventions.AttributeHttpFlavor, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.ProtocolVersion)),
new(SemanticConventions.AttributeHttpMethod, request.Method),
new(SemanticConventions.AttributeHttpScheme, request.RequestUri.Scheme),
Expand Down

0 comments on commit 48c354a

Please sign in to comment.