Skip to content

Commit 50247ce

Browse files
dougqhclaude
andcommitted
Guard core-metric telemetry drain against queue-full delta loss
getValueAndReset() resets a counter's delta baseline, so calling it before the offer() succeeds means a full metricsQueue silently drops that delta forever -- worst under telemetry backpressure when the agent is unreachable. In both the span-metrics and baggage collection loops, check remainingCapacity() before reading each counter and stop early instead; the untouched counters are collected on the next cycle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9c335a6 commit 50247ce

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

internal-api/src/main/java/datadog/trace/api/telemetry/CoreMetricCollector.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public void prepareMetrics() {
3535
for (SpanMetricsImpl spanMetrics : this.spanMetricRegistry.getSpanMetrics()) {
3636
String tag = INTEGRATION_NAME_TAG + spanMetrics.getInstrumentationName();
3737
for (CoreCounter counter : spanMetrics.getCounters()) {
38+
if (this.metricsQueue.remainingCapacity() == 0) {
39+
// Queue full: stop before reading any more counters. getValueAndReset() below resets the
40+
// counter's delta baseline, so resetting one we then fail to enqueue would drop that
41+
// delta for good; the untouched counters are picked up on the next collection cycle.
42+
break;
43+
}
3844
long value = counter.getValueAndReset();
3945
if (value == 0) {
4046
// Skip not updated counters
@@ -51,6 +57,12 @@ public void prepareMetrics() {
5157

5258
// Collect baggage metrics
5359
for (BaggageMetrics.TaggedCounter counter : this.baggageMetrics.getTaggedCounters()) {
60+
if (this.metricsQueue.remainingCapacity() == 0) {
61+
// Queue full: stop before reading any more counters. getValueAndReset() below resets the
62+
// counter's delta baseline, so resetting one we then fail to enqueue would drop that
63+
// delta for good; the untouched counters are picked up on the next collection cycle.
64+
break;
65+
}
5466
long value = counter.getValueAndReset();
5567
if (value == 0) {
5668
// Skip not updated counters

0 commit comments

Comments
 (0)