Add getRootSpan() to MutableSpan
MODIFY
dd-trace-api/src/main/java/datadog/trace/api/interceptor/MutableSpan.java
dd-trace-api/src/main/java/datadog/trace/api/interceptor/MutableSpan.java
@@ -41,4 +41,6 @@ public interface MutableSpan {
Boolean isError();
MutableSpan setError(boolean value);
+
+ MutableSpan getRootSpan();
}

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDSpan.java
dd-trace-ot/src/main/java/datadog/opentracing/DDSpan.java
@@ -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);

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanTest.groovy
@@ -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()
+ }
}

Add getRootSpan() to MutableSpan