diff --git a/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs b/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs index 90665fd..a936369 100644 --- a/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs +++ b/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs @@ -68,7 +68,12 @@ namespace DotNetCore.CAP.Abstractions try { - operationId = s_diagnosticListener.WritePublishMessageStoreBefore(message); + var tracingResult = TracingBefore(message.Name, message.Content); + operationId = tracingResult.Item1; + + message.Content = tracingResult.Item2 != null + ? Helper.AddTracingHeaderProperty(message.Content, tracingResult.Item2) + : message.Content; if (Transaction.Value?.DbTransaction == null) { @@ -100,6 +105,21 @@ namespace DotNetCore.CAP.Abstractions throw; } } + + private (Guid, TracingHeaders) TracingBefore(string topic, string values) + { + Guid operationId = Guid.NewGuid(); + + var eventData = new BrokerStoreEventData( + operationId, + "", + topic, + values); + + s_diagnosticListener.WritePublishMessageStoreBefore(eventData); + + return (operationId, eventData.Headers); + } protected abstract Task ExecuteAsync(CapPublishedMessage message, ICapTransaction transaction = null, diff --git a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs index da0cc0c..e0b249b 100644 --- a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs +++ b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs @@ -38,26 +38,13 @@ namespace DotNetCore.CAP.Diagnostics //============================================================================ //==================== Before publish store message ==================== //============================================================================ - public static Guid WritePublishMessageStoreBefore(this DiagnosticListener @this, - CapPublishedMessage message, - [CallerMemberName] string operation = "") + public static void WritePublishMessageStoreBefore(this DiagnosticListener @this, BrokerStoreEventData eventData) { if (@this.IsEnabled(CapBeforePublishMessageStore)) { - var operationId = Guid.NewGuid(); - - @this.Write(CapBeforePublishMessageStore, new - { - OperationId = operationId, - Operation = operation, - MessageName = message.Name, - MessageContent = message.Content - }); - - return operationId; + eventData.Headers = new TracingHeaders(); + @this.Write(CapBeforePublishMessageStore, eventData); } - - return Guid.Empty; } public static void WritePublishMessageStoreAfter(this DiagnosticListener @this, diff --git a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs new file mode 100644 index 0000000..fed5f71 --- /dev/null +++ b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs @@ -0,0 +1,22 @@ +using System; + +namespace DotNetCore.CAP.Diagnostics +{ + public class BrokerStoreEventData : EventData + { + public BrokerStoreEventData( + Guid operationId, + string operation, + string messageName, + string messageContent) : base(operationId, operation) + { + MessageName = messageName; + MessageContent = messageContent; + } + + public string MessageName { get; set; } + public string MessageContent { get; set; } + + public TracingHeaders Headers { get; set; } + } +} \ No newline at end of file