Skip to content

Commit b83742d

Browse files
authored
Log warning when trace buffer overflow occurs. (#8712)
1 parent c4bd105 commit b83742d

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

dd-trace-core/src/main/java/datadog/trace/common/writer/RemoteWriter.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package datadog.trace.common.writer;
22

33
import static datadog.trace.api.sampling.PrioritySampling.UNSET;
4+
import static java.util.concurrent.TimeUnit.MINUTES;
45

56
import datadog.trace.core.DDSpan;
67
import datadog.trace.core.monitor.HealthMetrics;
8+
import datadog.trace.relocate.api.RatelimitedLogger;
79
import java.util.Collection;
810
import java.util.List;
911
import java.util.concurrent.TimeUnit;
@@ -28,6 +30,8 @@ public abstract class RemoteWriter implements Writer {
2830

2931
private static final Logger log = LoggerFactory.getLogger(RemoteWriter.class);
3032

33+
private final RatelimitedLogger rlLog = new RatelimitedLogger(log, 1, MINUTES);
34+
3135
protected final TraceProcessingWorker traceProcessingWorker;
3236
private final PayloadDispatcher dispatcher;
3337
private final boolean alwaysFlush;
@@ -63,10 +67,14 @@ protected RemoteWriter(
6367

6468
@Override
6569
public void write(final List<DDSpan> trace) {
66-
// We can't add events after shutdown otherwise it will never complete shutting down.
67-
if (!closed) {
70+
if (closed) {
71+
// We can't add events after shutdown otherwise it will never complete shutting down.
72+
log.debug("Dropped due to shutdown: {}", trace);
73+
handleDroppedTrace(trace);
74+
} else {
6875
if (trace.isEmpty()) {
69-
handleDroppedTrace("Trace was empty", trace, UNSET);
76+
log.debug("Dropped an empty trace.");
77+
handleDroppedTrace(trace);
7078
} else {
7179
final DDSpan root = trace.get(0);
7280
final int samplingPriority = root.samplingPriority();
@@ -79,26 +87,28 @@ public void write(final List<DDSpan> trace) {
7987
log.debug("Enqueued for single span sampling: {}", trace);
8088
break;
8189
case DROPPED_BY_POLICY:
82-
handleDroppedTrace("Dropping policy is active", trace, samplingPriority);
90+
log.debug("Dropped by the policy: {}", trace);
91+
handleDroppedTrace(trace);
8392
break;
8493
case DROPPED_BUFFER_OVERFLOW:
85-
handleDroppedTrace("Trace written to overfilled buffer", trace, samplingPriority);
94+
if (log.isDebugEnabled()) {
95+
log.debug("Dropped due to a buffer overflow: {}", trace);
96+
} else {
97+
rlLog.warn("Dropped due to a buffer overflow: [{} spans]", trace.size());
98+
}
99+
handleDroppedTrace(trace);
86100
break;
87101
}
88102
}
89-
} else {
90-
handleDroppedTrace("Trace written after shutdown.", trace, UNSET);
91103
}
92104
if (alwaysFlush) {
93105
flush();
94106
}
95107
}
96108

97-
private void handleDroppedTrace(
98-
final String reason, final List<DDSpan> trace, final int samplingPriority) {
99-
log.debug("{}. Counted but dropping trace: {}", reason, trace);
100-
healthMetrics.onFailedPublish(
101-
trace.isEmpty() ? 0 : trace.get(0).samplingPriority(), trace.size());
109+
private void handleDroppedTrace(final List<DDSpan> trace) {
110+
int samplingPriority = trace.isEmpty() ? UNSET : trace.get(0).samplingPriority();
111+
healthMetrics.onFailedPublish(samplingPriority, trace.size());
102112
incrementDropCounts(trace.size());
103113
}
104114

0 commit comments

Comments
 (0)