Skip to content

Commit 29b9da5

Browse files
author
Andrew Kent
committed
Add getRootSpan() to MutableSpan
1 parent f833218 commit 29b9da5

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

dd-trace-api/src/main/java/datadog/trace/api/interceptor/MutableSpan.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ public interface MutableSpan {
4141
Boolean isError();
4242

4343
MutableSpan setError(boolean value);
44+
45+
MutableSpan getRootSpan();
4446
}

dd-trace-ot/src/main/java/datadog/opentracing/DDSpan.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ public DDSpan setError(final boolean error) {
125125
return this;
126126
}
127127

128+
@Override
129+
public MutableSpan getRootSpan() {
130+
return context().getTrace().getRootSpan();
131+
}
132+
128133
public void setErrorMeta(final Throwable error) {
129134
setError(true);
130135

dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanTest.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,18 @@ class DDSpanTest extends Specification {
183183
child2.getMetrics().get(DDSpanContext.PRIORITY_SAMPLING_KEY) == null
184184
child2.getMetrics().get(DDSpanContext.SAMPLE_RATE_KEY) == null
185185
}
186+
187+
def "getRootSpan returns the root span"() {
188+
setup:
189+
def root = tracer.buildSpan("root").start()
190+
def child = tracer.buildSpan("child").asChildOf(root).start()
191+
192+
expect:
193+
root.getRootSpan() == root
194+
child.getRootSpan() == root
195+
196+
cleanup:
197+
child.finish()
198+
root.finish()
199+
}
186200
}

0 commit comments

Comments
 (0)