From 50637d4791d0d15a335f4550f4ca423ffdfc7b22 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 12 Apr 2022 08:32:55 -0700 Subject: [PATCH] switch to our logger (#1780) * switch to our logger * preserve correlation id when calling CorpusAccounts Co-authored-by: Stas Tishkin --- .../ApiService/EnvironmentVariables.cs | 4 + src/ApiService/ApiService/Info.cs | 40 +++++++++ src/ApiService/ApiService/Log.cs | 84 ++++++++++--------- src/ApiService/ApiService/QueueFileChanges.cs | 16 ++-- .../ApiService/QueueNodeHearbeat.cs | 12 +-- .../ApiService/QueueProxyHeartbeat.cs | 16 ++-- .../ApiService/QueueSignalREvents.cs | 7 +- src/ApiService/ApiService/UserCredentials.cs | 1 + .../ApiService/onefuzzlib/Events.cs | 15 ++-- .../ApiService/onefuzzlib/ProxyOperations.cs | 7 +- src/ApiService/ApiService/onefuzzlib/Queue.cs | 7 +- .../ApiService/onefuzzlib/Storage.cs | 12 +-- .../onefuzzlib/WebhookOperations.cs | 14 ++-- 13 files changed, 140 insertions(+), 95 deletions(-) create mode 100644 src/ApiService/ApiService/Info.cs diff --git a/src/ApiService/ApiService/EnvironmentVariables.cs b/src/ApiService/ApiService/EnvironmentVariables.cs index 27c2680f8d..9b406ff27f 100644 --- a/src/ApiService/ApiService/EnvironmentVariables.cs +++ b/src/ApiService/ApiService/EnvironmentVariables.cs @@ -12,7 +12,11 @@ public static class EnvironmentVariables static EnvironmentVariables() { +#if DEBUG + LogDestinations = new LogDestination[] { LogDestination.AppInsights, LogDestination.Console }; +#else LogDestinations = new LogDestination[] { LogDestination.AppInsights }; +#endif } //TODO: Add environment variable to control where to write logs to diff --git a/src/ApiService/ApiService/Info.cs b/src/ApiService/ApiService/Info.cs new file mode 100644 index 0000000000..9676ed51bb --- /dev/null +++ b/src/ApiService/ApiService/Info.cs @@ -0,0 +1,40 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Azure.Functions.Worker.Http; + +namespace Microsoft.OneFuzz.Service; + +public record FunctionInfo(string Name, string ResourceGroup, string? SlotName); + + +public class Info +{ + + private readonly ILogTracerFactory _loggerFactory; + + + public Info(ILogTracerFactory loggerFactory) + { + _loggerFactory = loggerFactory; + } + + [Function("Info")] + public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestData req) + { + var log = _loggerFactory.MakeLogTracer(Guid.NewGuid()); + log.Info("Creating function info response"); + var response = req.CreateResponse(); + FunctionInfo info = new( + $"{EnvironmentVariables.OneFuzz.InstanceName}", + $"{EnvironmentVariables.OneFuzz.ResourceGroup}", + Environment.GetEnvironmentVariable("WEBSITE_SLOT_NAME")); + + + log.Info("Returning function info"); + await response.WriteAsJsonAsync(info); + log.Info("Returned function info"); + return response; + } + +} diff --git a/src/ApiService/ApiService/Log.cs b/src/ApiService/ApiService/Log.cs index b909291144..2f1d54ba40 100644 --- a/src/ApiService/ApiService/Log.cs +++ b/src/ApiService/ApiService/Log.cs @@ -24,21 +24,21 @@ class AppInsights : ILog public void Log(Guid correlationId, String message, SeverityLevel level, IDictionary tags, string? caller) { - tags.Add("Correlation ID", correlationId.ToString()); - if (caller is not null) tags.Add("CalledBy", caller); + tags["Correlation ID"] = correlationId.ToString(); + if (caller is not null) tags["CalledBy"] = caller; telemetryClient.TrackTrace(message, level, tags); } public void LogEvent(Guid correlationId, String evt, IDictionary tags, IDictionary? metrics, string? caller) { - tags.Add("Correlation ID", correlationId.ToString()); - if (caller is not null) tags.Add("CalledBy", caller); + tags["Correlation ID"] = correlationId.ToString(); + if (caller is not null) tags["CalledBy"] = caller; telemetryClient.TrackEvent(evt, properties: tags, metrics: metrics); } public void LogException(Guid correlationId, Exception ex, IDictionary tags, IDictionary? metrics, string? caller) { - tags.Add("Correlation ID", correlationId.ToString()); + tags["Correlation ID"] = correlationId.ToString(); - if (caller is not null) tags.Add("CalledBy", caller); + if (caller is not null) tags["CalledBy"] = caller; telemetryClient.TrackException(ex, tags, metrics); } @@ -69,7 +69,7 @@ private void LogTags(Guid correlationId, string? caller, IDictionary tags, string? caller) { - System.Console.Out.WriteLine("[{0}:{1}][{2}] {3}", correlationId, caller, level, message); + System.Console.Out.WriteLine($"[{correlationId}:{caller}][{level}] {message}"); LogTags(correlationId, caller, tags); } public void LogEvent(Guid correlationId, String evt, IDictionary tags, IDictionary? metrics, string? caller) { - System.Console.Out.WriteLine("[{0}:{1}][Event] {2}", correlationId, caller, evt); + System.Console.Out.WriteLine($"[{correlationId}:{caller}][Event] {evt}"); LogTags(correlationId, caller, tags); LogMetrics(correlationId, caller, metrics); } public void LogException(Guid correlationId, Exception ex, IDictionary tags, IDictionary? metrics, string? caller) { - System.Console.Out.WriteLine("[{0}:{1}][Exception] {2}", correlationId, caller, ex); + System.Console.Out.WriteLine($"[{correlationId}:{caller}][Exception] {ex}"); LogTags(correlationId, caller, tags); LogMetrics(correlationId, caller, metrics); } @@ -121,77 +121,80 @@ public interface ILogTracer public class LogTracer : ILogTracer { + private string? GetCaller() + { + return new StackTrace()?.GetFrame(2)?.GetMethod()?.DeclaringType?.FullName; + } - private List loggers; + private List _loggers; - private IDictionary tags = new Dictionary(); - private Guid correlationId; + public Guid CorrelationId { get; } + public IDictionary Tags { get; } public LogTracer(Guid correlationId, List loggers) { - this.correlationId = correlationId; - this.loggers = loggers; + CorrelationId = correlationId; + Tags = new Dictionary(); + _loggers = loggers; } - public IDictionary Tags => tags; - public void Info(string message) { - var caller = new StackTrace()?.GetFrame(1)?.GetMethod()?.Name; - foreach (var logger in loggers) + var caller = GetCaller(); + foreach (var logger in _loggers) { - logger.Log(correlationId, message, SeverityLevel.Information, Tags, caller); + logger.Log(CorrelationId, message, SeverityLevel.Information, Tags, caller); } } public void Warning(string message) { - var caller = new StackTrace()?.GetFrame(1)?.GetMethod()?.Name; - foreach (var logger in loggers) + var caller = GetCaller(); + foreach (var logger in _loggers) { - logger.Log(correlationId, message, SeverityLevel.Warning, Tags, caller); + logger.Log(CorrelationId, message, SeverityLevel.Warning, Tags, caller); } } public void Error(string message) { - var caller = new StackTrace()?.GetFrame(1)?.GetMethod()?.Name; - foreach (var logger in loggers) + var caller = GetCaller(); + foreach (var logger in _loggers) { - logger.Log(correlationId, message, SeverityLevel.Error, Tags, caller); + logger.Log(CorrelationId, message, SeverityLevel.Error, Tags, caller); } } public void Critical(string message) { - var caller = new StackTrace()?.GetFrame(1)?.GetMethod()?.Name; - foreach (var logger in loggers) + var caller = GetCaller(); + foreach (var logger in _loggers) { - logger.Log(correlationId, message, SeverityLevel.Critical, Tags, caller); + logger.Log(CorrelationId, message, SeverityLevel.Critical, Tags, caller); } } public void Event(string evt, IDictionary? metrics) { - var caller = new StackTrace()?.GetFrame(1)?.GetMethod()?.Name; - foreach (var logger in loggers) + var caller = GetCaller(); + foreach (var logger in _loggers) { - logger.LogEvent(correlationId, evt, Tags, metrics, caller); + logger.LogEvent(CorrelationId, evt, Tags, metrics, caller); } } public void Exception(Exception ex, IDictionary? metrics) { - var caller = new StackTrace()?.GetFrame(1)?.GetMethod()?.Name; - foreach (var logger in loggers) + var caller = GetCaller(); + foreach (var logger in _loggers) { - logger.LogException(correlationId, ex, Tags, metrics, caller); + logger.LogException(CorrelationId, ex, Tags, metrics, caller); } } public void ForceFlush() { - foreach (var logger in loggers) + foreach (var logger in _loggers) { logger.Flush(); } @@ -205,17 +208,16 @@ public interface ILogTracerFactory public class LogTracerFactory : ILogTracerFactory { - - private List loggers; + private List _loggers; public LogTracerFactory(List loggers) { - this.loggers = loggers; + _loggers = loggers; } public LogTracer MakeLogTracer(Guid correlationId) { - return new LogTracer(correlationId, this.loggers); + return new(correlationId, _loggers); } } diff --git a/src/ApiService/ApiService/QueueFileChanges.cs b/src/ApiService/ApiService/QueueFileChanges.cs index 2b3d46f8a7..1a0b5161e6 100644 --- a/src/ApiService/ApiService/QueueFileChanges.cs +++ b/src/ApiService/ApiService/QueueFileChanges.cs @@ -1,6 +1,5 @@ using System; using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; @@ -15,14 +14,14 @@ public class QueueFileChanges // https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger?tabs=csharp#poison-messages const int MAX_DEQUEUE_COUNT = 5; - private readonly ILogger _logger; + private readonly ILogTracerFactory _loggerFactory; private readonly IStorageProvider _storageProvider; private readonly IStorage _storage; - public QueueFileChanges(ILoggerFactory loggerFactory, IStorageProvider storageProvider, IStorage storage) + public QueueFileChanges(ILogTracerFactory loggerFactory, IStorageProvider storageProvider, IStorage storage) { - _logger = loggerFactory.CreateLogger(); + _loggerFactory = loggerFactory; _storageProvider = storageProvider; _storage = storage; } @@ -32,6 +31,7 @@ public Task Run( [QueueTrigger("file-changes-refactored", Connection = "AzureWebJobsStorage")] string msg, int dequeueCount) { + var log = _loggerFactory.MakeLogTracer(Guid.NewGuid()); var fileChangeEvent = JsonSerializer.Deserialize>(msg, EntityConverter.GetJsonSerializerOptions()); var lastTry = dequeueCount == MAX_DEQUEUE_COUNT; @@ -47,16 +47,16 @@ public Task Run( const string topic = "topic"; if (!fileChangeEvent.ContainsKey(topic) - || !_storage.CorpusAccounts().Contains(fileChangeEvent[topic])) + || !_storage.CorpusAccounts(log).Contains(fileChangeEvent[topic])) { return Task.CompletedTask; } - file_added(fileChangeEvent, lastTry); + file_added(log, fileChangeEvent, lastTry); return Task.CompletedTask; } - private void file_added(Dictionary fileChangeEvent, bool failTaskOnTransientError) + private void file_added(ILogTracer log, Dictionary fileChangeEvent, bool failTaskOnTransientError) { var data = JsonSerializer.Deserialize>(fileChangeEvent["data"])!; var url = data["url"]; @@ -65,7 +65,7 @@ private void file_added(Dictionary fileChangeEvent, bool failTas var container = parts[0]; var path = string.Join('/', parts.Skip(1)); - _logger.LogInformation($"file added container: {container} - path: {path}"); + log.Info($"file added container: {container} - path: {path}"); // TODO: new_files(container, path, fail_task_on_transient_error) } } diff --git a/src/ApiService/ApiService/QueueNodeHearbeat.cs b/src/ApiService/ApiService/QueueNodeHearbeat.cs index c360bc6698..d13fa5285b 100644 --- a/src/ApiService/ApiService/QueueNodeHearbeat.cs +++ b/src/ApiService/ApiService/QueueNodeHearbeat.cs @@ -1,6 +1,5 @@ using System; using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; using System.Text.Json; using System.Threading.Tasks; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; @@ -10,14 +9,14 @@ namespace Microsoft.OneFuzz.Service; public class QueueNodeHearbeat { - private readonly ILogger _logger; + private readonly ILogTracerFactory _loggerFactory; private readonly IEvents _events; private readonly INodeOperations _nodes; - public QueueNodeHearbeat(ILoggerFactory loggerFactory, INodeOperations nodes, IEvents events) + public QueueNodeHearbeat(ILogTracerFactory loggerFactory, INodeOperations nodes, IEvents events) { - _logger = loggerFactory.CreateLogger(); + _loggerFactory = loggerFactory; _nodes = nodes; _events = events; } @@ -25,7 +24,8 @@ public QueueNodeHearbeat(ILoggerFactory loggerFactory, INodeOperations nodes, IE [Function("QueueNodeHearbeat")] public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg) { - _logger.LogInformation($"heartbeat: {msg}"); + var log = _loggerFactory.MakeLogTracer(Guid.NewGuid()); + log.Info($"heartbeat: {msg}"); var hb = JsonSerializer.Deserialize(msg, EntityConverter.GetJsonSerializerOptions()).EnsureNotNull($"wrong data {msg}"); @@ -33,7 +33,7 @@ public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsS if (node == null) { - _logger.LogWarning($"invalid node id: {hb.NodeId}"); + log.Warning($"invalid node id: {hb.NodeId}"); return; } diff --git a/src/ApiService/ApiService/QueueProxyHeartbeat.cs b/src/ApiService/ApiService/QueueProxyHeartbeat.cs index dddfff0321..8705a98d40 100644 --- a/src/ApiService/ApiService/QueueProxyHeartbeat.cs +++ b/src/ApiService/ApiService/QueueProxyHeartbeat.cs @@ -1,6 +1,5 @@ using System; using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; using System.Text.Json; using System.Threading.Tasks; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; @@ -9,29 +8,34 @@ namespace Microsoft.OneFuzz.Service; public class QueueProxyHearbeat { - private readonly ILogger _logger; + private readonly ILogTracerFactory _loggerFactory; private readonly IProxyOperations _proxy; - public QueueProxyHearbeat(ILoggerFactory loggerFactory, IProxyOperations proxy) + public QueueProxyHearbeat(ILogTracerFactory loggerFactory, IProxyOperations proxy) { - _logger = loggerFactory.CreateLogger(); + _loggerFactory = loggerFactory; _proxy = proxy; } [Function("QueueProxyHearbeat")] public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg) { - _logger.LogInformation($"heartbeat: {msg}"); + var log = _loggerFactory.MakeLogTracer(Guid.NewGuid()); + + log.Info($"heartbeat: {msg}"); var hb = JsonSerializer.Deserialize(msg, EntityConverter.GetJsonSerializerOptions()).EnsureNotNull($"wrong data {msg}"); ; var newHb = hb with { TimeStamp = DateTimeOffset.UtcNow }; + log.Tags["Proxy ID"] = newHb.ProxyId.ToString(); + + var proxy = await _proxy.GetByProxyId(newHb.ProxyId); if (proxy == null) { - _logger.LogWarning($"invalid proxy id: {newHb.ProxyId}"); + log.Warning($"invalid proxy id: {newHb.ProxyId}"); return; } var newProxy = proxy with { heartbeat = newHb }; diff --git a/src/ApiService/ApiService/QueueSignalREvents.cs b/src/ApiService/ApiService/QueueSignalREvents.cs index cd432ae07e..21a5a05b4e 100644 --- a/src/ApiService/ApiService/QueueSignalREvents.cs +++ b/src/ApiService/ApiService/QueueSignalREvents.cs @@ -1,15 +1,14 @@ using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; namespace Microsoft.OneFuzz.Service; public class QueueSignalREvents { - private readonly ILogger _logger; + private readonly ILogTracerFactory _loggerFactory; - public QueueSignalREvents(ILoggerFactory loggerFactory) + public QueueSignalREvents(ILogTracerFactory loggerFactory) { - _logger = loggerFactory.CreateLogger(); + _loggerFactory = loggerFactory; } [Function("QueueSignalREvents")] diff --git a/src/ApiService/ApiService/UserCredentials.cs b/src/ApiService/ApiService/UserCredentials.cs index 8771aa4f9f..67256c409c 100644 --- a/src/ApiService/ApiService/UserCredentials.cs +++ b/src/ApiService/ApiService/UserCredentials.cs @@ -109,6 +109,7 @@ from t in token.Claims } else { + log.Error("Failed to get allowed tenants"); return OneFuzzResult.Error(allowedTenants.ErrorV); } } diff --git a/src/ApiService/ApiService/onefuzzlib/Events.cs b/src/ApiService/ApiService/onefuzzlib/Events.cs index b0ed8b5669..65aadf9bfd 100644 --- a/src/ApiService/ApiService/onefuzzlib/Events.cs +++ b/src/ApiService/ApiService/onefuzzlib/Events.cs @@ -1,5 +1,4 @@ using ApiService.OneFuzzLib; -using Microsoft.Extensions.Logging; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using System; using System.Collections.Generic; @@ -29,13 +28,13 @@ public interface IEvents public class Events : IEvents { private readonly IQueue _queue; - private readonly ILogger _logger; + private readonly ILogTracerFactory _loggerFactory; private readonly IWebhookOperations _webhook; - public Events(IQueue queue, ILoggerFactory loggerFactory, IWebhookOperations webhook) + public Events(IQueue queue, ILogTracerFactory loggerFactory, IWebhookOperations webhook) { _queue = queue; - _logger = loggerFactory.CreateLogger(); + _loggerFactory = loggerFactory; _webhook = webhook; } @@ -48,6 +47,7 @@ public async Task QueueSignalrEvent(EventMessage eventMessage) public async Task SendEvent(BaseEvent anEvent) { + var log = _loggerFactory.MakeLogTracer(Guid.NewGuid()); var eventType = anEvent.GetEventType(); var eventMessage = new EventMessage( @@ -59,16 +59,17 @@ public async Task SendEvent(BaseEvent anEvent) ); await QueueSignalrEvent(eventMessage); await _webhook.SendEvent(eventMessage); - LogEvent(anEvent, eventType); + LogEvent(log, anEvent, eventType); } - public void LogEvent(BaseEvent anEvent, EventType eventType) + public void LogEvent(ILogTracer log, BaseEvent anEvent, EventType eventType) { var options = EntityConverter.GetJsonSerializerOptions(); options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; options.Converters.Add(new RemoveUserInfo()); var serializedEvent = JsonSerializer.Serialize(anEvent, options); - _logger.LogInformation($"sending event: {eventType} - {serializedEvent}"); + log.Tags["Event Type"] = eventType.ToString(); + log.Info($"sending event: {eventType} - {serializedEvent}"); } } diff --git a/src/ApiService/ApiService/onefuzzlib/ProxyOperations.cs b/src/ApiService/ApiService/onefuzzlib/ProxyOperations.cs index bd05801d32..358e28eb30 100644 --- a/src/ApiService/ApiService/onefuzzlib/ProxyOperations.cs +++ b/src/ApiService/ApiService/onefuzzlib/ProxyOperations.cs @@ -2,7 +2,6 @@ using System; using System.Linq; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; namespace Microsoft.OneFuzz.Service; @@ -12,12 +11,12 @@ public interface IProxyOperations : IOrm } public class ProxyOperations : Orm, IProxyOperations { - private readonly ILogger _logger; + private readonly ILogTracerFactory _logger; - public ProxyOperations(ILoggerFactory loggerFactory, IStorage storage) + public ProxyOperations(ILogTracerFactory loggerFactory, IStorage storage) : base(storage) { - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory; } public async Task GetByProxyId(Guid proxyId) diff --git a/src/ApiService/ApiService/onefuzzlib/Queue.cs b/src/ApiService/ApiService/onefuzzlib/Queue.cs index b638b8cb1d..d159d717fc 100644 --- a/src/ApiService/ApiService/onefuzzlib/Queue.cs +++ b/src/ApiService/ApiService/onefuzzlib/Queue.cs @@ -1,6 +1,5 @@ using Azure.Storage; using Azure.Storage.Queues; -using Microsoft.Extensions.Logging; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using System; using System.Text.Json; @@ -17,12 +16,12 @@ public interface IQueue public class Queue : IQueue { IStorage _storage; - ILogger _logger; + ILogTracerFactory _loggerFactory; - public Queue(IStorage storage, ILoggerFactory loggerFactory) + public Queue(IStorage storage, ILogTracerFactory loggerFactory) { _storage = storage; - _logger = loggerFactory.CreateLogger(); + _loggerFactory = loggerFactory; } diff --git a/src/ApiService/ApiService/onefuzzlib/Storage.cs b/src/ApiService/ApiService/onefuzzlib/Storage.cs index 05c6be2869..afefbfd77e 100644 --- a/src/ApiService/ApiService/onefuzzlib/Storage.cs +++ b/src/ApiService/ApiService/onefuzzlib/Storage.cs @@ -5,7 +5,6 @@ using Azure.Core; using System.Text.Json; using System.Linq; -using Microsoft.Extensions.Logging; namespace Microsoft.OneFuzz.Service; @@ -19,21 +18,18 @@ public interface IStorage { public ArmClient GetMgmtClient(); - public IEnumerable CorpusAccounts(); + public IEnumerable CorpusAccounts(ILogTracer log); string GetPrimaryAccount(StorageType storageType); public (string?, string?) GetStorageAccountNameAndKey(string accountId); } public class Storage : IStorage { - private ICreds _creds; - private readonly ILogger _logger; - public Storage(ILoggerFactory loggerFactory, ICreds creds) + public Storage(ICreds creds) { _creds = creds; - _logger = loggerFactory.CreateLogger(); ; } // TODO: @cached @@ -57,7 +53,7 @@ public ArmClient GetMgmtClient() } // TODO: @cached - public IEnumerable CorpusAccounts() + public IEnumerable CorpusAccounts(ILogTracer log) { var skip = GetFuncStorage(); var results = new List { GetFuzzStorage() }; @@ -94,7 +90,7 @@ public IEnumerable CorpusAccounts() results.Add(account.Id!); } - _logger.LogInformation($"corpus accounts: {JsonSerializer.Serialize(results)}"); + log.Info($"corpus accounts: {JsonSerializer.Serialize(results)}"); return results; } diff --git a/src/ApiService/ApiService/onefuzzlib/WebhookOperations.cs b/src/ApiService/ApiService/onefuzzlib/WebhookOperations.cs index 8d33c387ef..2a83447e07 100644 --- a/src/ApiService/ApiService/onefuzzlib/WebhookOperations.cs +++ b/src/ApiService/ApiService/onefuzzlib/WebhookOperations.cs @@ -1,5 +1,4 @@ using ApiService.OneFuzzLib.Orm; -using Microsoft.Extensions.Logging; using Microsoft.OneFuzz.Service; using System; using System.Collections.Generic; @@ -22,16 +21,17 @@ Guid EventId ); private readonly IQueue _queue; - private readonly ILogger _logger; - public WebhookMessageLogOperations(IStorage storage, IQueue queue, ILoggerFactory loggerFactory) : base(storage) + private readonly ILogTracerFactory _loggerFactory; + public WebhookMessageLogOperations(IStorage storage, IQueue queue, ILogTracerFactory loggerFactory) : base(storage) { _queue = queue; - _logger = loggerFactory.CreateLogger(); ; + _loggerFactory = loggerFactory; } public async Task QueueWebhook(WebhookMessageLog webhookLog) { + var log = _loggerFactory.MakeLogTracer(Guid.NewGuid()); var obj = new WebhookMessageQueueObj(webhookLog.WebhookId, webhookLog.EventId); TimeSpan? visibilityTimeout = webhookLog.State switch @@ -41,11 +41,11 @@ public async Task QueueWebhook(WebhookMessageLog webhookLog) _ => null }; - if (visibilityTimeout == null) { - _logger.LogError($"invalid WebhookMessage queue state, not queuing. {webhookLog.WebhookId}:{webhookLog.EventId} - {webhookLog.State}"); - + log.Tags["WebhookId"] = webhookLog.WebhookId.ToString(); + log.Tags["EventId"] = webhookLog.EventId.ToString(); + log.Error($"invalid WebhookMessage queue state, not queuing. {webhookLog.WebhookId}:{webhookLog.EventId} - {webhookLog.State}"); } else {