Merge pull request #290 from DataDog/ark/pending_expire

Handle spans registered after trace is written
This commit is contained in:
Andrew Kent 2018-04-23 10:00:38 -07:00 committed by GitHub
commit c3feb3b878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

@ -148,4 +148,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]]
}
}