@@ -15,13 +15,11 @@ internal sealed class MetricsReporter : IMetricsReporter
15
15
{
16
16
const string Version = "0.1.0" ;
17
17
18
- static readonly Meter Meter ;
18
+ static readonly Counter < int > s_messagingClientSentMessages ;
19
+ static readonly Histogram < double > s_messagingClientOperationDuration ;
19
20
20
- static readonly Counter < int > MessagingClientSentMessages ;
21
- static readonly Histogram < double > MessagingClientOperationDuration ;
22
-
23
- static readonly Counter < int > MessagingClientConsumedMessages ;
24
- static readonly Histogram < double > MessagingProcessDuration ;
21
+ static readonly Counter < int > s_messagingClientConsumedMessages ;
22
+ static readonly Histogram < double > s_messagingProcessDuration ;
25
23
26
24
readonly KeyValuePair < string , object ? >
27
25
_messagingOperationSystemTag = new ( MessagingSystem , MessagingSystemValue ) ;
@@ -48,27 +46,27 @@ internal sealed class MetricsReporter : IMetricsReporter
48
46
49
47
static MetricsReporter ( )
50
48
{
51
- Meter = new ( "RabbitMQ.Amqp" , Version ) ;
49
+ Meter meter = new ( "RabbitMQ.Amqp" , Version ) ;
52
50
53
- MessagingClientSentMessages = Meter . CreateCounter < int > (
51
+ s_messagingClientSentMessages = meter . CreateCounter < int > (
54
52
"messaging.client.sent.messages" ,
55
53
unit : "{message}" ,
56
54
description :
57
55
"Number of messages producer attempted to send to the broker." ) ;
58
56
59
- MessagingClientOperationDuration = Meter . CreateHistogram < double > (
57
+ s_messagingClientOperationDuration = meter . CreateHistogram < double > (
60
58
"messaging.client.operation.duration" ,
61
59
unit : "s" ,
62
60
description :
63
61
"Duration of messaging operation initiated by a producer or consumer client." ) ;
64
62
65
- MessagingClientConsumedMessages = Meter . CreateCounter < int > (
63
+ s_messagingClientConsumedMessages = meter . CreateCounter < int > (
66
64
"messaging.client.consumed.messages" ,
67
65
unit : "{message}" ,
68
66
description :
69
67
"Number of messages that were delivered to the application. " ) ;
70
68
71
- MessagingProcessDuration = Meter . CreateHistogram < double > (
69
+ s_messagingProcessDuration = meter . CreateHistogram < double > (
72
70
"messaging.process.duration" ,
73
71
unit : "s" ,
74
72
description :
@@ -81,17 +79,17 @@ public void ReportMessageSendSuccess(IMetricsReporter.PublisherContext context,
81
79
var serverPort = new KeyValuePair < string , object ? > ( ServerPort , context . ServerPort ) ;
82
80
var destination = new KeyValuePair < string , object ? > ( MessageDestinationName , context . Destination ) ;
83
81
84
- MessagingClientSentMessages . Add ( 1 , serverAddress , serverPort , destination , _messagingOperationSystemTag ,
82
+ s_messagingClientSentMessages . Add ( 1 , serverAddress , serverPort , destination , _messagingOperationSystemTag ,
85
83
_sendOperationType , _publishOperationName ) ;
86
84
if ( startTimestamp > 0 )
87
85
{
88
86
#if NET7_0_OR_GREATER
89
87
var duration = Stopwatch . GetElapsedTime ( startTimestamp ) ;
90
88
#else
91
89
var duration =
92
- new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * StopWatchTickFrequency ) ) ;
90
+ new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * s_stopWatchTickFrequency ) ) ;
93
91
#endif
94
- MessagingClientOperationDuration . Record ( duration . TotalSeconds , serverAddress , serverPort , destination ,
92
+ s_messagingClientOperationDuration . Record ( duration . TotalSeconds , serverAddress , serverPort , destination ,
95
93
_messagingOperationSystemTag , _sendOperationType , _publishOperationName ) ;
96
94
}
97
95
}
@@ -103,7 +101,7 @@ public void ReportMessageSendFailure(IMetricsReporter.PublisherContext context,
103
101
var serverAddress = new KeyValuePair < string , object ? > ( ServerAddress , context . ServerAddress ) ;
104
102
var serverPort = new KeyValuePair < string , object ? > ( ServerPort , context . ServerPort ) ;
105
103
var destination = new KeyValuePair < string , object ? > ( MessageDestinationName , context . Destination ) ;
106
- MessagingClientSentMessages . Add ( 1 , errorType , serverAddress , serverPort , destination ,
104
+ s_messagingClientSentMessages . Add ( 1 , errorType , serverAddress , serverPort , destination ,
107
105
_messagingOperationSystemTag , _sendOperationType , _publishOperationName ) ;
108
106
109
107
if ( startTimestamp > 0 )
@@ -112,9 +110,9 @@ public void ReportMessageSendFailure(IMetricsReporter.PublisherContext context,
112
110
var duration = Stopwatch . GetElapsedTime ( startTimestamp ) ;
113
111
#else
114
112
var duration =
115
- new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * StopWatchTickFrequency ) ) ;
113
+ new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * s_stopWatchTickFrequency ) ) ;
116
114
#endif
117
- MessagingClientOperationDuration . Record ( duration . TotalSeconds , errorType , serverAddress , serverPort ,
115
+ s_messagingClientOperationDuration . Record ( duration . TotalSeconds , errorType , serverAddress , serverPort ,
118
116
destination ,
119
117
_messagingOperationSystemTag , _sendOperationType , _publishOperationName ) ;
120
118
}
@@ -125,17 +123,17 @@ public void ReportMessageDeliverSuccess(IMetricsReporter.ConsumerContext context
125
123
var serverAddress = new KeyValuePair < string , object ? > ( ServerAddress , context . ServerAddress ) ;
126
124
var serverPort = new KeyValuePair < string , object ? > ( ServerPort , context . ServerPort ) ;
127
125
var destination = new KeyValuePair < string , object ? > ( MessageDestinationName , context . Destination ) ;
128
- MessagingClientConsumedMessages . Add ( 1 , serverAddress , serverPort , destination , _messagingOperationSystemTag ,
126
+ s_messagingClientConsumedMessages . Add ( 1 , serverAddress , serverPort , destination , _messagingOperationSystemTag ,
129
127
_processOperationType , _deliverOperationName ) ;
130
128
if ( startTimestamp > 0 )
131
129
{
132
130
#if NET7_0_OR_GREATER
133
131
var duration = Stopwatch . GetElapsedTime ( startTimestamp ) ;
134
132
#else
135
133
var duration =
136
- new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * StopWatchTickFrequency ) ) ;
134
+ new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * s_stopWatchTickFrequency ) ) ;
137
135
#endif
138
- MessagingProcessDuration . Record ( duration . TotalSeconds , serverAddress , serverPort ,
136
+ s_messagingProcessDuration . Record ( duration . TotalSeconds , serverAddress , serverPort ,
139
137
destination ,
140
138
_messagingOperationSystemTag , _sendOperationType , _publishOperationName ) ;
141
139
}
@@ -148,7 +146,7 @@ public void ReportMessageDeliverFailure(IMetricsReporter.ConsumerContext context
148
146
var serverAddress = new KeyValuePair < string , object ? > ( ServerAddress , context . ServerAddress ) ;
149
147
var serverPort = new KeyValuePair < string , object ? > ( ServerPort , context . ServerPort ) ;
150
148
var destination = new KeyValuePair < string , object ? > ( MessageDestinationName , context . Destination ) ;
151
- MessagingClientConsumedMessages . Add ( 1 , errorType , serverAddress , serverPort , destination ,
149
+ s_messagingClientConsumedMessages . Add ( 1 , errorType , serverAddress , serverPort , destination ,
152
150
_messagingOperationSystemTag ,
153
151
_processOperationType , _deliverOperationName ) ;
154
152
if ( startTimestamp > 0 )
@@ -157,9 +155,9 @@ public void ReportMessageDeliverFailure(IMetricsReporter.ConsumerContext context
157
155
var duration = Stopwatch . GetElapsedTime ( startTimestamp ) ;
158
156
#else
159
157
var duration =
160
- new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * StopWatchTickFrequency ) ) ;
158
+ new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * s_stopWatchTickFrequency ) ) ;
161
159
#endif
162
- MessagingProcessDuration . Record ( duration . TotalSeconds , errorType , serverAddress , serverPort ,
160
+ s_messagingProcessDuration . Record ( duration . TotalSeconds , errorType , serverAddress , serverPort ,
163
161
destination ,
164
162
_messagingOperationSystemTag , _sendOperationType , _publishOperationName ) ;
165
163
}
@@ -168,7 +166,7 @@ public void ReportMessageDeliverFailure(IMetricsReporter.ConsumerContext context
168
166
const long TicksPerMicrosecond = 10 ;
169
167
const long TicksPerMillisecond = TicksPerMicrosecond * 1000 ;
170
168
const long TicksPerSecond = TicksPerMillisecond * 1000 ; // 10,000,000
171
- static readonly double StopWatchTickFrequency = ( double ) TicksPerSecond / Stopwatch . Frequency ;
169
+ static readonly double s_stopWatchTickFrequency = ( double ) TicksPerSecond / Stopwatch . Frequency ;
172
170
#endif
173
171
}
174
172
#else
0 commit comments