Handle spans registered after trace is written

Decrement the pending trace count when spans are registered after a
trace writes. Log certain pending trace messages at debug.
This commit is contained in:
Andrew Kent 2018-04-18 12:32:20 -07:00
parent c7cf1cf36d
commit bb69666e9f
2 changed files with 19 additions and 3 deletions

View File

@ -75,7 +75,7 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
public void addSpan(final DDSpan span) {
if (span.getDurationNano() == 0) {
log.warn("{} - added to trace, but not complete.", span);
log.debug("{} - added to trace, but not complete.", span);
return;
}
if (traceId != span.getTraceId()) {
@ -85,10 +85,10 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
if (!isWritten.get()) {
addFirst(span);
expireSpan(span);
} else {
log.warn("{} - finished after trace reported.", span);
log.debug("{} - finished after trace reported.", span);
}
expireSpan(span);
}
/**

View File

@ -142,4 +142,20 @@ class PendingTraceTest extends Specification {
otherTrace.weakReferences.size() == 0
otherTrace.asList() == []
}
def "child spans created after trace written" () {
setup:
rootSpan.finish()
// this shouldn't happen, but it's possible users of the api
// may incorrectly add spans after the trace is reported.
// in those cases we should still decrement the pending trace count
DDSpan childSpan = tracer.buildSpan("child").asChildOf(rootSpan).start()
childSpan.finish()
expect:
trace.pendingReferenceCount.get() == 0
trace.asList() == [rootSpan]
writer == [[rootSpan]]
}
}