diff --git a/sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/EventProcessorClient.cs b/sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/EventProcessorClient.cs index 05610e1acc4c..c9f401deef3f 100755 --- a/sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/EventProcessorClient.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/EventProcessorClient.cs @@ -723,6 +723,7 @@ internal virtual Task RunPartitionProcessingAsync(string partitionId, && EventDataInstrumentation.TryExtractDiagnosticId(partitionEvent.Data, out string diagnosticId)) { diagnosticScope.AddLink(diagnosticId); + diagnosticScope.AddAttribute(DiagnosticProperty.EnqueuedTimeAttribute, partitionEvent.Data.EnqueuedTime.ToUnixTimeSeconds()); } diagnosticScope.Start(); diff --git a/sdk/eventhub/Azure.Messaging.EventHubs.Processor/tests/Diagnostics/DiagnosticsTests.cs b/sdk/eventhub/Azure.Messaging.EventHubs.Processor/tests/Diagnostics/DiagnosticsTests.cs index 7dfb2c51db8f..e755f4bb0271 100755 --- a/sdk/eventhub/Azure.Messaging.EventHubs.Processor/tests/Diagnostics/DiagnosticsTests.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs.Processor/tests/Diagnostics/DiagnosticsTests.cs @@ -82,6 +82,7 @@ public async Task RunPartitionProcessingAsyncCreatesScopeForEventProcessing() var mockStorage = new MockCheckPointStorage(); var mockConsumer = new Mock("cg", Mock.Of(), default); var mockProcessor = new Mock(mockStorage, "cg", fullyQualifiedNamespace, eventHubName, Mock.Of>(), default, default) { CallBase = true }; + var enqueuedTime = DateTimeOffset.UtcNow; using ClientDiagnosticListener listener = new ClientDiagnosticListener(DiagnosticSourceName); var completionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -99,8 +100,8 @@ async IAsyncEnumerable mockPartitionEventEnumerable() { var context = new MockPartitionContext(partitionId); - yield return new PartitionEvent(context, new EventData(Array.Empty()) { Properties = { { "Diagnostic-Id", "id" } } }); - yield return new PartitionEvent(context, new EventData(Array.Empty()) { Properties = { { "Diagnostic-Id", "id2" } } }); + yield return new PartitionEvent(context, new MockEventData(Array.Empty(), enqueuedTime: enqueuedTime) { Properties = { { "Diagnostic-Id", "id" } } }); + yield return new PartitionEvent(context, new MockEventData(Array.Empty(), enqueuedTime: enqueuedTime) { Properties = { { "Diagnostic-Id", "id2" } } }); while (!completionSource.Task.IsCompleted && !token.IsCancellationRequested) { @@ -160,7 +161,8 @@ async IAsyncEnumerable mockPartitionEventEnumerable() { new KeyValuePair(DiagnosticProperty.KindAttribute, DiagnosticProperty.ConsumerKind), new KeyValuePair(DiagnosticProperty.EventHubAttribute, eventHubName), - new KeyValuePair(DiagnosticProperty.EndpointAttribute, fullyQualifiedNamespace) + new KeyValuePair(DiagnosticProperty.EndpointAttribute, fullyQualifiedNamespace), + new KeyValuePair(DiagnosticProperty.EnqueuedTimeAttribute, enqueuedTime.ToUnixTimeSeconds().ToString()) }; foreach (var scope in listener.Scopes) diff --git a/sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Diagnostics/DiagnosticProperty.cs b/sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Diagnostics/DiagnosticProperty.cs index 0666d1549aa6..a3fa0f38b79c 100755 --- a/sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Diagnostics/DiagnosticProperty.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Diagnostics/DiagnosticProperty.cs @@ -21,6 +21,9 @@ internal static class DiagnosticProperty /// The attribute which represents the fully-qualified endpoint address of the Event Hubs namespace to associate with diagnostics information. public const string EndpointAttribute = "peer.address"; + /// The attribute which represents the UNIX Epoch enqueued time of an event to associate with diagnostics information. + public const string EnqueuedTimeAttribute = "x-opt-enqueued-time"; + /// The value which identifies the Event Hubs diagnostics context. public const string EventHubsServiceContext = "eventhubs";