Merge pull request #462 from DataDog/ark/root-span
Add getRootSpan() to MutableSpan
This commit is contained in:
commit
79a33d7ac5
|
@ -41,4 +41,6 @@ public interface MutableSpan {
|
|||
Boolean isError();
|
||||
|
||||
MutableSpan setError(boolean value);
|
||||
|
||||
MutableSpan getRootSpan();
|
||||
}
|
||||
|
|
|
@ -125,6 +125,11 @@ public class DDSpan implements Span, MutableSpan {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableSpan getRootSpan() {
|
||||
return context().getTrace().getRootSpan();
|
||||
}
|
||||
|
||||
public void setErrorMeta(final Throwable error) {
|
||||
setError(true);
|
||||
|
||||
|
|
|
@ -40,6 +40,16 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
|||
Collections.newSetFromMap(new ConcurrentHashMap<WeakReference<?>, Boolean>());
|
||||
|
||||
private final AtomicInteger pendingReferenceCount = new AtomicInteger(0);
|
||||
/**
|
||||
* During a trace there are cases where the root span must be accessed (e.g. priority sampling and
|
||||
* trace-search tags).
|
||||
*
|
||||
* <p>Use a weak ref because we still need to handle buggy cases where the root span is not
|
||||
* correctly closed (see SpanCleaner).
|
||||
*
|
||||
* <p>The root span will be available in non-buggy cases because it has either finished and
|
||||
* strongly ref'd in this queue or is unfinished and ref'd in a ContinuableScope.
|
||||
*/
|
||||
private final AtomicReference<WeakReference<DDSpan>> rootSpan = new AtomicReference<>();
|
||||
|
||||
/** Ensure a trace is never written multiple times */
|
||||
|
|
|
@ -183,4 +183,18 @@ class DDSpanTest extends Specification {
|
|||
child2.getMetrics().get(DDSpanContext.PRIORITY_SAMPLING_KEY) == null
|
||||
child2.getMetrics().get(DDSpanContext.SAMPLE_RATE_KEY) == null
|
||||
}
|
||||
|
||||
def "getRootSpan returns the root span"() {
|
||||
setup:
|
||||
def root = tracer.buildSpan("root").start()
|
||||
def child = tracer.buildSpan("child").asChildOf(root).start()
|
||||
|
||||
expect:
|
||||
root.getRootSpan() == root
|
||||
child.getRootSpan() == root
|
||||
|
||||
cleanup:
|
||||
child.finish()
|
||||
root.finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue