Skip to content

Commit 545e3f0

Browse files
dougqhclaude
andcommitted
Guard stats telemetry drain against delta loss when the queue is full
getValueAndReset() resets a counter's delta baseline, so calling it before the offer() succeeds means a full metricsQueue silently drops that delta forever -- exactly when it matters most (telemetry backing up because the agent is unreachable). Check remainingCapacity() before reading any counter and stop the drain early instead; the untouched counters are collected on the next cycle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent d5193a2 commit 545e3f0

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public void prepareMetrics() {
7070

7171
// Collect client-side trace-stats span-collapse metrics, tagged by collapse reason.
7272
for (StatsMetrics.TaggedCounter counter : this.statsMetrics.getTaggedCounters()) {
73+
if (this.metricsQueue.remainingCapacity() == 0) {
74+
// Queue full: stop before reading any more counters. getValueAndReset() below resets the
75+
// counter's delta baseline, so resetting one we then fail to enqueue would drop that
76+
// delta for good; the untouched counters are picked up on the next collection cycle.
77+
break;
78+
}
7379
long value = counter.getValueAndReset();
7480
if (value == 0) {
7581
// Skip not updated counters

0 commit comments

Comments
 (0)