Skip to content

Commit

Permalink
Update logging metadata to include entity URIs and FQDNs (#623)
Browse files Browse the repository at this point in the history
This allows one to disambiguate logs from multiple transports. For example, events from multiple Azure Service Bus namespaces but the queues are named the same such as when copying or fanning-out to multiple tenants.
  • Loading branch information
mburumaxwell authored Jun 6, 2024
1 parent ad13dbc commit d4ca8e4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private async Task OnMessageReceivedAsync(IServiceScope scope, EventRegistration
sequenceNumber: sequenceNumber,
extras: new Dictionary<string, string?>
{
["QueueUrl"] = queueUrl,
[MetadataNames.EntityUri] = queueUrl,
["ReceiptHandle"] = message.ReceiptHandle,
[nameof(message.MD5OfBody)] = message.MD5OfBody,
[nameof(message.MD5OfMessageAttributes)] = message.MD5OfMessageAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,12 @@ private async Task OnEventReceivedAsync(EventRegistration reg, EventConsumerRegi
sequenceNumber: data.SequenceNumber.ToString(),
extras: new Dictionary<string, string?>
{
[MetadataNames.FullyQualifiedNamespace] = processor.FullyQualifiedNamespace,
[MetadataNames.EventName] = eventName?.ToString(),
[MetadataNames.EventType] = eventType?.ToString(),
["PartitionId"] = partitionId,
["EventHubName"] = processor.EventHubName,
["ConsumerGroup"] = processor.ConsumerGroup,
["PartitionId"] = partitionId,
["PartitionKey"] = data.PartitionKey,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private async Task OnMessageReceivedAsync(IServiceScope scope, EventRegistration
correlationId: null,
extras: new Dictionary<string, string?>
{
[MetadataNames.EntityUri] = queueClient.Uri.ToString(),
["PopReceipt"] = message.PopReceipt,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ private static TimeSpan SafeDuplicateDetectionHistoryTimeWindow(TimeSpan value)

private async Task OnMessageReceivedAsync(EventRegistration reg, EventConsumerRegistration ecr, ServiceBusProcessor processor, ProcessMessageEventArgs args)
{
var fqdn = args.FullyQualifiedNamespace;
var entityPath = args.EntityPath;
var message = args.Message;
var messageId = message.MessageId;
Expand All @@ -511,7 +512,8 @@ private async Task OnMessageReceivedAsync(EventRegistration reg, EventConsumerRe
sequenceNumber: message.SequenceNumber.ToString(),
extras: new Dictionary<string, string?>
{
["EntityPath"] = entityPath,
[MetadataNames.FullyQualifiedNamespace] = fqdn,
[MetadataNames.EntityUri] = entityPath,
["EnqueuedSequenceNumber"] = message.EnqueuedSequenceNumber.ToString(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private async Task OnMessageReceivedAsync(EventRegistration reg, EventConsumerRe
sequenceNumber: message.SequenceNumber.ToString(),
extras: new Dictionary<string, string?>
{
["EntityPath"] = entityPath,
[MetadataNames.EntityUri] = entityPath,
});

// Instrumentation
Expand Down
2 changes: 2 additions & 0 deletions src/Tingle.EventBus/MetadataNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static class MetadataNames
public const string CorrelationId = "CorrelationId";
public const string RequestId = "RequestId";
public const string InitiatorId = "InitiatorId";
public const string FullyQualifiedNamespace = "FullyQualifiedNamespace";
public const string EntityUri = "EntityUri";

public const string ActivityId = "EventBus.ActivityId";
public const string EventType = "EventBus.EventType";
Expand Down

0 comments on commit d4ca8e4

Please sign in to comment.