Skip to content

Commit adddafb

Browse files
committed
Allow AgentSpan to act as a primordial Context
1 parent a11c635 commit adddafb

File tree

1 file changed

+16
-1
lines changed
  • internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api

1 file changed

+16
-1
lines changed

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentSpan.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.SPAN_KEY;
44

55
import datadog.context.Context;
6+
import datadog.context.ContextKey;
67
import datadog.context.ImplicitContextKeyed;
78
import datadog.trace.api.DDTraceId;
89
import datadog.trace.api.TraceConfig;
910
import datadog.trace.api.gateway.IGSpanInfo;
1011
import datadog.trace.api.gateway.RequestContext;
1112
import datadog.trace.api.interceptor.MutableSpan;
13+
import javax.annotation.Nullable;
1214

13-
public interface AgentSpan extends MutableSpan, ImplicitContextKeyed, IGSpanInfo, WithAgentSpan {
15+
public interface AgentSpan
16+
extends MutableSpan, ImplicitContextKeyed, Context, IGSpanInfo, WithAgentSpan {
1417

1518
DDTraceId getTraceId();
1619

@@ -154,4 +157,16 @@ default AgentSpan asAgentSpan() {
154157
default Context storeInto(Context context) {
155158
return context.with(SPAN_KEY, this);
156159
}
160+
161+
@Nullable
162+
@Override
163+
default <T> T get(ContextKey<T> key) {
164+
// noinspection unchecked
165+
return SPAN_KEY == key ? (T) this : null;
166+
}
167+
168+
@Override
169+
default <T> Context with(ContextKey<T> key, @Nullable T value) {
170+
return Context.root().with(SPAN_KEY, this).with(key, value);
171+
}
157172
}

0 commit comments

Comments
 (0)