Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
fa9b4a3b
Commit
fa9b4a3b
authored
Nov 26, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refacing diagnostics tracing module.
parent
828de686
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
339 additions
and
594 deletions
+339
-594
CAP.sln
CAP.sln
+2
-0
CapDiagnosticListenerNames.cs
src/DotNetCore.CAP/Diagnostics/CapDiagnosticListenerNames.cs
+31
-0
DiagnosticListenerExtensions.cs
...otNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs
+0
-229
EventData.Broker.Consume.cs
src/DotNetCore.CAP/Diagnostics/EventData.Broker.Consume.cs
+0
-27
EventData.Broker.ConsumeEnd.cs
...DotNetCore.CAP/Diagnostics/EventData.Broker.ConsumeEnd.cs
+0
-19
EventData.Broker.ConsumeError.cs
...tNetCore.CAP/Diagnostics/EventData.Broker.ConsumeError.cs
+0
-27
EventData.Broker.Publish.cs
src/DotNetCore.CAP/Diagnostics/EventData.Broker.Publish.cs
+0
-20
EventData.Broker.PublishEnd.cs
...DotNetCore.CAP/Diagnostics/EventData.Broker.PublishEnd.cs
+0
-20
EventData.Broker.PublishError.cs
...tNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs
+0
-20
EventData.Cap.P.cs
src/DotNetCore.CAP/Diagnostics/EventData.Cap.P.cs
+33
-0
EventData.Cap.S.cs
src/DotNetCore.CAP/Diagnostics/EventData.Cap.S.cs
+41
-0
EventData.SubscriberInvoke.cs
src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvoke.cs
+0
-35
EventData.SubscriberInvokeEnd.cs
...tNetCore.CAP/Diagnostics/EventData.SubscriberInvokeEnd.cs
+0
-20
EventData.SubscriberInvokeError.cs
...etCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs
+0
-20
EventData.cs
src/DotNetCore.CAP/Diagnostics/EventData.cs
+0
-20
IErrorEventData.cs
src/DotNetCore.CAP/Diagnostics/IErrorEventData.cs
+0
-12
TracingHeaders.cs
src/DotNetCore.CAP/Diagnostics/TracingHeaders.cs
+0
-44
ICapPublisher.Default.cs
src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs
+65
-6
IConsumerRegister.Default.cs
src/DotNetCore.CAP/Internal/IConsumerRegister.Default.cs
+51
-33
IMessageSender.Default.cs
src/DotNetCore.CAP/Internal/IMessageSender.Default.cs
+48
-32
ISubscriberExecutor.Default.cs
src/DotNetCore.CAP/Internal/ISubscriberExecutor.Default.cs
+68
-10
No files found.
CAP.sln
View file @
fa9b4a3b
...
@@ -128,9 +128,11 @@ Global
...
@@ -128,9 +128,11 @@ Global
{77C0AC02-C44B-49D5-B969-7D5305FC20A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77C0AC02-C44B-49D5-B969-7D5305FC20A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77C0AC02-C44B-49D5-B969-7D5305FC20A5}.Release|Any CPU.Build.0 = Release|Any CPU
{77C0AC02-C44B-49D5-B969-7D5305FC20A5}.Release|Any CPU.Build.0 = Release|Any CPU
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F}.Release|Any CPU.Build.0 = Release|Any CPU
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F}.Release|Any CPU.Build.0 = Release|Any CPU
{11563D1A-27CC-45CF-8C04-C16BCC21250A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11563D1A-27CC-45CF-8C04-C16BCC21250A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11563D1A-27CC-45CF-8C04-C16BCC21250A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11563D1A-27CC-45CF-8C04-C16BCC21250A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11563D1A-27CC-45CF-8C04-C16BCC21250A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11563D1A-27CC-45CF-8C04-C16BCC21250A}.Release|Any CPU.Build.0 = Release|Any CPU
{11563D1A-27CC-45CF-8C04-C16BCC21250A}.Release|Any CPU.Build.0 = Release|Any CPU
{63B2A464-FBEA-42FB-8EFA-98AFA39FC920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63B2A464-FBEA-42FB-8EFA-98AFA39FC920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
...
...
src/DotNetCore.CAP/Diagnostics/CapDiagnosticListenerNames.cs
0 → 100644
View file @
fa9b4a3b
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
namespace
DotNetCore.CAP.Diagnostics
{
/// <summary>
/// Extension methods on the DiagnosticListener class to log CAP data
/// </summary>
public
static
class
CapDiagnosticListenerNames
{
public
const
string
DiagnosticListenerName
=
"CapDiagnosticListener"
;
private
const
string
CapPrefix
=
"DotNetCore.CAP."
;
public
const
string
BeforePublishMessageStore
=
CapPrefix
+
"WritePublishMessageStoreBefore"
;
public
const
string
AfterPublishMessageStore
=
CapPrefix
+
"WritePublishMessageStoreAfter"
;
public
const
string
ErrorPublishMessageStore
=
CapPrefix
+
"WritePublishMessageStoreError"
;
public
const
string
BeforePublish
=
CapPrefix
+
"WritePublishBefore"
;
public
const
string
AfterPublish
=
CapPrefix
+
"WritePublishAfter"
;
public
const
string
ErrorPublish
=
CapPrefix
+
"WritePublishError"
;
public
const
string
BeforeConsume
=
CapPrefix
+
"WriteConsumeBefore"
;
public
const
string
AfterConsume
=
CapPrefix
+
"WriteConsumeAfter"
;
public
const
string
ErrorConsume
=
CapPrefix
+
"WriteConsumeError"
;
public
const
string
BeforeSubscriberInvoke
=
CapPrefix
+
"WriteSubscriberInvokeBefore"
;
public
const
string
AfterSubscriberInvoke
=
CapPrefix
+
"WriteSubscriberInvokeAfter"
;
public
const
string
ErrorSubscriberInvoke
=
CapPrefix
+
"WriteSubscriberInvokeError"
;
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs
deleted
100644 → 0
View file @
828de686
// 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.Runtime.CompilerServices
;
using
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
/// <summary>
/// Extension methods on the DiagnosticListener class to log CAP data
/// </summary>
public
static
class
CapDiagnosticListenerExtensions
{
public
const
string
DiagnosticListenerName
=
"CapDiagnosticListener"
;
private
const
string
CapPrefix
=
"DotNetCore.CAP."
;
public
const
string
CapBeforePublishMessageStore
=
CapPrefix
+
"WritePublishMessageStoreBefore"
;
public
const
string
CapAfterPublishMessageStore
=
CapPrefix
+
"WritePublishMessageStoreAfter"
;
public
const
string
CapErrorPublishMessageStore
=
CapPrefix
+
"WritePublishMessageStoreError"
;
public
const
string
CapBeforePublish
=
CapPrefix
+
"WritePublishBefore"
;
public
const
string
CapAfterPublish
=
CapPrefix
+
"WritePublishAfter"
;
public
const
string
CapErrorPublish
=
CapPrefix
+
"WritePublishError"
;
public
const
string
CapBeforeConsume
=
CapPrefix
+
"WriteConsumeBefore"
;
public
const
string
CapAfterConsume
=
CapPrefix
+
"WriteConsumeAfter"
;
public
const
string
CapErrorConsume
=
CapPrefix
+
"WriteConsumeError"
;
public
const
string
CapBeforeSubscriberInvoke
=
CapPrefix
+
"WriteSubscriberInvokeBefore"
;
public
const
string
CapAfterSubscriberInvoke
=
CapPrefix
+
"WriteSubscriberInvokeAfter"
;
public
const
string
CapErrorSubscriberInvoke
=
CapPrefix
+
"WriteSubscriberInvokeError"
;
//============================================================================
//==================== Before publish store message ====================
//============================================================================
public
static
Guid
WritePublishMessageStoreBefore
(
this
DiagnosticListener
@this
,
Message
message
,
[
CallerMemberName
]
string
operation
=
""
)
{
if
(
@this
.
IsEnabled
(
CapBeforePublishMessageStore
))
{
var
operationId
=
Guid
.
NewGuid
();
@this
.
Write
(
CapBeforePublishMessageStore
,
new
{
OperationId
=
operationId
,
Operation
=
operation
,
Message
=
message
});
return
operationId
;
}
return
Guid
.
Empty
;
}
public
static
void
WritePublishMessageStoreAfter
(
this
DiagnosticListener
@this
,
Guid
operationId
,
Message
message
,
[
CallerMemberName
]
string
operation
=
""
)
{
if
(
@this
.
IsEnabled
(
CapAfterPublishMessageStore
))
{
@this
.
Write
(
CapAfterPublishMessageStore
,
new
{
OperationId
=
operationId
,
Operation
=
operation
,
Message
=
message
,
Timestamp
=
Stopwatch
.
GetTimestamp
()
});
}
}
public
static
void
WritePublishMessageStoreError
(
this
DiagnosticListener
@this
,
Guid
operationId
,
Message
message
,
Exception
ex
,
[
CallerMemberName
]
string
operation
=
""
)
{
if
(
@this
.
IsEnabled
(
CapErrorPublishMessageStore
))
{
@this
.
Write
(
CapErrorPublishMessageStore
,
new
{
OperationId
=
operationId
,
Operation
=
operation
,
Message
=
message
,
Exception
=
ex
,
Timestamp
=
Stopwatch
.
GetTimestamp
()
});
}
}
////============================================================================
////==================== Publish ====================
////============================================================================
//public static void WritePublishBefore(this DiagnosticListener @this, BrokerPublishEventData eventData)
//{
// if (@this.IsEnabled(CapBeforePublish))
// {
// eventData.Headers = new TracingHeaders();
// @this.Write(CapBeforePublish, eventData);
// }
//}
//public static void WritePublishAfter(this DiagnosticListener @this, BrokerPublishEndEventData eventData)
//{
// if (@this.IsEnabled(CapAfterPublish))
// {
// eventData.Headers = new TracingHeaders();
// @this.Write(CapAfterPublish, eventData);
// }
//}
//public static void WritePublishError(this DiagnosticListener @this, BrokerPublishErrorEventData eventData)
//{
// if (@this.IsEnabled(CapErrorPublish))
// {
// eventData.Headers = new TracingHeaders();
// @this.Write(CapErrorPublish, eventData);
// }
//}
//============================================================================
//==================== Consume ====================
//============================================================================
//public static Guid WriteConsumeBefore(this DiagnosticListener @this, BrokerConsumeEventData eventData)
//{
// if (@this.IsEnabled(CapBeforeConsume))
// {
// eventData.Headers = new TracingHeaders();
// @this.Write(CapBeforeConsume, eventData);
// }
// return Guid.Empty;
//}
//public static void WriteConsumeAfter(this DiagnosticListener @this, BrokerConsumeEndEventData eventData)
//{
// if (@this.IsEnabled(CapAfterConsume))
// {
// eventData.Headers = new TracingHeaders();
// @this.Write(CapAfterConsume, eventData);
// }
//}
//public static void WriteConsumeError(this DiagnosticListener @this, BrokerConsumeErrorEventData eventData)
//{
// if (@this.IsEnabled(CapErrorConsume))
// {
// eventData.Headers = new TracingHeaders();
// @this.Write(CapErrorConsume, eventData);
// }
//}
//============================================================================
//==================== SubscriberInvoke ====================
//============================================================================
//public static Guid WriteSubscriberInvokeBefore(this DiagnosticListener @this,
// ConsumerContext context,
// [CallerMemberName] string operation = "")
//{
// if (@this.IsEnabled(CapBeforeSubscriberInvoke))
// {
// var operationId = Guid.NewGuid();
// var methodName = context.ConsumerDescriptor.MethodInfo.Name;
// var subscribeName = context.ConsumerDescriptor.Attribute.Name;
// var subscribeGroup = context.ConsumerDescriptor.Attribute.Group;
// var values = context.DeliverMessage.Value;
// @this.Write(CapBeforeSubscriberInvoke, new SubscriberInvokeEventData(operationId, operation, methodName,
// subscribeName,
// subscribeGroup, parameterValues, DateTimeOffset.UtcNow));
// return operationId;
// }
// return Guid.Empty;
//}
//public static void WriteSubscriberInvokeAfter(this DiagnosticListener @this,
// Guid operationId,
// ConsumerContext context,
// DateTimeOffset startTime,
// TimeSpan duration,
// [CallerMemberName] string operation = "")
//{
// if (@this.IsEnabled(CapAfterSubscriberInvoke))
// {
// var methodName = context.ConsumerDescriptor.MethodInfo.Name;
// var subscribeName = context.ConsumerDescriptor.Attribute.Name;
// var subscribeGroup = context.ConsumerDescriptor.Attribute.Group;
// var values = context.DeliverMessage.Value;
// @this.Write(CapAfterSubscriberInvoke, new SubscriberInvokeEndEventData(operationId, operation, methodName,
// subscribeName,
// subscribeGroup, parameterValues, startTime, duration));
// }
//}
//public static void WriteSubscriberInvokeError(this DiagnosticListener @this,
// Guid operationId,
// ConsumerContext context,
// Exception ex,
// DateTimeOffset startTime,
// TimeSpan duration,
// [CallerMemberName] string operation = "")
//{
// if (@this.IsEnabled(CapErrorSubscriberInvoke))
// {
// var methodName = context.ConsumerDescriptor.MethodInfo.Name;
// var subscribeName = context.ConsumerDescriptor.Attribute.Name;
// var subscribeGroup = context.ConsumerDescriptor.Attribute.Group;
// var parameterValues = context.DeliverMessage.Content;
// @this.Write(CapErrorSubscriberInvoke, new SubscriberInvokeErrorEventData(operationId, operation, methodName,
// subscribeName,
// subscribeGroup, parameterValues, ex, startTime, duration));
// }
//}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.Broker.Consume.cs
deleted
100644 → 0
View file @
828de686
// 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
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
BrokerConsumeEventData
{
public
BrokerConsumeEventData
(
Guid
operationId
,
string
brokerAddress
,
TransportMessage
message
,
DateTimeOffset
startTime
)
{
OperationId
=
operationId
;
StartTime
=
startTime
;
BrokerAddress
=
brokerAddress
;
Message
=
message
;
}
public
Guid
OperationId
{
get
;
set
;
}
public
string
BrokerAddress
{
get
;
set
;
}
public
TransportMessage
Message
{
get
;
set
;
}
public
DateTimeOffset
StartTime
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.Broker.ConsumeEnd.cs
deleted
100644 → 0
View file @
828de686
// 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
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
BrokerConsumeEndEventData
:
BrokerConsumeEventData
{
public
BrokerConsumeEndEventData
(
Guid
operationId
,
string
operation
,
string
brokerAddress
,
TransportMessage
message
,
DateTimeOffset
startTime
,
TimeSpan
duration
)
:
base
(
operationId
,
brokerAddress
,
message
,
startTime
)
{
Duration
=
duration
;
}
public
TimeSpan
Duration
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.Broker.ConsumeError.cs
deleted
100644 → 0
View file @
828de686
// 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
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
BrokerConsumeErrorEventData
:
IErrorEventData
{
public
BrokerConsumeErrorEventData
(
Guid
operationId
,
string
brokerAddress
,
TransportMessage
message
,
Exception
exception
)
{
OperationId
=
operationId
;
BrokerAddress
=
brokerAddress
;
Message
=
message
;
Exception
=
exception
;
}
public
Guid
OperationId
{
get
;
set
;
}
public
string
BrokerAddress
{
get
;
}
public
TransportMessage
Message
{
get
;
}
public
Exception
Exception
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.Broker.Publish.cs
deleted
100644 → 0
View file @
828de686
// 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
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
BrokerPublishEventData
:
BrokerEventData
{
public
BrokerPublishEventData
(
Guid
operationId
,
string
operation
,
string
brokerAddress
,
Message
message
,
DateTimeOffset
startTime
)
:
base
(
operationId
,
operation
,
brokerAddress
,
message
)
{
StartTime
=
startTime
;
}
public
DateTimeOffset
StartTime
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishEnd.cs
deleted
100644 → 0
View file @
828de686
// 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
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
BrokerPublishEndEventData
:
BrokerPublishEventData
{
public
BrokerPublishEndEventData
(
Guid
operationId
,
string
operation
,
string
brokerAddress
,
Message
message
,
DateTimeOffset
startTime
,
TimeSpan
duration
)
:
base
(
operationId
,
operation
,
brokerAddress
,
message
,
startTime
)
{
Duration
=
duration
;
}
public
TimeSpan
Duration
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs
deleted
100644 → 0
View file @
828de686
// 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
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
BrokerPublishErrorEventData
:
BrokerPublishEndEventData
,
IErrorEventData
{
public
BrokerPublishErrorEventData
(
Guid
operationId
,
string
operation
,
string
brokerAddress
,
Message
message
,
Exception
exception
,
DateTimeOffset
startTime
,
TimeSpan
duration
)
:
base
(
operationId
,
operation
,
brokerAddress
,
message
,
startTime
,
duration
)
{
Exception
=
exception
;
}
public
Exception
Exception
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.Cap.P.cs
0 → 100644
View file @
fa9b4a3b
using
System
;
using
DotNetCore.CAP.Messages
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
CapEventDataPubStore
{
public
long
?
OperationTimestamp
{
get
;
set
;
}
public
string
Operation
{
get
;
set
;
}
public
Message
Message
{
get
;
set
;
}
public
long
?
ElapsedTimeMs
{
get
;
set
;
}
public
Exception
Exception
{
get
;
set
;
}
}
public
class
CapEventDataPubSend
{
public
long
?
OperationTimestamp
{
get
;
set
;
}
public
string
Operation
{
get
;
set
;
}
public
TransportMessage
TransportMessage
{
get
;
set
;
}
public
string
BrokerAddress
{
get
;
set
;
}
public
long
?
ElapsedTimeMs
{
get
;
set
;
}
public
Exception
Exception
{
get
;
set
;
}
}
}
src/DotNetCore.CAP/Diagnostics/EventData.
Broker
.cs
→
src/DotNetCore.CAP/Diagnostics/EventData.
Cap.S
.cs
View file @
fa9b4a3b
...
@@ -2,22 +2,40 @@
...
@@ -2,22 +2,40 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
// Licensed under the MIT License. See License.txt in the project root for license information.
using
System
;
using
System
;
using
System.Reflection
;
using
DotNetCore.CAP.Messages
;
using
DotNetCore.CAP.Messages
;
using
JetBrains.Annotations
;
namespace
DotNetCore.CAP.Diagnostics
namespace
DotNetCore.CAP.Diagnostics
{
{
public
class
BrokerEventData
:
EventData
public
class
CapEventDataSubStore
{
{
public
BrokerEventData
(
Guid
operationId
,
string
operation
,
string
brokerAddress
,
Message
message
)
public
long
?
OperationTimestamp
{
get
;
set
;
}
:
base
(
operationId
,
operation
)
{
BrokerAddress
=
brokerAddress
;
Message
=
message
;
public
string
Operation
{
get
;
set
;
}
}
public
TransportMessage
TransportMessage
{
get
;
set
;
}
public
string
BrokerAddress
{
get
;
set
;
}
public
string
BrokerAddress
{
get
;
set
;
}
public
long
?
ElapsedTimeMs
{
get
;
set
;
}
public
Exception
Exception
{
get
;
set
;
}
}
public
class
CapEventDataSubExecute
{
public
long
?
OperationTimestamp
{
get
;
set
;
}
public
string
Operation
{
get
;
set
;
}
public
Message
Message
{
get
;
set
;
}
public
Message
Message
{
get
;
set
;
}
[
CanBeNull
]
public
MethodInfo
MethodInfo
{
get
;
set
;
}
public
long
?
ElapsedTimeMs
{
get
;
set
;
}
public
Exception
Exception
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvoke.cs
deleted
100644 → 0
View file @
828de686
// 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
{
public
class
SubscriberInvokeEventData
:
EventData
{
public
SubscriberInvokeEventData
(
Guid
operationId
,
string
operation
,
string
methodName
,
string
subscribeName
,
string
subscribeGroup
,
object
values
,
DateTimeOffset
startTime
)
:
base
(
operationId
,
operation
)
{
MethodName
=
methodName
;
SubscribeName
=
subscribeName
;
SubscribeGroup
=
subscribeGroup
;
StartTime
=
startTime
;
}
public
DateTimeOffset
StartTime
{
get
;
}
public
string
MethodName
{
get
;
set
;
}
public
string
SubscribeName
{
get
;
set
;
}
public
string
SubscribeGroup
{
get
;
set
;
}
public
string
Values
{
get
;
set
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeEnd.cs
deleted
100644 → 0
View file @
828de686
// 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
{
public
class
SubscriberInvokeEndEventData
:
SubscriberInvokeEventData
{
public
SubscriberInvokeEndEventData
(
Guid
operationId
,
string
operation
,
string
methodName
,
string
subscribeName
,
string
subscribeGroup
,
string
parameterValues
,
DateTimeOffset
startTime
,
TimeSpan
duration
)
:
base
(
operationId
,
operation
,
methodName
,
subscribeName
,
subscribeGroup
,
parameterValues
,
startTime
)
{
Duration
=
duration
;
}
public
TimeSpan
Duration
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs
deleted
100644 → 0
View file @
828de686
// 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
{
public
class
SubscriberInvokeErrorEventData
:
SubscriberInvokeEndEventData
,
IErrorEventData
{
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
)
{
Exception
=
exception
;
}
public
Exception
Exception
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/EventData.cs
deleted
100644 → 0
View file @
828de686
// 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
{
public
class
EventData
{
public
EventData
(
Guid
operationId
,
string
operation
)
{
OperationId
=
operationId
;
Operation
=
operation
;
}
public
Guid
OperationId
{
get
;
set
;
}
public
string
Operation
{
get
;
set
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/IErrorEventData.cs
deleted
100644 → 0
View file @
828de686
// 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
{
public
interface
IErrorEventData
{
Exception
Exception
{
get
;
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Diagnostics/TracingHeaders.cs
deleted
100644 → 0
View file @
828de686
// 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.Collections
;
using
System.Collections.Generic
;
using
System.Linq
;
namespace
DotNetCore.CAP.Diagnostics
{
public
class
TracingHeaders
:
IEnumerable
<
KeyValuePair
<
string
,
string
>>
{
private
List
<
KeyValuePair
<
string
,
string
>>
_dataStore
=
new
List
<
KeyValuePair
<
string
,
string
>>();
public
IEnumerator
<
KeyValuePair
<
string
,
string
>>
GetEnumerator
()
{
return
_dataStore
.
GetEnumerator
();
}
IEnumerator
IEnumerable
.
GetEnumerator
()
{
return
GetEnumerator
();
}
public
void
Add
(
string
name
,
string
value
)
{
_dataStore
.
Add
(
new
KeyValuePair
<
string
,
string
>(
name
,
value
));
}
public
bool
Contains
(
string
name
)
{
return
_dataStore
!=
null
&&
_dataStore
.
Any
(
x
=>
x
.
Key
==
name
);
}
public
void
Remove
(
string
name
)
{
_dataStore
?.
RemoveAll
(
x
=>
x
.
Key
==
name
);
}
public
void
Cleaar
()
{
_dataStore
?.
Clear
();
}
}
}
src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs
View file @
fa9b4a3b
...
@@ -21,7 +21,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -21,7 +21,7 @@ namespace DotNetCore.CAP.Internal
// ReSharper disable once InconsistentNaming
// ReSharper disable once InconsistentNaming
protected
static
readonly
DiagnosticListener
s_diagnosticListener
=
protected
static
readonly
DiagnosticListener
s_diagnosticListener
=
new
DiagnosticListener
(
CapDiagnosticListener
Extension
s
.
DiagnosticListenerName
);
new
DiagnosticListener
(
CapDiagnosticListener
Name
s
.
DiagnosticListenerName
);
public
CapPublisher
(
IServiceProvider
service
)
public
CapPublisher
(
IServiceProvider
service
)
{
{
...
@@ -62,16 +62,16 @@ namespace DotNetCore.CAP.Internal
...
@@ -62,16 +62,16 @@ namespace DotNetCore.CAP.Internal
var
message
=
new
Message
(
optionHeaders
,
value
);
var
message
=
new
Message
(
optionHeaders
,
value
);
var
operationId
=
default
(
Guid
)
;
long
?
tracingTimestamp
=
null
;
try
try
{
{
operationId
=
s_diagnosticListener
.
WritePublishMessageStore
Before
(
message
);
tracingTimestamp
=
Tracing
Before
(
message
);
if
(
Transaction
.
Value
?.
DbTransaction
==
null
)
if
(
Transaction
.
Value
?.
DbTransaction
==
null
)
{
{
var
mediumMessage
=
await
_storage
.
StoreMessageAsync
(
name
,
message
,
cancellationToken
:
cancellationToken
);
var
mediumMessage
=
await
_storage
.
StoreMessageAsync
(
name
,
message
,
cancellationToken
:
cancellationToken
);
s_diagnosticListener
.
WritePublishMessageStoreAfter
(
operationId
,
message
);
TracingAfter
(
tracingTimestamp
,
message
);
_dispatcher
.
EnqueueToPublish
(
mediumMessage
);
_dispatcher
.
EnqueueToPublish
(
mediumMessage
);
}
}
...
@@ -81,7 +81,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -81,7 +81,7 @@ namespace DotNetCore.CAP.Internal
var
mediumMessage
=
await
_storage
.
StoreMessageAsync
(
name
,
message
,
transaction
.
DbTransaction
,
cancellationToken
);
var
mediumMessage
=
await
_storage
.
StoreMessageAsync
(
name
,
message
,
transaction
.
DbTransaction
,
cancellationToken
);
s_diagnosticListener
.
WritePublishMessageStoreAfter
(
operationId
,
message
);
TracingAfter
(
tracingTimestamp
,
message
);
transaction
.
AddToSent
(
mediumMessage
);
transaction
.
AddToSent
(
mediumMessage
);
...
@@ -93,7 +93,8 @@ namespace DotNetCore.CAP.Internal
...
@@ -93,7 +93,8 @@ namespace DotNetCore.CAP.Internal
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
s_diagnosticListener
.
WritePublishMessageStoreError
(
operationId
,
message
,
e
);
TracingError
(
tracingTimestamp
,
message
,
e
);
throw
;
throw
;
}
}
}
}
...
@@ -113,5 +114,63 @@ namespace DotNetCore.CAP.Internal
...
@@ -113,5 +114,63 @@ namespace DotNetCore.CAP.Internal
return
PublishAsync
(
name
,
value
,
header
,
cancellationToken
);
return
PublishAsync
(
name
,
value
,
header
,
cancellationToken
);
}
}
#
region
tracing
private
long
?
TracingBefore
(
Message
message
)
{
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
BeforePublishMessageStore
))
{
var
eventData
=
new
CapEventDataPubStore
()
{
OperationTimestamp
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
(),
Operation
=
message
.
GetName
(),
Message
=
message
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
BeforePublishMessageStore
,
eventData
);
return
eventData
.
OperationTimestamp
;
}
return
null
;
}
private
void
TracingAfter
(
long
?
tracingTimestamp
,
Message
message
)
{
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
AfterPublishMessageStore
))
{
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
var
eventData
=
new
CapEventDataPubStore
()
{
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
Message
=
message
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
AfterPublishMessageStore
,
eventData
);
}
}
private
void
TracingError
(
long
?
tracingTimestamp
,
Message
message
,
Exception
ex
)
{
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
ErrorPublishMessageStore
))
{
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
var
eventData
=
new
CapEventDataPubStore
()
{
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
Message
=
message
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
,
Exception
=
ex
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
ErrorPublishMessageStore
,
eventData
);
}
}
#
endregion
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/IConsumerRegister.Default.cs
View file @
fa9b4a3b
...
@@ -37,7 +37,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -37,7 +37,7 @@ namespace DotNetCore.CAP.Internal
// diagnostics listener
// diagnostics listener
// ReSharper disable once InconsistentNaming
// ReSharper disable once InconsistentNaming
private
static
readonly
DiagnosticListener
s_diagnosticListener
=
private
static
readonly
DiagnosticListener
s_diagnosticListener
=
new
DiagnosticListener
(
CapDiagnosticListener
Extension
s
.
DiagnosticListenerName
);
new
DiagnosticListener
(
CapDiagnosticListener
Name
s
.
DiagnosticListenerName
);
public
ConsumerRegister
(
ILogger
<
ConsumerRegister
>
logger
,
public
ConsumerRegister
(
ILogger
<
ConsumerRegister
>
logger
,
IOptions
<
CapOptions
>
options
,
IOptions
<
CapOptions
>
options
,
...
@@ -152,10 +152,10 @@ namespace DotNetCore.CAP.Internal
...
@@ -152,10 +152,10 @@ namespace DotNetCore.CAP.Internal
client
.
OnMessageReceived
+=
async
(
sender
,
transportMessage
)
=>
client
.
OnMessageReceived
+=
async
(
sender
,
transportMessage
)
=>
{
{
_cts
.
Token
.
ThrowIfCancellationRequested
();
_cts
.
Token
.
ThrowIfCancellationRequested
();
Guid
?
operationId
=
null
;
long
?
tracingTimestamp
=
null
;
try
try
{
{
operationId
=
TracingBefore
(
transportMessage
);
tracingTimestamp
=
TracingBefore
(
transportMessage
,
_serverAddress
);
var
startTime
=
DateTimeOffset
.
UtcNow
;
var
startTime
=
DateTimeOffset
.
UtcNow
;
var
stopwatch
=
Stopwatch
.
StartNew
();
var
stopwatch
=
Stopwatch
.
StartNew
();
...
@@ -191,10 +191,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -191,10 +191,7 @@ namespace DotNetCore.CAP.Internal
client
.
Commit
();
client
.
Commit
();
if
(
operationId
!=
null
)
TracingAfter
(
tracingTimestamp
,
transportMessage
,
_serverAddress
);
{
TracingAfter
(
operationId
.
Value
,
message
,
startTime
,
stopwatch
.
Elapsed
);
}
}
}
else
else
{
{
...
@@ -203,10 +200,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -203,10 +200,7 @@ namespace DotNetCore.CAP.Internal
client
.
Commit
();
client
.
Commit
();
if
(
operationId
!=
null
)
TracingAfter
(
tracingTimestamp
,
transportMessage
,
_serverAddress
);
{
TracingAfter
(
operationId
.
Value
,
message
,
startTime
,
stopwatch
.
Elapsed
);
}
_dispatcher
.
EnqueueToExecute
(
mediumMessage
,
executor
);
_dispatcher
.
EnqueueToExecute
(
mediumMessage
,
executor
);
}
}
...
@@ -217,10 +211,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -217,10 +211,7 @@ namespace DotNetCore.CAP.Internal
client
.
Reject
();
client
.
Reject
();
if
(
operationId
!=
null
)
TracingError
(
tracingTimestamp
,
transportMessage
,
client
.
ServersAddress
,
e
);
{
TracingError
(
operationId
.
Value
,
transportMessage
,
e
);
}
}
}
};
};
...
@@ -258,39 +249,66 @@ namespace DotNetCore.CAP.Internal
...
@@ -258,39 +249,66 @@ namespace DotNetCore.CAP.Internal
}
}
}
}
private
Guid
?
TracingBefore
(
TransportMessage
message
)
#
region
tracing
private
long
?
TracingBefore
(
TransportMessage
message
,
string
broker
)
{
{
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListener
Extensions
.
Cap
BeforeConsume
))
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListener
Names
.
BeforeConsume
))
{
{
var
operationId
=
Guid
.
NewGuid
();
var
eventData
=
new
CapEventDataSubStore
()
{
var
eventData
=
new
BrokerConsumeEventData
(
operationId
,
_serverAddress
,
message
,
DateTimeOffset
.
UtcNow
);
OperationTimestamp
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
(),
Operation
=
message
.
GetName
(),
BrokerAddress
=
broker
,
TransportMessage
=
message
};
s_diagnosticListener
.
Write
(
CapDiagnosticListener
Extensions
.
Cap
BeforeConsume
,
eventData
);
s_diagnosticListener
.
Write
(
CapDiagnosticListener
Names
.
BeforeConsume
,
eventData
);
return
operationId
;
return
eventData
.
OperationTimestamp
;
}
}
return
null
;
return
null
;
}
}
private
void
TracingAfter
(
Guid
operationId
,
Message
message
,
DateTimeOffset
startTime
,
TimeSpan
du
)
private
void
TracingAfter
(
long
?
tracingTimestamp
,
TransportMessage
message
,
string
broker
)
{
{
//if (s_diagnosticListener.IsEnabled(CapDiagnosticListenerExtensions.CapAfterConsume))
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
AfterConsume
))
//{
{
// var eventData = new BrokerConsumeEndEventData(operationId, "", _serverAddress, message, startTime, du);
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
var
eventData
=
new
CapEventDataSubStore
()
// s_diagnosticListener.Write(CapDiagnosticListenerExtensions.CapAfterConsume, eventData);
{
//}
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
BrokerAddress
=
broker
,
TransportMessage
=
message
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
AfterConsume
,
eventData
);
}
}
}
private
void
TracingError
(
Guid
operationId
,
TransportMessage
message
,
Exception
ex
)
private
void
TracingError
(
long
?
tracingTimestamp
,
TransportMessage
message
,
string
broker
,
Exception
ex
)
{
{
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerExtensions
.
Cap
ErrorConsume
))
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
ErrorConsume
))
{
{
var
eventData
=
new
BrokerConsumeErrorEventData
(
operationId
,
_serverAddress
,
message
,
ex
);
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
s_diagnosticListener
.
Write
(
CapDiagnosticListenerExtensions
.
CapErrorConsume
,
eventData
);
var
eventData
=
new
CapEventDataPubSend
()
{
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
BrokerAddress
=
broker
,
TransportMessage
=
message
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
,
Exception
=
ex
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
ErrorConsume
,
eventData
);
}
}
}
}
#
endregion
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/IMessageSender.Default.cs
View file @
fa9b4a3b
...
@@ -25,7 +25,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -25,7 +25,7 @@ namespace DotNetCore.CAP.Internal
// ReSharper disable once InconsistentNaming
// ReSharper disable once InconsistentNaming
protected
static
readonly
DiagnosticListener
s_diagnosticListener
=
protected
static
readonly
DiagnosticListener
s_diagnosticListener
=
new
DiagnosticListener
(
CapDiagnosticListener
Extension
s
.
DiagnosticListenerName
);
new
DiagnosticListener
(
CapDiagnosticListener
Name
s
.
DiagnosticListenerName
);
public
MessageSender
(
public
MessageSender
(
ILogger
<
MessageSender
>
logger
,
ILogger
<
MessageSender
>
logger
,
...
@@ -61,32 +61,23 @@ namespace DotNetCore.CAP.Internal
...
@@ -61,32 +61,23 @@ namespace DotNetCore.CAP.Internal
private
async
Task
<(
bool
,
OperateResult
)>
SendWithoutRetryAsync
(
MediumMessage
message
)
private
async
Task
<(
bool
,
OperateResult
)>
SendWithoutRetryAsync
(
MediumMessage
message
)
{
{
var
startTime
=
DateTimeOffset
.
UtcNow
;
var
transportMsg
=
await
_serializer
.
SerializeAsync
(
message
.
Origin
);
var
stopwatch
=
Stopwatch
.
StartNew
();
var
operationId
=
TracingBefore
(
message
.
Origin
);
var
tracingTimestamp
=
TracingBefore
(
transportMsg
,
_transport
.
Address
);
var
transportMsg
=
await
_serializer
.
SerializeAsync
(
message
.
Origin
);
var
result
=
await
_transport
.
SendAsync
(
transportMsg
);
var
result
=
await
_transport
.
SendAsync
(
transportMsg
);
stopwatch
.
Stop
();
if
(
result
.
Succeeded
)
if
(
result
.
Succeeded
)
{
{
await
SetSuccessfulState
(
message
);
await
SetSuccessfulState
(
message
);
if
(
operationId
!=
null
)
TracingAfter
(
tracingTimestamp
,
transportMsg
,
_transport
.
Address
);
{
TracingAfter
(
operationId
.
Value
,
message
.
Origin
,
startTime
,
stopwatch
.
Elapsed
);
}
return
(
false
,
OperateResult
.
Success
);
return
(
false
,
OperateResult
.
Success
);
}
}
else
else
{
{
if
(
operationId
!=
null
)
TracingError
(
tracingTimestamp
,
transportMsg
,
_transport
.
Address
,
result
);
{
TracingError
(
operationId
.
Value
,
message
.
Origin
,
result
,
startTime
,
stopwatch
.
Elapsed
);
}
var
needRetry
=
await
SetFailedState
(
message
,
result
.
Exception
);
var
needRetry
=
await
SetFailedState
(
message
,
result
.
Exception
);
...
@@ -144,42 +135,67 @@ namespace DotNetCore.CAP.Internal
...
@@ -144,42 +135,67 @@ namespace DotNetCore.CAP.Internal
return
true
;
return
true
;
}
}
private
Guid
?
TracingBefore
(
Message
message
)
#
region
tracing
private
long
?
TracingBefore
(
TransportMessage
message
,
string
broker
)
{
{
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListener
Extensions
.
Cap
BeforePublish
))
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListener
Names
.
BeforePublish
))
{
{
var
operationId
=
Guid
.
NewGuid
();
var
eventData
=
new
CapEventDataPubSend
()
{
var
eventData
=
new
BrokerPublishEventData
(
operationId
,
""
,
_transport
.
Address
,
message
,
DateTimeOffset
.
UtcNow
);
OperationTimestamp
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
(),
Operation
=
message
.
GetName
(),
BrokerAddress
=
broker
,
TransportMessage
=
message
};
s_diagnosticListener
.
Write
(
CapDiagnosticListener
Extensions
.
Cap
BeforePublish
,
eventData
);
s_diagnosticListener
.
Write
(
CapDiagnosticListener
Names
.
BeforePublish
,
eventData
);
return
operationId
;
return
eventData
.
OperationTimestamp
;
}
}
return
null
;
return
null
;
}
}
private
void
TracingAfter
(
Guid
operationId
,
Message
message
,
DateTimeOffset
startTime
,
TimeSpan
du
)
private
void
TracingAfter
(
long
?
tracingTimestamp
,
TransportMessage
message
,
string
broker
)
{
{
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerExtensions
.
Cap
AfterPublish
))
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
AfterPublish
))
{
{
var
eventData
=
new
BrokerPublishEndEventData
(
operationId
,
""
,
_transport
.
Address
,
message
,
startTime
,
du
);
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
var
eventData
=
new
CapEventDataPubSend
()
s_diagnosticListener
.
Write
(
CapDiagnosticListenerExtensions
.
CapAfterPublish
,
eventData
);
{
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
BrokerAddress
=
broker
,
TransportMessage
=
message
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
AfterPublish
,
eventData
);
}
}
}
}
private
void
TracingError
(
Guid
operationId
,
Message
message
,
OperateResult
result
,
DateTimeOffset
startTime
,
TimeSpan
du
)
private
void
TracingError
(
long
?
tracingTimestamp
,
TransportMessage
message
,
string
broker
,
OperateResult
result
)
{
{
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerExtensions
.
CapAfte
rPublish
))
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
Erro
rPublish
))
{
{
var
ex
=
new
PublisherSentFailedException
(
result
.
ToString
(),
result
.
Exception
);
var
ex
=
new
PublisherSentFailedException
(
result
.
ToString
(),
result
.
Exception
);
var
eventData
=
new
BrokerPublishErrorEventData
(
operationId
,
""
,
_transport
.
Address
,
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
message
,
ex
,
startTime
,
du
);
s_diagnosticListener
.
Write
(
CapDiagnosticListenerExtensions
.
CapErrorPublish
,
eventData
);
var
eventData
=
new
CapEventDataPubSend
()
{
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
BrokerAddress
=
broker
,
TransportMessage
=
message
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
,
Exception
=
ex
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
ErrorPublish
,
eventData
);
}
}
}
}
#
endregion
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/ISubscriberExecutor.Default.cs
View file @
fa9b4a3b
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Reflection
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Diagnostics
;
using
DotNetCore.CAP.Diagnostics
;
...
@@ -26,7 +27,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -26,7 +27,7 @@ namespace DotNetCore.CAP.Internal
// diagnostics listener
// diagnostics listener
// ReSharper disable once InconsistentNaming
// ReSharper disable once InconsistentNaming
private
static
readonly
DiagnosticListener
s_diagnosticListener
=
private
static
readonly
DiagnosticListener
s_diagnosticListener
=
new
DiagnosticListener
(
CapDiagnosticListener
Extension
s
.
DiagnosticListenerName
);
new
DiagnosticListener
(
CapDiagnosticListener
Name
s
.
DiagnosticListenerName
);
public
DefaultSubscriberExecutor
(
public
DefaultSubscriberExecutor
(
ILogger
<
DefaultSubscriberExecutor
>
logger
,
ILogger
<
DefaultSubscriberExecutor
>
logger
,
...
@@ -52,6 +53,8 @@ namespace DotNetCore.CAP.Internal
...
@@ -52,6 +53,8 @@ namespace DotNetCore.CAP.Internal
$"
{
Environment
.
NewLine
}
see: https://github.com/dotnetcore/CAP/issues/63"
;
$"
{
Environment
.
NewLine
}
see: https://github.com/dotnetcore/CAP/issues/63"
;
_logger
.
LogError
(
error
);
_logger
.
LogError
(
error
);
TracingError
(
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
(),
message
.
Origin
,
null
,
new
Exception
(
error
));
return
Task
.
FromResult
(
OperateResult
.
Failed
(
new
SubscriberNotFoundException
(
error
)));
return
Task
.
FromResult
(
OperateResult
.
Failed
(
new
SubscriberNotFoundException
(
error
)));
}
}
...
@@ -168,19 +171,13 @@ namespace DotNetCore.CAP.Internal
...
@@ -168,19 +171,13 @@ namespace DotNetCore.CAP.Internal
private
async
Task
InvokeConsumerMethodAsync
(
MediumMessage
message
,
ConsumerExecutorDescriptor
descriptor
,
CancellationToken
cancellationToken
)
private
async
Task
InvokeConsumerMethodAsync
(
MediumMessage
message
,
ConsumerExecutorDescriptor
descriptor
,
CancellationToken
cancellationToken
)
{
{
var
startTime
=
DateTimeOffset
.
UtcNow
;
var
stopwatch
=
Stopwatch
.
StartNew
();
var
operationId
=
Guid
.
Empty
;
var
consumerContext
=
new
ConsumerContext
(
descriptor
,
message
.
Origin
);
var
consumerContext
=
new
ConsumerContext
(
descriptor
,
message
.
Origin
);
var
tracingTimestamp
=
TracingBefore
(
message
.
Origin
,
descriptor
.
MethodInfo
);
try
try
{
{
// operationId = s_diagnosticListener.WriteSubscriberInvokeBefore(consumerContext);
var
ret
=
await
Invoker
.
InvokeAsync
(
consumerContext
,
cancellationToken
);
var
ret
=
await
Invoker
.
InvokeAsync
(
consumerContext
,
cancellationToken
);
// s_diagnosticListener.WriteSubscriberInvokeAfter(operationId, consumerContext, startTime,stopwatch.Elapsed
);
TracingAfter
(
tracingTimestamp
,
message
.
Origin
,
descriptor
.
MethodInfo
);
if
(!
string
.
IsNullOrEmpty
(
ret
.
CallbackName
))
if
(!
string
.
IsNullOrEmpty
(
ret
.
CallbackName
))
{
{
...
@@ -199,10 +196,71 @@ namespace DotNetCore.CAP.Internal
...
@@ -199,10 +196,71 @@ namespace DotNetCore.CAP.Internal
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
// s_diagnosticListener.WriteSubscriberInvokeError(operationId, consumerContext, ex, startTime, stopwatch.Elapsed
);
TracingError
(
tracingTimestamp
,
message
.
Origin
,
descriptor
.
MethodInfo
,
ex
);
throw
new
SubscriberExecutionFailedException
(
ex
.
Message
,
ex
);
throw
new
SubscriberExecutionFailedException
(
ex
.
Message
,
ex
);
}
}
}
}
#
region
tracing
private
long
?
TracingBefore
(
Message
message
,
MethodInfo
method
)
{
if
(
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
BeforeSubscriberInvoke
))
{
var
eventData
=
new
CapEventDataSubExecute
()
{
OperationTimestamp
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
(),
Operation
=
message
.
GetName
(),
Message
=
message
,
MethodInfo
=
method
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
BeforeSubscriberInvoke
,
eventData
);
return
eventData
.
OperationTimestamp
;
}
return
null
;
}
private
void
TracingAfter
(
long
?
tracingTimestamp
,
Message
message
,
MethodInfo
method
)
{
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
AfterSubscriberInvoke
))
{
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
var
eventData
=
new
CapEventDataSubExecute
()
{
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
Message
=
message
,
MethodInfo
=
method
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
AfterSubscriberInvoke
,
eventData
);
}
}
private
void
TracingError
(
long
?
tracingTimestamp
,
Message
message
,
MethodInfo
method
,
Exception
ex
)
{
if
(
tracingTimestamp
!=
null
&&
s_diagnosticListener
.
IsEnabled
(
CapDiagnosticListenerNames
.
ErrorSubscriberInvoke
))
{
var
now
=
DateTimeOffset
.
UtcNow
.
ToUnixTimeMilliseconds
();
var
eventData
=
new
CapEventDataSubExecute
()
{
OperationTimestamp
=
now
,
Operation
=
message
.
GetName
(),
Message
=
message
,
MethodInfo
=
method
,
ElapsedTimeMs
=
now
-
tracingTimestamp
.
Value
,
Exception
=
ex
};
s_diagnosticListener
.
Write
(
CapDiagnosticListenerNames
.
ErrorSubscriberInvoke
,
eventData
);
}
}
#
endregion
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment