Skip to content

Commit

Permalink
Log work item start/end/exception using current's scope logger (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Jan 6, 2025
1 parent 76baee7 commit ec58592
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@ async Task ProcessWorkItemAsync()
using (var operation = telemetryClient.StartOperation<RequestTelemetry>(type))
using (logger.BeginScope(processor.GetLoggingContextData(workItem)))
{
var success = await processor.ProcessWorkItemAsync(workItem, cancellationToken);
if (success)
try
{
telemetryScope.SetSuccess();
logger.LogInformation("Processing work item {type}", type);
var success = await processor.ProcessWorkItemAsync(workItem, cancellationToken);
if (success)
{
telemetryScope.SetSuccess();
}
}
catch (Exception e)
{
operation.Telemetry.Success = false;
logger.LogError(e, "Failed to process work item {type}", type);
throw;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.ApplicationInsights;
using Microsoft.DotNet.DarcLib;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down

0 comments on commit ec58592

Please sign in to comment.