1
1
package datadog .trace .common .writer ;
2
2
3
3
import static datadog .trace .api .sampling .PrioritySampling .UNSET ;
4
+ import static java .util .concurrent .TimeUnit .MINUTES ;
4
5
5
6
import datadog .trace .core .DDSpan ;
6
7
import datadog .trace .core .monitor .HealthMetrics ;
8
+ import datadog .trace .relocate .api .RatelimitedLogger ;
7
9
import java .util .Collection ;
8
10
import java .util .List ;
9
11
import java .util .concurrent .TimeUnit ;
@@ -28,6 +30,8 @@ public abstract class RemoteWriter implements Writer {
28
30
29
31
private static final Logger log = LoggerFactory .getLogger (RemoteWriter .class );
30
32
33
+ private final RatelimitedLogger rlLog = new RatelimitedLogger (log , 1 , MINUTES );
34
+
31
35
protected final TraceProcessingWorker traceProcessingWorker ;
32
36
private final PayloadDispatcher dispatcher ;
33
37
private final boolean alwaysFlush ;
@@ -63,10 +67,14 @@ protected RemoteWriter(
63
67
64
68
@ Override
65
69
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 {
68
75
if (trace .isEmpty ()) {
69
- handleDroppedTrace ("Trace was empty" , trace , UNSET );
76
+ log .debug ("Dropped an empty trace." );
77
+ handleDroppedTrace (trace );
70
78
} else {
71
79
final DDSpan root = trace .get (0 );
72
80
final int samplingPriority = root .samplingPriority ();
@@ -79,26 +87,28 @@ public void write(final List<DDSpan> trace) {
79
87
log .debug ("Enqueued for single span sampling: {}" , trace );
80
88
break ;
81
89
case DROPPED_BY_POLICY :
82
- handleDroppedTrace ("Dropping policy is active" , trace , samplingPriority );
90
+ log .debug ("Dropped by the policy: {}" , trace );
91
+ handleDroppedTrace (trace );
83
92
break ;
84
93
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 );
86
100
break ;
87
101
}
88
102
}
89
- } else {
90
- handleDroppedTrace ("Trace written after shutdown." , trace , UNSET );
91
103
}
92
104
if (alwaysFlush ) {
93
105
flush ();
94
106
}
95
107
}
96
108
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 ());
102
112
incrementDropCounts (trace .size ());
103
113
}
104
114
0 commit comments