diff --git a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs index e0b249b..d3c0f97 100644 --- a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs +++ b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs @@ -203,6 +203,7 @@ namespace DotNetCore.CAP.Diagnostics Exception ex, DateTimeOffset startTime, TimeSpan duration, + int retries, [CallerMemberName] string operation = "") { if (@this.IsEnabled(CapErrorSubscriberInvoke)) @@ -214,7 +215,7 @@ namespace DotNetCore.CAP.Diagnostics @this.Write(CapErrorSubscriberInvoke, new SubscriberInvokeErrorEventData(operationId, operation, methodName, subscribeName, - subscribeGroup, parameterValues, ex, startTime, duration)); + subscribeGroup, parameterValues, ex, startTime, duration, retries)); } } } diff --git a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs index ec44e3b..c6fef21 100644 --- a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs +++ b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs @@ -9,12 +9,14 @@ namespace DotNetCore.CAP.Diagnostics { public BrokerPublishErrorEventData(Guid operationId, string operation, string brokerAddress, string brokerTopicName, string brokerTopicBody, Exception exception, DateTimeOffset startTime, - TimeSpan duration) + TimeSpan duration, int retries) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody, startTime, duration) { + Retries = retries; Exception = exception; } + public int Retries { get; } public Exception Exception { get; } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs b/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs index 005f70f..6c57cc5 100644 --- a/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs +++ b/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs @@ -9,12 +9,14 @@ namespace DotNetCore.CAP.Diagnostics { public SubscriberInvokeErrorEventData(Guid operationId, string operation, string methodName, string subscribeName, string subscribeGroup, string parameterValues, Exception exception, - DateTimeOffset startTime, TimeSpan duration) : base(operationId, operation, methodName, subscribeName, - subscribeGroup, parameterValues, startTime, duration) + DateTimeOffset startTime, TimeSpan duration, int retries) : base(operationId, operation, methodName, + subscribeName, subscribeGroup, parameterValues, startTime, duration) { + Retries = retries; Exception = exception; } + public int Retries { get; } public Exception Exception { get; } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs index 873929f..4902081 100644 --- a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs +++ b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs @@ -190,7 +190,8 @@ namespace DotNetCore.CAP message.Content, ex, startTime, - du); + du, + message.Retries + 1); s_diagnosticListener.WritePublishError(eventData); } diff --git a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs index 19ecbc9..f1267e3 100644 --- a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs +++ b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs @@ -199,7 +199,8 @@ namespace DotNetCore.CAP } catch (Exception ex) { - s_diagnosticListener.WriteSubscriberInvokeError(operationId, consumerContext, ex, startTime, stopwatch.Elapsed); + s_diagnosticListener.WriteSubscriberInvokeError(operationId, consumerContext, ex, startTime, + stopwatch.Elapsed, receivedMessage.Retries + 1); throw new SubscriberExecutionFailedException(ex.Message, ex); } diff --git a/test/DotNetCore.CAP.Test/DiagnosticsTest.cs b/test/DotNetCore.CAP.Test/DiagnosticsTest.cs index b3473a9..e33d8d9 100644 --- a/test/DotNetCore.CAP.Test/DiagnosticsTest.cs +++ b/test/DotNetCore.CAP.Test/DiagnosticsTest.cs @@ -65,7 +65,7 @@ namespace DotNetCore.CAP.Test var ex = new Exception("WritePublishErrorTest"); DiagnosticsWapper(() => { - var eventData = new BrokerPublishErrorEventData(operationId, "", "", "", "", ex, DateTimeOffset.UtcNow, default(TimeSpan)); + var eventData = new BrokerPublishErrorEventData(operationId, "", "", "", "", ex, DateTimeOffset.UtcNow, default(TimeSpan), default(int)); s_diagnosticListener.WritePublishError(eventData); }, kvp => @@ -192,7 +192,7 @@ namespace DotNetCore.CAP.Test DiagnosticsWapper(() => { s_diagnosticListener.WriteSubscriberInvokeError(operationId, FackConsumerContext(), ex, - DateTimeOffset.Now, TimeSpan.MaxValue); + DateTimeOffset.Now, TimeSpan.MaxValue, default(int)); }, kvp => { if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapErrorSubscriberInvoke))