rootSpan hack for PendingTrace
This commit is contained in:
parent
6bbe611114
commit
224f65a0c2
|
@ -16,6 +16,8 @@ import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -41,6 +43,7 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
||||||
Collections.newSetFromMap(new ConcurrentHashMap<WeakReference<?>, Boolean>());
|
Collections.newSetFromMap(new ConcurrentHashMap<WeakReference<?>, Boolean>());
|
||||||
|
|
||||||
private final AtomicInteger pendingReferenceCount = new AtomicInteger(0);
|
private final AtomicInteger pendingReferenceCount = new AtomicInteger(0);
|
||||||
|
private final AtomicReference<WeakReference<DDSpan>> rootSpan = new AtomicReference<>();
|
||||||
|
|
||||||
/** Ensure a trace is never written multiple times */
|
/** Ensure a trace is never written multiple times */
|
||||||
private final AtomicBoolean isWritten = new AtomicBoolean(false);
|
private final AtomicBoolean isWritten = new AtomicBoolean(false);
|
||||||
|
@ -74,6 +77,7 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
||||||
log.debug("{} - span registered for wrong trace ({})", span, traceId);
|
log.debug("{} - span registered for wrong trace ({})", span, traceId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
rootSpan.compareAndSet(null, new WeakReference<DDSpan>(span));
|
||||||
synchronized (span) {
|
synchronized (span) {
|
||||||
if (null == span.ref) {
|
if (null == span.ref) {
|
||||||
span.ref = new WeakReference<DDSpan>(span, referenceQueue);
|
span.ref = new WeakReference<DDSpan>(span, referenceQueue);
|
||||||
|
@ -121,6 +125,11 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
||||||
expireSpan(span);
|
expireSpan(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DDSpan getRootSpan() {
|
||||||
|
WeakReference<DDSpan> rootRef = rootSpan.get();
|
||||||
|
return rootRef == null ? null : rootRef.get();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When using continuations, it's possible one may be used after all existing spans are otherwise
|
* When using continuations, it's possible one may be used after all existing spans are otherwise
|
||||||
* completed, so we need to wait till continuations are de-referenced before reporting.
|
* completed, so we need to wait till continuations are de-referenced before reporting.
|
||||||
|
|
Loading…
Reference in New Issue