Commit af1b1ec6 authored by Savorboard's avatar Savorboard

refactor diagnostics

parent 9d0a453a
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using DotNetCore.CAP.Internal; using DotNetCore.CAP.Internal;
...@@ -23,21 +26,25 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -23,21 +26,25 @@ namespace DotNetCore.CAP.Diagnostics
public const string CapAfterPublish = CapPrefix + nameof(WritePublishAfter); public const string CapAfterPublish = CapPrefix + nameof(WritePublishAfter);
public const string CapErrorPublish = CapPrefix + nameof(WritePublishError); public const string CapErrorPublish = CapPrefix + nameof(WritePublishError);
public const string CapBeforeReceiveMessageStore = CapPrefix + nameof(WriteReceiveMessageStoreBefore); public const string CapBeforeConsume = CapPrefix + nameof(WriteConsumeBefore);
public const string CapAfterReceiveMessageStore = CapPrefix + nameof(WriteReceiveMessageStoreAfter); public const string CapAfterConsume = CapPrefix + nameof(WriteConsumeAfter);
public const string CapErrorReceiveMessageStore = CapPrefix + nameof(WriteReceiveMessageStoreError); public const string CapErrorConsume = CapPrefix + nameof(WriteConsumeError);
public const string CapBeforeSubscriberInvoke = CapPrefix + nameof(WriteSubscriberInvokeBefore);
public const string CapAfterSubscriberInvoke = CapPrefix + nameof(WriteSubscriberInvokeAfter);
public const string CapErrorSubscriberInvoke = CapPrefix + nameof(WriteSubscriberInvokeError);
public const string CapBeforeConsumerInvoke = CapPrefix + nameof(WriteConsumerInvokeBefore);
public const string CapAfterConsumerInvoke = CapPrefix + nameof(WriteConsumerInvokeAfter);
public const string CapErrorConsumerInvoke = CapPrefix + nameof(WriteConsumerInvokeError);
//============================================================================
//==================== Before publish store message ====================
//============================================================================
public static Guid WritePublishMessageStoreBefore(this DiagnosticListener @this, public static Guid WritePublishMessageStoreBefore(this DiagnosticListener @this,
CapPublishedMessage message, CapPublishedMessage message,
[CallerMemberName] string operation = "") [CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapBeforePublishMessageStore)) if (@this.IsEnabled(CapBeforePublishMessageStore))
{ {
Guid operationId = Guid.NewGuid(); var operationId = Guid.NewGuid();
@this.Write(CapBeforePublishMessageStore, new @this.Write(CapBeforePublishMessageStore, new
{ {
...@@ -49,6 +56,7 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -49,6 +56,7 @@ namespace DotNetCore.CAP.Diagnostics
return operationId; return operationId;
} }
return Guid.Empty; return Guid.Empty;
} }
...@@ -91,143 +99,112 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -91,143 +99,112 @@ namespace DotNetCore.CAP.Diagnostics
} }
} }
public static Guid WritePublishBefore(this DiagnosticListener @this,
string topic, //============================================================================
string body, //==================== Publish ====================
string brokerAddress, //============================================================================
[CallerMemberName] string operation = "") public static void WritePublishBefore(this DiagnosticListener @this, BrokerPublishEventData eventData)
{ {
if (@this.IsEnabled(CapBeforePublish)) if (@this.IsEnabled(CapBeforePublish))
{ {
Guid operationId = Guid.NewGuid(); @this.Write(CapBeforePublish, eventData);
@this.Write(CapBeforePublish, new BrokerPublishEventData(operationId, operation, brokerAddress, topic, body, DateTimeOffset.UtcNow));
return operationId;
} }
return Guid.Empty;
} }
public static void WritePublishAfter(this DiagnosticListener @this, public static void WritePublishAfter(this DiagnosticListener @this, BrokerPublishEndEventData eventData)
Guid operationId,
string topic,
string body,
string brokerAddress,
DateTimeOffset startTime,
TimeSpan duration,
[CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapAfterPublish)) if (@this.IsEnabled(CapAfterPublish))
{ {
@this.Write(CapAfterPublish, new BrokerPublishEndEventData(operationId, operation, brokerAddress, topic, body, startTime, duration)); @this.Write(CapAfterPublish, eventData);
} }
} }
public static void WritePublishError(this DiagnosticListener @this, public static void WritePublishError(this DiagnosticListener @this, BrokerPublishErrorEventData eventData)
Guid operationId,
string topic,
string body,
string brokerAddress,
Exception ex,
DateTimeOffset startTime,
TimeSpan duration,
[CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapErrorPublish)) if (@this.IsEnabled(CapErrorPublish))
{ {
@this.Write(CapErrorPublish, new BrokerPublishErrorEventData(operationId, operation, brokerAddress, topic, body, ex, startTime, duration)); @this.Write(CapErrorPublish, eventData);
} }
} }
public static Guid WriteReceiveMessageStoreBefore(this DiagnosticListener @this,
string topic, //============================================================================
string body, //==================== Consume ====================
string groupName, //============================================================================
[CallerMemberName] string operation = "") public static Guid WriteConsumeBefore(this DiagnosticListener @this, BrokerConsumeEventData eventData)
{ {
if (@this.IsEnabled(CapBeforeReceiveMessageStore)) if (@this.IsEnabled(CapBeforeConsume))
{ {
Guid operationId = Guid.NewGuid(); @this.Write(CapBeforeConsume, eventData);
@this.Write(CapBeforePublish, new BrokerConsumeEventData(operationId, operation, groupName, topic, body, DateTimeOffset.UtcNow));
return operationId;
} }
return Guid.Empty; return Guid.Empty;
} }
public static void WriteReceiveMessageStoreAfter(this DiagnosticListener @this, public static void WriteConsumeAfter(this DiagnosticListener @this, BrokerConsumeEndEventData eventData)
Guid operationId,
string topic,
string body,
string groupName,
DateTimeOffset startTime,
TimeSpan duration,
[CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapAfterReceiveMessageStore)) if (@this.IsEnabled(CapAfterConsume))
{ {
@this.Write(CapAfterPublish, new BrokerConsumeEndEventData(operationId, operation, groupName, topic, body, startTime, duration)); @this.Write(CapAfterConsume, eventData);
} }
} }
public static void WriteReceiveMessageStoreError(this DiagnosticListener @this, public static void WriteConsumeError(this DiagnosticListener @this, BrokerConsumeErrorEventData eventData)
Guid operationId,
string topic,
string body,
string groupName,
Exception ex,
DateTimeOffset startTime,
TimeSpan duration,
[CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapErrorReceiveMessageStore)) if (@this.IsEnabled(CapErrorConsume))
{ {
@this.Write(CapErrorPublish, new BrokerConsumeErrorEventData(operationId, operation, groupName, topic, body, ex, startTime, duration)); @this.Write(CapErrorConsume, eventData);
} }
} }
public static Guid WriteConsumerInvokeBefore(this DiagnosticListener @this,
//============================================================================
//==================== SubscriberInvoke ====================
//============================================================================
public static Guid WriteSubscriberInvokeBefore(this DiagnosticListener @this,
ConsumerContext context, ConsumerContext context,
[CallerMemberName] string operation = "") [CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapBeforeConsumerInvoke)) if (@this.IsEnabled(CapBeforeSubscriberInvoke))
{ {
Guid operationId = Guid.NewGuid(); var operationId = Guid.NewGuid();
var methodName = context.ConsumerDescriptor.MethodInfo.Name; var methodName = context.ConsumerDescriptor.MethodInfo.Name;
var subscribeName = context.ConsumerDescriptor.Attribute.Name; var subscribeName = context.ConsumerDescriptor.Attribute.Name;
var subscribeGroup = context.ConsumerDescriptor.Attribute.Group; var subscribeGroup = context.ConsumerDescriptor.Attribute.Group;
var parameterValues = context.DeliverMessage.Content; var parameterValues = context.DeliverMessage.Content;
@this.Write(CapBeforePublish, new SubscriberInvokeEventData(operationId, operation, methodName, subscribeName, @this.Write(CapBeforePublish, new SubscriberInvokeEventData(operationId, operation, methodName,
subscribeName,
subscribeGroup, parameterValues, DateTimeOffset.UtcNow)); subscribeGroup, parameterValues, DateTimeOffset.UtcNow));
return operationId; return operationId;
} }
return Guid.Empty; return Guid.Empty;
} }
public static void WriteConsumerInvokeAfter(this DiagnosticListener @this, public static void WriteSubscriberInvokeAfter(this DiagnosticListener @this,
Guid operationId, Guid operationId,
ConsumerContext context, ConsumerContext context,
DateTimeOffset startTime, DateTimeOffset startTime,
TimeSpan duration, TimeSpan duration,
[CallerMemberName] string operation = "") [CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapAfterConsumerInvoke)) if (@this.IsEnabled(CapAfterSubscriberInvoke))
{ {
var methodName = context.ConsumerDescriptor.MethodInfo.Name; var methodName = context.ConsumerDescriptor.MethodInfo.Name;
var subscribeName = context.ConsumerDescriptor.Attribute.Name; var subscribeName = context.ConsumerDescriptor.Attribute.Name;
var subscribeGroup = context.ConsumerDescriptor.Attribute.Group; var subscribeGroup = context.ConsumerDescriptor.Attribute.Group;
var parameterValues = context.DeliverMessage.Content; var parameterValues = context.DeliverMessage.Content;
@this.Write(CapBeforePublish, new SubscriberInvokeEndEventData(operationId, operation, methodName, subscribeName, @this.Write(CapBeforePublish, new SubscriberInvokeEndEventData(operationId, operation, methodName,
subscribeName,
subscribeGroup, parameterValues, startTime, duration)); subscribeGroup, parameterValues, startTime, duration));
} }
} }
public static void WriteConsumerInvokeError(this DiagnosticListener @this, public static void WriteSubscriberInvokeError(this DiagnosticListener @this,
Guid operationId, Guid operationId,
ConsumerContext context, ConsumerContext context,
Exception ex, Exception ex,
...@@ -235,14 +212,15 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -235,14 +212,15 @@ namespace DotNetCore.CAP.Diagnostics
TimeSpan duration, TimeSpan duration,
[CallerMemberName] string operation = "") [CallerMemberName] string operation = "")
{ {
if (@this.IsEnabled(CapErrorConsumerInvoke)) if (@this.IsEnabled(CapErrorSubscriberInvoke))
{ {
var methodName = context.ConsumerDescriptor.MethodInfo.Name; var methodName = context.ConsumerDescriptor.MethodInfo.Name;
var subscribeName = context.ConsumerDescriptor.Attribute.Name; var subscribeName = context.ConsumerDescriptor.Attribute.Name;
var subscribeGroup = context.ConsumerDescriptor.Attribute.Group; var subscribeGroup = context.ConsumerDescriptor.Attribute.Group;
var parameterValues = context.DeliverMessage.Content; var parameterValues = context.DeliverMessage.Content;
@this.Write(CapBeforePublish, new SubscriberInvokeErrorEventData(operationId, operation, methodName, subscribeName, @this.Write(CapBeforePublish, new SubscriberInvokeErrorEventData(operationId, operation, methodName,
subscribeName,
subscribeGroup, parameterValues, ex, startTime, duration)); subscribeGroup, parameterValues, ex, startTime, duration));
} }
} }
......
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class BrokerConsumeEventData : BrokerEventData public class BrokerConsumeEventData : BrokerEventData
{ {
public DateTimeOffset StartTime { get; } public BrokerConsumeEventData(Guid operationId, string operation, string brokerAddress,
public BrokerConsumeEventData(Guid operationId, string operation, string groupName,
string brokerTopicName, string brokerTopicBody, DateTimeOffset startTime) string brokerTopicName, string brokerTopicBody, DateTimeOffset startTime)
: base(operationId, operation, groupName, brokerTopicName, brokerTopicBody) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody)
{ {
StartTime = startTime; StartTime = startTime;
} }
public DateTimeOffset StartTime { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class BrokerConsumeEndEventData : BrokerConsumeEventData public class BrokerConsumeEndEventData : BrokerConsumeEventData
{ {
public TimeSpan Duration { get; } public BrokerConsumeEndEventData(Guid operationId, string operation, string brokerAddress,
string brokerTopicName,
public BrokerConsumeEndEventData(Guid operationId, string operation, string groupName, string brokerTopicName,
string brokerTopicBody, DateTimeOffset startTime, TimeSpan duration) string brokerTopicBody, DateTimeOffset startTime, TimeSpan duration)
: base(operationId, operation, groupName, brokerTopicName, brokerTopicBody, startTime) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody, startTime)
{ {
Duration = duration; Duration = duration;
} }
public TimeSpan Duration { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class BrokerConsumeErrorEventData : BrokerConsumeEndEventData, IErrorEventData public class BrokerConsumeErrorEventData : BrokerConsumeEndEventData, IErrorEventData
{ {
public Exception Exception { get; } public BrokerConsumeErrorEventData(Guid operationId, string operation, string brokerAddress,
string brokerTopicName, string brokerTopicBody, Exception exception, DateTimeOffset startTime,
public BrokerConsumeErrorEventData(Guid operationId, string operation, string groupName, TimeSpan duration)
string brokerTopicName, string brokerTopicBody, Exception exception, DateTimeOffset startTime, TimeSpan duration) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody, startTime, duration)
: base(operationId, operation, groupName, brokerTopicName, brokerTopicBody, startTime, duration)
{ {
Exception = exception; Exception = exception;
} }
public Exception Exception { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class BrokerPublishEventData : BrokerEventData public class BrokerPublishEventData : BrokerEventData
{ {
public DateTimeOffset StartTime { get; } public BrokerPublishEventData(Guid operationId, string operation, string brokerAddress,
public BrokerPublishEventData(Guid operationId, string operation, string groupName,
string brokerTopicName, string brokerTopicBody, DateTimeOffset startTime) string brokerTopicName, string brokerTopicBody, DateTimeOffset startTime)
: base(operationId, operation, groupName, brokerTopicName, brokerTopicBody) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody)
{ {
StartTime = startTime; StartTime = startTime;
} }
public DateTimeOffset StartTime { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class BrokerPublishEndEventData : BrokerPublishEventData public class BrokerPublishEndEventData : BrokerPublishEventData
{ {
public TimeSpan Duration { get; } public BrokerPublishEndEventData(Guid operationId, string operation, string brokerAddress,
string brokerTopicName,
public BrokerPublishEndEventData(Guid operationId, string operation, string groupName, string brokerTopicName,
string brokerTopicBody, DateTimeOffset startTime, TimeSpan duration) string brokerTopicBody, DateTimeOffset startTime, TimeSpan duration)
: base(operationId, operation, groupName, brokerTopicName, brokerTopicBody, startTime) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody, startTime)
{ {
Duration = duration; Duration = duration;
} }
public TimeSpan Duration { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class BrokerPublishErrorEventData : BrokerPublishEndEventData, IErrorEventData public class BrokerPublishErrorEventData : BrokerPublishEndEventData, IErrorEventData
{ {
public Exception Exception { get; } public BrokerPublishErrorEventData(Guid operationId, string operation, string brokerAddress,
string brokerTopicName, string brokerTopicBody, Exception exception, DateTimeOffset startTime,
public BrokerPublishErrorEventData(Guid operationId, string operation, string groupName, TimeSpan duration)
string brokerTopicName, string brokerTopicBody, Exception exception, DateTimeOffset startTime, TimeSpan duration) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody, startTime, duration)
: base(operationId, operation, groupName, brokerTopicName, brokerTopicBody, startTime, duration)
{ {
Exception = exception; Exception = exception;
} }
public Exception Exception { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class BrokerEventData : EventData public class BrokerEventData : EventData
{ {
public string GroupName { get; set; } public BrokerEventData(Guid operationId, string operation, string brokerAddress,
public string BrokerTopicBody { get; set; }
public string BrokerTopicName { get; set; }
public BrokerEventData(Guid operationId, string operation, string groupName,
string brokerTopicName, string brokerTopicBody) string brokerTopicName, string brokerTopicBody)
: base(operationId, operation) : base(operationId, operation)
{ {
GroupName = groupName; Headers = new TracingHeaders();
BrokerAddress = brokerAddress;
BrokerTopicName = brokerTopicName; BrokerTopicName = brokerTopicName;
BrokerTopicBody = brokerTopicBody; BrokerTopicBody = brokerTopicBody;
} }
public TracingHeaders Headers { get; set; }
public string BrokerAddress { get; set; }
public string BrokerTopicBody { get; set; }
public string BrokerTopicName { get; set; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class SubscriberInvokeEventData : EventData public class SubscriberInvokeEventData : EventData
{ {
public DateTimeOffset StartTime { get; }
public string MethodName { get; set; }
public string SubscribeName { get; set; }
public string SubscribeGroup { get; set; }
public string ParameterValues { get; set; }
public SubscriberInvokeEventData(Guid operationId, public SubscriberInvokeEventData(Guid operationId,
string operation, string operation,
string methodName, string methodName,
...@@ -29,5 +22,15 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -29,5 +22,15 @@ namespace DotNetCore.CAP.Diagnostics
ParameterValues = parameterValues; ParameterValues = parameterValues;
StartTime = startTime; StartTime = startTime;
} }
public DateTimeOffset StartTime { get; }
public string MethodName { get; set; }
public string SubscribeName { get; set; }
public string SubscribeGroup { get; set; }
public string ParameterValues { get; set; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class SubscriberInvokeEndEventData : SubscriberInvokeEventData public class SubscriberInvokeEndEventData : SubscriberInvokeEventData
{ {
public TimeSpan Duration { get; }
public SubscriberInvokeEndEventData(Guid operationId, string operation, public SubscriberInvokeEndEventData(Guid operationId, string operation,
string methodName, string subscribeName, string subscribeGroup, string methodName, string subscribeName, string subscribeGroup,
string parameterValues, DateTimeOffset startTime, TimeSpan duration) string parameterValues, DateTimeOffset startTime, TimeSpan duration)
...@@ -13,5 +14,7 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -13,5 +14,7 @@ namespace DotNetCore.CAP.Diagnostics
{ {
Duration = duration; Duration = duration;
} }
public TimeSpan Duration { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
public class SubscriberInvokeErrorEventData : SubscriberInvokeEndEventData, IErrorEventData public class SubscriberInvokeErrorEventData : SubscriberInvokeEndEventData, IErrorEventData
{ {
public Exception Exception { get; }
public SubscriberInvokeErrorEventData(Guid operationId, string operation, string methodName, public SubscriberInvokeErrorEventData(Guid operationId, string operation, string methodName,
string subscribeName, string subscribeGroup, string parameterValues, Exception exception, string subscribeName, string subscribeGroup, string parameterValues, Exception exception,
DateTimeOffset startTime, TimeSpan duration) : base(operationId, operation, methodName, subscribeName, DateTimeOffset startTime, TimeSpan duration) : base(operationId, operation, methodName, subscribeName,
...@@ -13,5 +14,7 @@ namespace DotNetCore.CAP.Diagnostics ...@@ -13,5 +14,7 @@ namespace DotNetCore.CAP.Diagnostics
{ {
Exception = exception; Exception = exception;
} }
public Exception Exception { get; }
} }
} }
\ No newline at end of file
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
......
using System; // Copyright (c) .NET Core Community. All rights reserved.
using System.Collections.Generic; // Licensed under the MIT License. See License.txt in the project root for license information.
using System.Text;
using System;
namespace DotNetCore.CAP.Diagnostics namespace DotNetCore.CAP.Diagnostics
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment