@@ -4,7 +4,10 @@ import datadog.trace.common.sampling.SingleSpanSampler
4
4
import datadog.trace.common.writer.ddagent.PrioritizationStrategy.PublishResult
5
5
import datadog.trace.core.CoreSpan
6
6
import datadog.trace.core.DDSpan
7
+ import datadog.trace.core.DDSpanContext
8
+ import datadog.trace.core.PendingTrace
7
9
import datadog.trace.core.monitor.HealthMetrics
10
+ import datadog.trace.core.postprocessor.SpanPostProcessor
8
11
import datadog.trace.test.util.DDSpecification
9
12
import spock.util.concurrent.PollingConditions
10
13
@@ -41,6 +44,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
41
44
FAST_LANE ,
42
45
1 ,
43
46
TimeUnit . NANOSECONDS ,
47
+ null ,
44
48
null
45
49
) // stop heartbeats from being throttled
46
50
@@ -67,6 +71,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
67
71
FAST_LANE ,
68
72
1 ,
69
73
TimeUnit . NANOSECONDS ,
74
+ null ,
70
75
null
71
76
) // stop heartbeats from being throttled
72
77
def timeConditions = new PollingConditions (timeout : 1 , initialDelay : 1 , factor : 1.25 )
@@ -92,7 +97,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
92
97
false
93
98
},
94
99
FAST_LANE ,
95
- 100 , TimeUnit . SECONDS , null ) // prevent heartbeats from helping the flush happen
100
+ 100 , TimeUnit . SECONDS , null , null ) // prevent heartbeats from helping the flush happen
96
101
97
102
when : " there is pending work it is completed before a flush"
98
103
// processing this span will throw an exception, but it should be caught
@@ -131,7 +136,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
131
136
throwingDispatcher, {
132
137
false
133
138
}, FAST_LANE ,
134
- 100 , TimeUnit . SECONDS , null ) // prevent heartbeats from helping the flush happen
139
+ 100 , TimeUnit . SECONDS , null , null ) // prevent heartbeats from helping the flush happen
135
140
worker. start()
136
141
137
142
when : " a trace is processed but can't be passed on"
@@ -149,6 +154,58 @@ class TraceProcessingWorkerTest extends DDSpecification {
149
154
priority << [SAMPLER_DROP , USER_DROP , SAMPLER_KEEP , USER_KEEP , UNSET ]
150
155
}
151
156
157
+ def " trace should be post-processed" () {
158
+ setup :
159
+ AtomicInteger acceptedCount = new AtomicInteger ()
160
+ PayloadDispatcherImpl countingDispatcher = Mock (PayloadDispatcherImpl )
161
+ countingDispatcher. addTrace(_) >> {
162
+ acceptedCount. getAndIncrement()
163
+ }
164
+ HealthMetrics healthMetrics = Mock (HealthMetrics )
165
+
166
+ // Span 1 - should be post-processed
167
+ def span1 = DDSpan . create(" test" , 0 , Mock (DDSpanContext ) {
168
+ isRequiresPostProcessing() >> true
169
+ getTrace() >> Mock (PendingTrace ) {
170
+ getCurrentTimeNano() >> 0
171
+ }
172
+ }, [])
173
+ def processedSpan1 = false
174
+
175
+ // Span 2 - should NOT be post-processed
176
+ def span2 = DDSpan . create(" test" , 0 , Mock (DDSpanContext ) {
177
+ isRequiresPostProcessing() >> false
178
+ getTrace() >> Mock (PendingTrace ) {
179
+ getCurrentTimeNano() >> 0
180
+ }
181
+ }, [])
182
+ def processedSpan2 = false
183
+
184
+ SpanPostProcessor spanPostProcessor = Mock (SpanPostProcessor ) {
185
+ process(span1, _) >> { processedSpan1 = true }
186
+ process(span2, _) >> { processedSpan2 = true }
187
+ }
188
+
189
+ TraceProcessingWorker worker = new TraceProcessingWorker (10 , healthMetrics,
190
+ countingDispatcher, {
191
+ false
192
+ }, FAST_LANE , 100 , TimeUnit . SECONDS , null , spanPostProcessor)
193
+ worker. start()
194
+
195
+ when : " traces are submitted"
196
+ worker. publish(span1, SAMPLER_KEEP , [span1, span2])
197
+ worker. publish(span2, SAMPLER_KEEP , [span1, span2])
198
+
199
+ then : " traces are passed through unless rejected on submission"
200
+ conditions. eventually {
201
+ assert processedSpan1 == true
202
+ assert processedSpan2 == false
203
+ }
204
+
205
+ cleanup :
206
+ worker. close()
207
+ }
208
+
152
209
def " traces should be processed" () {
153
210
setup :
154
211
AtomicInteger acceptedCount = new AtomicInteger ()
@@ -160,7 +217,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
160
217
TraceProcessingWorker worker = new TraceProcessingWorker (10 , healthMetrics,
161
218
countingDispatcher, {
162
219
false
163
- }, FAST_LANE , 100 , TimeUnit . SECONDS , null )
220
+ }, FAST_LANE , 100 , TimeUnit . SECONDS , null , null )
164
221
// prevent heartbeats from helping the flush happen
165
222
worker. start()
166
223
@@ -211,7 +268,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
211
268
TraceProcessingWorker worker = new TraceProcessingWorker (10 , healthMetrics,
212
269
countingDispatcher, {
213
270
false
214
- }, FAST_LANE , 100 , TimeUnit . SECONDS , null )
271
+ }, FAST_LANE , 100 , TimeUnit . SECONDS , null , null )
215
272
worker. start()
216
273
worker. close()
217
274
int queueSize = 0
@@ -248,7 +305,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
248
305
return false
249
306
}
250
307
}
251
- TraceProcessingWorker worker = new TraceProcessingWorker (10 , healthMetrics, countingDispatcher, { true }, FAST_LANE , 100 , TimeUnit . SECONDS , singleSpanSampler)
308
+ TraceProcessingWorker worker = new TraceProcessingWorker (10 , healthMetrics, countingDispatcher, { true }, FAST_LANE , 100 , TimeUnit . SECONDS , singleSpanSampler, null )
252
309
worker. start()
253
310
254
311
when : " traces are submitted"
@@ -324,7 +381,7 @@ class TraceProcessingWorkerTest extends DDSpecification {
324
381
return false
325
382
}
326
383
}
327
- TraceProcessingWorker worker = new TraceProcessingWorker (10 , healthMetrics, countingDispatcher, { false }, FAST_LANE , 100 , TimeUnit . SECONDS , singleSpanSampler)
384
+ TraceProcessingWorker worker = new TraceProcessingWorker (10 , healthMetrics, countingDispatcher, { false }, FAST_LANE , 100 , TimeUnit . SECONDS , singleSpanSampler, null )
328
385
worker. start()
329
386
330
387
when : " traces are submitted"
0 commit comments