Skip to content

Commit

Permalink
chore(send operation): print correlation ID in error & success messag…
Browse files Browse the repository at this point in the history
…es (#3583)
  • Loading branch information
iainsproat authored Jul 23, 2024
1 parent 8c32ad4 commit 885a05b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Core/Core/Api/Operations/Operations.Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ public static async Task<string> Send(

var transportContext = transports.ToDictionary(t => t.TransportName, t => t.TransportContext);

var correlationId = Guid.NewGuid().ToString();

// make sure all logs in the operation have the proper context
using (LogContext.PushProperty("transportContext", transportContext))
using (LogContext.PushProperty("correlationId", Guid.NewGuid().ToString()))
using (LogContext.PushProperty("correlationId", correlationId))
{
var sendTimer = Stopwatch.StartNew();
SpeckleLog.Logger.Information("Starting send operation");
Expand All @@ -110,8 +112,9 @@ public static async Task<string> Send(
{
SpeckleLog.Logger.Information(
ex,
"Send operation failed after {elapsed} seconds",
sendTimer.Elapsed.TotalSeconds
"Send operation failed after {elapsed} seconds. Correlation ID: {correlationId}",
sendTimer.Elapsed.TotalSeconds,
correlationId
);
if (ex is OperationCanceledException or SpeckleException)
{
Expand All @@ -134,10 +137,11 @@ public static async Task<string> Send(
.ForContext("note", "the elapsed summary doesn't need to add up to the total elapsed... Threading magic...")
.ForContext("serializerElapsed", serializerV2.Elapsed)
.Information(
"Finished sending {objectCount} objects after {elapsed}, result {objectId}",
"Finished sending {objectCount} objects after {elapsed}, result: {objectId}. Correlation ID: {correlationId}",
transports.Max(t => t.SavedObjectCount),
sendTimer.Elapsed.TotalSeconds,
hash
hash,
correlationId
);
return hash;
}
Expand Down

0 comments on commit 885a05b

Please sign in to comment.