Skip to content

Commit

Permalink
Update Http Send trace (#118)
Browse files Browse the repository at this point in the history
* Update Http Send trace

* format
  • Loading branch information
adamhathcock authored Sep 16, 2024
1 parent 56c4109 commit bbe23f6
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/Speckle.Sdk/Helpers/SpeckleHttpClientHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using Polly;
using Speckle.Sdk.Common;
using Speckle.Sdk.Logging;
Expand All @@ -24,16 +24,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,18 +46,13 @@ CancellationToken cancellationToken
.ConfigureAwait(false);
context.TryGetValue("retryCount", out var retryCount);
activity?.SetTag("retryCount", retryCount);

SpeckleLog.Logger.Information(
"Execution of http request to {httpScheme}://{hostUrl}{relativeUrl} {resultStatus} with {httpStatusCode} after {elapsed} seconds and {retryCount} retries. Request correlation ID: {correlationId}",
request.RequestUri.Scheme,
request.RequestUri.Host,
request.RequestUri.PathAndQuery,
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 bbe23f6

Please sign in to comment.