Skip to content

Commit 37c0710

Browse files
authored
Fix remote span handling in LocalRootSpan utility (#238)
* Fix remote span handling in LocalRootSpan utility * spotless
1 parent ea5dc65 commit 37c0710

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

common/src/main/java/co/elastic/otel/common/LocalRootSpan.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ public static ReadableSpan getFor(ReadableSpan span) {
103103
* parents
104104
* <li>The provided span or one if its parents is a delayed inferred span where the parent was
105105
* provided as a remote span
106+
* <li>The provided span is a remote span
106107
* </ul>
107108
*/
108109
@Nullable
109110
public static ReadableSpan getFor(Span span) {
111+
if (span.getSpanContext().isRemote()) {
112+
return null;
113+
}
110114
return getFor((ReadableSpan) span);
111115
}
112116

common/src/test/java/co/elastic/otel/common/LocalRootSpanTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ public void checkRemoteParent() {
9797
assertThat(LocalRootSpan.getFor((ReadableSpan) span)).isSameAs(span);
9898
}
9999

100+
@Test
101+
public void checkRemoteSpan() {
102+
Map<String, String> headers = new HashMap<>();
103+
headers.put("traceparent", "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01");
104+
Context remoteParent =
105+
sdk.getPropagators()
106+
.getTextMapPropagator()
107+
.extract(Context.root(), headers, new MapGetter());
108+
109+
assertThat(LocalRootSpan.getFor(Span.fromContext(remoteParent))).isNull();
110+
}
111+
100112
@Test
101113
public void checkInferredSpanDetected() {
102114
Map<String, String> headers = new HashMap<>();

0 commit comments

Comments
 (0)