Skip to content

Commit

Permalink
Merge pull request #119 from specklesystems/jrm/main-merge
Browse files Browse the repository at this point in the history
Update Http Send trace (#118)
  • Loading branch information
JR-Morgan authored Sep 16, 2024
2 parents df5b151 + 2cb5d6e commit a28cf6d
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/Speckle.Sdk/Helpers/SpeckleHttpClientHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics;
using Polly;
using Speckle.Sdk.Common;
using Speckle.Sdk.Logging;
Expand All @@ -24,16 +23,10 @@ CancellationToken cancellationToken
{
// this is a preliminary client server correlation implementation
// refactor this, when we have a better observability stack
var sw = Stopwatch.StartNew();
var context = new Context();
using var activity = SpeckleActivityFactory.Start("Http Send");
using var activity = SpeckleActivityFactory.Start("Http Request");
{
SpeckleLog.Logger.Debug(
"Starting execution of http request to {targetUrl} {correlationId} {traceId}",
request.RequestUri,
context.CorrelationId,
activity?.TraceId
);
activity?.SetTag("http.method", request.Method);
activity?.SetTag("http.url", request.RequestUri);
activity?.SetTag("correlationId", context.CorrelationId);

Expand All @@ -52,16 +45,13 @@ CancellationToken cancellationToken
.ConfigureAwait(false);
context.TryGetValue("retryCount", out var retryCount);
activity?.SetTag("retryCount", retryCount);

SpeckleLog.Logger.Information(
"Execution of http request to {url} {resultStatus} with {httpStatusCode} after {elapsed} seconds and {retryCount} retries. Request correlation ID: {correlationId}",
request.RequestUri,
policyResult.Outcome == OutcomeType.Successful ? "succeeded" : "failed",
policyResult.Result?.StatusCode,
sw.Elapsed.TotalSeconds,
retryCount ?? 0,
context.CorrelationId.ToString()
activity?.SetStatus(
policyResult.Result.IsSuccessStatusCode ? SpeckleActivityStatusCode.Ok : SpeckleActivityStatusCode.Error
);
if (policyResult.FinalException != null)
{
activity?.RecordException(policyResult.FinalException);
}

if (policyResult.Outcome == OutcomeType.Successful)
{
Expand Down

0 comments on commit a28cf6d

Please sign in to comment.