@@ -13,6 +13,7 @@ class IncomingPipelineMetrics
13
13
const string TotalFailures = "nservicebus.messaging.failures" ;
14
14
const string MessageHandlerTime = "nservicebus.messaging.handler_time" ;
15
15
const string CriticalTime = "nservicebus.messaging.critical_time" ;
16
+ const string ProcessingTime = "nservicebus.messaging.processing_time" ;
16
17
const string RecoverabilityImmediate = "nservicebus.recoverability.immediate" ;
17
18
const string RecoverabilityDelayed = "nservicebus.recoverability.delayed" ;
18
19
const string RecoverabilityError = "nservicebus.recoverability.error" ;
@@ -30,6 +31,8 @@ public IncomingPipelineMetrics(IMeterFactory meterFactory, string queueName, str
30
31
"The time in seconds for the execution of the business code." ) ;
31
32
criticalTime = meter . CreateHistogram < double > ( CriticalTime , "s" ,
32
33
"The time in seconds between when the message was sent until processed by the endpoint." ) ;
34
+ processingTime = meter . CreateHistogram < double > ( ProcessingTime , "s" ,
35
+ "The time in seconds between when the message was fetched from the input queue until successfully processed by the endpoint." ) ;
33
36
totalImmediateRetries = meter . CreateCounter < long > ( RecoverabilityImmediate ,
34
37
description : "Total number of immediate retries requested." ) ;
35
38
totalDelayedRetries = meter . CreateCounter < long > ( RecoverabilityDelayed ,
@@ -47,13 +50,35 @@ public void AddDefaultIncomingPipelineMetricTags(IncomingPipelineMetricTags inco
47
50
incomingPipelineMetricsTags . Add ( MeterTags . EndpointDiscriminator , endpointDiscriminator ?? "" ) ;
48
51
}
49
52
50
- public void RecordMessageSuccessfullyProcessed ( ITransportReceiveContext context , IncomingPipelineMetricTags incomingPipelineMetricTags )
53
+ public void RecordProcessingTime ( ITransportReceiveContext context , TimeSpan elapsed )
54
+ {
55
+ if ( ! processingTime . Enabled )
56
+ {
57
+ return ;
58
+ }
59
+
60
+ var incomingPipelineMetricTags = context . Extensions . Get < IncomingPipelineMetricTags > ( ) ;
61
+
62
+ TagList tags ;
63
+ tags . Add ( new ( MeterTags . ExecutionResult , "success" ) ) ;
64
+ incomingPipelineMetricTags . ApplyTags ( ref tags , [
65
+ MeterTags . QueueName ,
66
+ MeterTags . EndpointDiscriminator ,
67
+ MeterTags . MessageType ,
68
+ MeterTags . MessageHandlerTypes ] ) ;
69
+
70
+ processingTime . Record ( elapsed . TotalSeconds , tags ) ;
71
+ }
72
+
73
+ public void RecordCriticalTimeAndTotalProcessed ( ITransportReceiveContext context )
51
74
{
52
75
if ( ! totalProcessedSuccessfully . Enabled && ! criticalTime . Enabled )
53
76
{
54
77
return ;
55
78
}
56
79
80
+ var incomingPipelineMetricTags = context . Extensions . Get < IncomingPipelineMetricTags > ( ) ;
81
+
57
82
TagList tags ;
58
83
tags . Add ( new ( MeterTags . ExecutionResult , "success" ) ) ;
59
84
incomingPipelineMetricTags . ApplyTags ( ref tags , [
@@ -66,10 +91,9 @@ public void RecordMessageSuccessfullyProcessed(ITransportReceiveContext context,
66
91
{
67
92
totalProcessedSuccessfully . Add ( 1 , tags ) ;
68
93
}
94
+ var completedAt = DateTimeOffset . UtcNow ;
69
95
if ( criticalTime . Enabled )
70
96
{
71
- var completedAt = DateTimeOffset . UtcNow ;
72
-
73
97
if ( context . Message . Headers . TryGetDeliverAt ( out var startTime )
74
98
|| context . Message . Headers . TryGetTimeSent ( out startTime ) )
75
99
{
@@ -96,7 +120,7 @@ public void RecordMessageProcessingFailure(IncomingPipelineMetricTags incomingPi
96
120
MeterTags . MessageHandlerTypes ] ) ;
97
121
totalFailures . Add ( 1 , tags ) ;
98
122
99
- // the critical time is intentionally not recorded in case of failure
123
+ // the processing and critical time are intentionally not recorded in case of failure
100
124
}
101
125
102
126
public void RecordFetchedMessage ( IncomingPipelineMetricTags incomingPipelineMetricTags )
@@ -109,7 +133,8 @@ public void RecordFetchedMessage(IncomingPipelineMetricTags incomingPipelineMetr
109
133
TagList tags ;
110
134
incomingPipelineMetricTags . ApplyTags ( ref tags , [
111
135
MeterTags . EndpointDiscriminator ,
112
- MeterTags . QueueName ] ) ;
136
+ MeterTags . QueueName ,
137
+ MeterTags . MessageType ] ) ;
113
138
114
139
totalFetched . Add ( 1 , tags ) ;
115
140
}
@@ -217,6 +242,7 @@ public void RecordSendToErrorQueue(IRecoverabilityContext recoverabilityContext)
217
242
readonly Counter < long > totalFailures ;
218
243
readonly Histogram < double > messageHandlerTime ;
219
244
readonly Histogram < double > criticalTime ;
245
+ readonly Histogram < double > processingTime ;
220
246
readonly Counter < long > totalImmediateRetries ;
221
247
readonly Counter < long > totalDelayedRetries ;
222
248
readonly Counter < long > totalSentToErrorQueue ;
0 commit comments