@@ -28,6 +28,7 @@ public class TracerHealthMetrics extends HealthMetrics implements AutoCloseable
28
28
httpStatus -> new String [] {"status:" + httpStatus };
29
29
30
30
private static final String [] NO_TAGS = new String [0 ];
31
+ private static final String [] STATUS_OK_TAGS = STATUS_TAGS .apply (200 );
31
32
private final RadixTreeCache <String []> statusTagsCache =
32
33
new RadixTreeCache <>(16 , 32 , STATUS_TAGS , 200 , 400 );
33
34
@@ -62,6 +63,8 @@ public class TracerHealthMetrics extends HealthMetrics implements AutoCloseable
62
63
63
64
private final FixedSizeStripedLongCounter enqueuedSpans =
64
65
CountersFactory .createFixedSizeStripedCounter (8 );
66
+ private final FixedSizeStripedLongCounter enqueuedBytes =
67
+ CountersFactory .createFixedSizeStripedCounter (8 );
65
68
private final FixedSizeStripedLongCounter singleSpanSampled =
66
69
CountersFactory .createFixedSizeStripedCounter (8 );
67
70
private final FixedSizeStripedLongCounter singleSpanUnsampled =
@@ -84,8 +87,6 @@ public class TracerHealthMetrics extends HealthMetrics implements AutoCloseable
84
87
CountersFactory .createFixedSizeStripedCounter (8 );
85
88
private final FixedSizeStripedLongCounter unsetPriorityFailedPublishSpanCount =
86
89
CountersFactory .createFixedSizeStripedCounter (8 );
87
- private final FixedSizeStripedLongCounter sampledSpans =
88
- CountersFactory .createFixedSizeStripedCounter (8 );
89
90
private final FixedSizeStripedLongCounter manualTraces =
90
91
CountersFactory .createFixedSizeStripedCounter (8 );
91
92
private final FixedSizeStripedLongCounter capturedContinuations =
@@ -102,6 +103,8 @@ public class TracerHealthMetrics extends HealthMetrics implements AutoCloseable
102
103
CountersFactory .createFixedSizeStripedCounter (8 );
103
104
private final FixedSizeStripedLongCounter partialTraces =
104
105
CountersFactory .createFixedSizeStripedCounter (8 );
106
+ private final FixedSizeStripedLongCounter partialBytes =
107
+ CountersFactory .createFixedSizeStripedCounter (8 );
105
108
private final FixedSizeStripedLongCounter clientSpansWithoutContext =
106
109
CountersFactory .createFixedSizeStripedCounter (8 );
107
110
private final FixedSizeStripedLongCounter longRunningTracesWrite =
@@ -111,6 +114,21 @@ public class TracerHealthMetrics extends HealthMetrics implements AutoCloseable
111
114
private final FixedSizeStripedLongCounter longRunningTracesExpired =
112
115
CountersFactory .createFixedSizeStripedCounter (8 );
113
116
117
+ private final FixedSizeStripedLongCounter apiRequests =
118
+ CountersFactory .createFixedSizeStripedCounter (8 );
119
+ private final FixedSizeStripedLongCounter apiResponsesOK =
120
+ CountersFactory .createFixedSizeStripedCounter (8 );
121
+ private final FixedSizeStripedLongCounter apiErrors =
122
+ CountersFactory .createFixedSizeStripedCounter (8 );
123
+ private final FixedSizeStripedLongCounter flushedTraces =
124
+ CountersFactory .createFixedSizeStripedCounter (8 );
125
+ private final FixedSizeStripedLongCounter flushedBytes =
126
+ CountersFactory .createFixedSizeStripedCounter (8 );
127
+ private final FixedSizeStripedLongCounter scopeCloseErrors =
128
+ CountersFactory .createFixedSizeStripedCounter (8 );
129
+ private final FixedSizeStripedLongCounter userScopeCloseErrors =
130
+ CountersFactory .createFixedSizeStripedCounter (8 );
131
+
114
132
private final StatsDClient statsd ;
115
133
private final long interval ;
116
134
private final TimeUnit units ;
@@ -216,7 +234,7 @@ public void onFlush(final boolean early) {}
216
234
217
235
@ Override
218
236
public void onPartialFlush (final int sizeInBytes ) {
219
- statsd . count ( "span.flushed.partial" , sizeInBytes , NO_TAGS );
237
+ partialBytes . inc ( sizeInBytes );
220
238
}
221
239
222
240
@ Override
@@ -233,7 +251,7 @@ public void onSingleSpanUnsampled() {
233
251
public void onSerialize (final int serializedSizeInBytes ) {
234
252
// DQH - Because of Java tracer's 2 phase acceptance and serialization scheme, this doesn't
235
253
// map precisely
236
- statsd . count ( "queue.enqueued.bytes" , serializedSizeInBytes , NO_TAGS );
254
+ enqueuedBytes . inc ( serializedSizeInBytes );
237
255
}
238
256
239
257
@ Override
@@ -266,9 +284,9 @@ public void onCreateManualTrace() {
266
284
267
285
@ Override
268
286
public void onScopeCloseError (int scopeSource ) {
269
- statsd . incrementCounter ( "scope.close.error" , NO_TAGS );
287
+ scopeCloseErrors . inc ( );
270
288
if (scopeSource == ScopeSource .MANUAL .id ()) {
271
- statsd . incrementCounter ( "scope.user.close.error" , NO_TAGS );
289
+ userScopeCloseErrors . inc ( );
272
290
}
273
291
}
274
292
@@ -323,19 +341,24 @@ public void onLongRunningUpdate(final int dropped, final int write, final int ex
323
341
324
342
private void onSendAttempt (
325
343
final int traceCount , final int sizeInBytes , final RemoteApi .Response response ) {
326
- statsd . incrementCounter ( "api.requests.total" , NO_TAGS );
327
- statsd . count ( "flush.traces.total" , traceCount , NO_TAGS );
344
+ apiRequests . inc ( );
345
+ flushedTraces . inc ( traceCount );
328
346
// TODO: missing queue.spans (# of spans being sent)
329
- statsd . count ( "flush.bytes.total" , sizeInBytes , NO_TAGS );
347
+ flushedBytes . inc ( sizeInBytes );
330
348
331
349
if (response .exception () != null ) {
332
350
// covers communication errors -- both not receiving a response or
333
351
// receiving malformed response (even when otherwise successful)
334
- statsd . incrementCounter ( "api.errors.total" , NO_TAGS );
352
+ apiErrors . inc ( );
335
353
}
336
354
337
- if (response .status () != null ) {
338
- statsd .incrementCounter ("api.responses.total" , statusTagsCache .get (response .status ()));
355
+ Integer status = response .status ();
356
+ if (status != null ) {
357
+ if (200 == status ) {
358
+ apiResponsesOK .inc ();
359
+ } else {
360
+ statsd .incrementCounter ("api.responses.total" , statusTagsCache .get (status ));
361
+ }
339
362
}
340
363
}
341
364
@@ -415,6 +438,7 @@ public void run(TracerHealthMetrics target) {
415
438
target .userDropFailedPublishSpanCount ,
416
439
USER_DROP_TAG );
417
440
reportIfChanged (target .statsd , "queue.enqueued.spans" , target .enqueuedSpans , NO_TAGS );
441
+ reportIfChanged (target .statsd , "queue.enqueued.bytes" , target .enqueuedBytes , NO_TAGS );
418
442
reportIfChanged (target .statsd , "trace.pending.created" , target .createdTraces , NO_TAGS );
419
443
reportIfChanged (target .statsd , "span.pending.created" , target .createdSpans , NO_TAGS );
420
444
reportIfChanged (target .statsd , "span.pending.finished" , target .finishedSpans , NO_TAGS );
@@ -424,6 +448,7 @@ public void run(TracerHealthMetrics target) {
424
448
reportIfChanged (
425
449
target .statsd , "span.continuations.finished" , target .finishedContinuations , NO_TAGS );
426
450
reportIfChanged (target .statsd , "queue.partial.traces" , target .partialTraces , NO_TAGS );
451
+ reportIfChanged (target .statsd , "span.flushed.partial" , target .partialBytes , NO_TAGS );
427
452
reportIfChanged (
428
453
target .statsd , "span.client.no-context" , target .clientSpansWithoutContext , NO_TAGS );
429
454
reportIfChanged (
@@ -442,6 +467,16 @@ public void run(TracerHealthMetrics target) {
442
467
target .statsd , "long-running.dropped" , target .longRunningTracesDropped , NO_TAGS );
443
468
reportIfChanged (
444
469
target .statsd , "long-running.expired" , target .longRunningTracesExpired , NO_TAGS );
470
+
471
+ reportIfChanged (target .statsd , "api.requests.total" , target .apiRequests , NO_TAGS );
472
+ reportIfChanged (target .statsd , "api.errors.total" , target .apiErrors , NO_TAGS );
473
+ // non-OK responses are reported immediately in onSendAttempt with different status tags
474
+ reportIfChanged (target .statsd , "api.responses.total" , target .apiResponsesOK , STATUS_OK_TAGS );
475
+ reportIfChanged (target .statsd , "flush.traces.total" , target .flushedTraces , NO_TAGS );
476
+ reportIfChanged (target .statsd , "flush.bytes.total" , target .flushedBytes , NO_TAGS );
477
+ reportIfChanged (target .statsd , "scope.close.error" , target .scopeCloseErrors , NO_TAGS );
478
+ reportIfChanged (
479
+ target .statsd , "scope.user.close.error" , target .userScopeCloseErrors , NO_TAGS );
445
480
}
446
481
447
482
private void reportIfChanged (
0 commit comments