Merge pull request #290 from DataDog/ark/pending_expire
Handle spans registered after trace is written
This commit is contained in:
commit
c3feb3b878
|
@ -75,7 +75,7 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
||||||
|
|
||||||
public void addSpan(final DDSpan span) {
|
public void addSpan(final DDSpan span) {
|
||||||
if (span.getDurationNano() == 0) {
|
if (span.getDurationNano() == 0) {
|
||||||
log.warn("{} - added to trace, but not complete.", span);
|
log.debug("{} - added to trace, but not complete.", span);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (traceId != span.getTraceId()) {
|
if (traceId != span.getTraceId()) {
|
||||||
|
@ -85,10 +85,10 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
||||||
|
|
||||||
if (!isWritten.get()) {
|
if (!isWritten.get()) {
|
||||||
addFirst(span);
|
addFirst(span);
|
||||||
expireSpan(span);
|
|
||||||
} else {
|
} else {
|
||||||
log.warn("{} - finished after trace reported.", span);
|
log.debug("{} - finished after trace reported.", span);
|
||||||
}
|
}
|
||||||
|
expireSpan(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -148,4 +148,20 @@ class PendingTraceTest extends Specification {
|
||||||
otherTrace.weakReferences.size() == 0
|
otherTrace.weakReferences.size() == 0
|
||||||
otherTrace.asList() == []
|
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]]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue