diff --git a/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java b/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java
index 5a237c63e6b..51239cb6ae4 100644
--- a/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java
+++ b/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java
@@ -79,20 +79,6 @@ public Span startSpan() {
: DefaultSpan.getInvalid();
}
- @Override
- public NoopSpanBuilder setParent(Span parent) {
- Utils.checkNotNull(parent, "parent");
- spanContext = parent.getContext();
- return this;
- }
-
- @Override
- public NoopSpanBuilder setParent(SpanContext remoteParent) {
- Utils.checkNotNull(remoteParent, "remoteParent");
- spanContext = remoteParent;
- return this;
- }
-
@Override
public NoopSpanBuilder setParent(Context context) {
Utils.checkNotNull(context, "context");
diff --git a/api/src/main/java/io/opentelemetry/trace/Span.java b/api/src/main/java/io/opentelemetry/trace/Span.java
index 7dc52ee7be6..0fa259d7081 100644
--- a/api/src/main/java/io/opentelemetry/trace/Span.java
+++ b/api/src/main/java/io/opentelemetry/trace/Span.java
@@ -399,51 +399,6 @@ enum Kind {
*/
interface Builder {
- /**
- * Sets the parent {@code Span} to use. If not set, the value of {@code Tracer.getCurrentSpan()}
- * at {@link #startSpan()} time will be used as parent.
- *
- *
This must be used to create a {@code Span} when manual Context propagation is used
- * OR when creating a root {@code Span} with a parent with an invalid {@link SpanContext}.
- *
- *
Observe this is the preferred method when the parent is a {@code Span} created within the
- * process. Using its {@code SpanContext} as parent remains as a valid, albeit inefficient,
- * operation.
- *
- *
If called multiple times, only the last specified value will be used. Observe that the
- * state defined by a previous call to {@link #setNoParent()} will be discarded.
- *
- * @param parent the {@code Span} used as parent.
- * @return this.
- * @throws NullPointerException if {@code parent} is {@code null}.
- * @see #setNoParent()
- * @since 0.1.0
- */
- Builder setParent(Span parent);
-
- /**
- * Sets the parent {@link SpanContext} to use. If not set, the value of {@code
- * Tracer.getCurrentSpan()} at {@link #startSpan()} time will be used as parent.
- *
- *
Similar to {@link #setParent(Span parent)} but this must be used to create a {@code
- * Span} when the parent is in a different process. This is only intended for use by RPC systems
- * or similar.
- *
- *
If no {@link SpanContext} is available, users must call {@link #setNoParent()} in order to
- * create a root {@code Span} for a new trace.
- *
- *
If called multiple times, only the last specified value will be used. Observe that the
- * state defined by a previous call to {@link #setNoParent()} will be discarded.
- *
- * @param remoteParent the {@link SpanContext} used as parent.
- * @return this.
- * @throws NullPointerException if {@code remoteParent} is {@code null}.
- * @see #setParent(Span parent)
- * @see #setNoParent()
- * @since 0.1.0
- */
- Builder setParent(SpanContext remoteParent);
-
/**
* Sets the parent to use from the specified {@code Context}. If not set, the value of {@code
* Tracer.getCurrentSpan()} at {@link #startSpan()} time will be used as parent.
diff --git a/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java b/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java
index 67eaf302808..aaeac94e475 100644
--- a/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java
+++ b/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java
@@ -82,7 +82,11 @@ void testInProcessContext() {
@Test
void testSpanContextPropagationExplicitParent() {
- Span span = defaultTracer.spanBuilder(SPAN_NAME).setParent(spanContext).startSpan();
+ Span span =
+ defaultTracer
+ .spanBuilder(SPAN_NAME)
+ .setParent(TracingContextUtils.withSpan(DefaultSpan.create(spanContext), Context.ROOT))
+ .startSpan();
assertThat(span.getContext()).isSameAs(spanContext);
}
@@ -90,7 +94,11 @@ void testSpanContextPropagationExplicitParent() {
void testSpanContextPropagation() {
DefaultSpan parent = new DefaultSpan(spanContext);
- Span span = defaultTracer.spanBuilder(SPAN_NAME).setParent(parent).startSpan();
+ Span span =
+ defaultTracer
+ .spanBuilder(SPAN_NAME)
+ .setParent(TracingContextUtils.withSpan(parent, Context.ROOT))
+ .startSpan();
assertThat(span.getContext()).isSameAs(spanContext);
}
diff --git a/api/src/test/java/io/opentelemetry/trace/SpanBuilderTest.java b/api/src/test/java/io/opentelemetry/trace/SpanBuilderTest.java
index fb298963d6d..bac804ffdd9 100644
--- a/api/src/test/java/io/opentelemetry/trace/SpanBuilderTest.java
+++ b/api/src/test/java/io/opentelemetry/trace/SpanBuilderTest.java
@@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import io.grpc.Context;
import io.opentelemetry.common.Attributes;
import io.opentelemetry.trace.Span.Kind;
import org.junit.jupiter.api.Test;
@@ -32,8 +33,8 @@ class SpanBuilderTest {
void doNotCrash_NoopImplementation() {
Span.Builder spanBuilder = tracer.spanBuilder("MySpanName");
spanBuilder.setSpanKind(Kind.SERVER);
- spanBuilder.setParent(DefaultSpan.getInvalid());
- spanBuilder.setParent(DefaultSpan.getInvalid().getContext());
+ spanBuilder.setParent(TracingContextUtils.withSpan(DefaultSpan.create(null), Context.ROOT));
+ spanBuilder.setParent(Context.ROOT);
spanBuilder.setNoParent();
spanBuilder.addLink(DefaultSpan.getInvalid().getContext());
spanBuilder.addLink(DefaultSpan.getInvalid().getContext(), Attributes.empty());
@@ -61,15 +62,9 @@ public Attributes getAttributes() {
}
@Test
- void setParent_NullSpan() {
+ void setParent_NullContext() {
Span.Builder spanBuilder = tracer.spanBuilder("MySpanName");
- assertThrows(NullPointerException.class, () -> spanBuilder.setParent((Span) null));
- }
-
- @Test
- void setParent_NullSpanContext() {
- Span.Builder spanBuilder = tracer.spanBuilder("MySpanName");
- assertThrows(NullPointerException.class, () -> spanBuilder.setParent((SpanContext) null));
+ assertThrows(NullPointerException.class, () -> spanBuilder.setParent(null));
}
@Test
diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java
index cd16949231e..2a4d4a91fb3 100644
--- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java
+++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java
@@ -21,10 +21,13 @@
import static io.opentelemetry.common.AttributesKeys.longKey;
import static io.opentelemetry.common.AttributesKeys.stringKey;
+import io.grpc.Context;
import io.opentelemetry.common.AttributeKey;
import io.opentelemetry.correlationcontext.CorrelationContext;
+import io.opentelemetry.trace.DefaultSpan;
import io.opentelemetry.trace.Span.Kind;
import io.opentelemetry.trace.Status;
+import io.opentelemetry.trace.TracingContextUtils;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer.SpanBuilder;
@@ -192,11 +195,13 @@ public Span start() {
if (ignoreActiveSpan && parentSpan == null && parentSpanContext == null) {
builder.setNoParent();
} else if (parentSpan != null) {
- builder.setParent(parentSpan.getSpan());
+ builder.setParent(TracingContextUtils.withSpan(parentSpan.getSpan(), Context.ROOT));
SpanContextShim contextShim = spanContextTable().get(parentSpan);
distContext = contextShim == null ? null : contextShim.getCorrelationContext();
} else if (parentSpanContext != null) {
- builder.setParent(parentSpanContext.getSpanContext());
+ builder.setParent(
+ TracingContextUtils.withSpan(
+ DefaultSpan.create(parentSpanContext.getSpanContext()), Context.ROOT));
distContext = parentSpanContext.getCorrelationContext();
}
diff --git a/sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/SpanBuilderSdk.java b/sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/SpanBuilderSdk.java
index 5cce20b005c..2515eebba68 100644
--- a/sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/SpanBuilderSdk.java
+++ b/sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/SpanBuilderSdk.java
@@ -58,14 +58,13 @@ final class SpanBuilderSdk implements Span.Builder {
private final IdsGenerator idsGenerator;
private final Clock clock;
- @Nullable private Span parent;
- @Nullable private SpanContext remoteParent;
+ @Nullable private Context parent;
private Kind spanKind = Kind.INTERNAL;
@Nullable private AttributesMap attributes;
@Nullable private List links;
private int totalNumberOfLinksAdded = 0;
- private ParentType parentType = ParentType.CURRENT_CONTEXT;
private long startEpochNanos = 0;
+ private boolean isRootSpan;
SpanBuilderSdk(
String spanName,
@@ -84,34 +83,18 @@ final class SpanBuilderSdk implements Span.Builder {
this.clock = clock;
}
- @Override
- public Span.Builder setParent(Span parent) {
- this.parent = Objects.requireNonNull(parent, "parent");
- this.remoteParent = null;
- this.parentType = ParentType.EXPLICIT_PARENT;
- return this;
- }
-
- @Override
- public Span.Builder setParent(SpanContext remoteParent) {
- this.remoteParent = Objects.requireNonNull(remoteParent, "remoteParent");
- this.parent = null;
- this.parentType = ParentType.EXPLICIT_REMOTE_PARENT;
- return this;
- }
-
@Override
public Span.Builder setParent(Context context) {
Objects.requireNonNull(context, "context");
- setParent(TracingContextUtils.getSpan(context));
+ this.isRootSpan = false;
+ this.parent = context;
return this;
}
@Override
public Span.Builder setNoParent() {
- this.parentType = ParentType.NO_PARENT;
+ this.isRootSpan = true;
this.parent = null;
- this.remoteParent = null;
return this;
}
@@ -206,17 +189,20 @@ public Span.Builder setStartTimestamp(long startTimestamp) {
@Override
public Span startSpan() {
- SpanContext parentContext = parent(parentType, parent, remoteParent);
+ final Context parentContext =
+ isRootSpan ? Context.ROOT : parent == null ? Context.current() : parent;
+ final Span parentSpan = TracingContextUtils.getSpan(parentContext);
+ final SpanContext parentSpanContext = parentSpan.getContext();
String traceId;
String spanId = idsGenerator.generateSpanId();
TraceState traceState = TraceState.getDefault();
- if (!parentContext.isValid()) {
+ if (!parentSpanContext.isValid()) {
// New root span.
traceId = idsGenerator.generateTraceId();
} else {
// New child span.
- traceId = parentContext.getTraceIdAsHexString();
- traceState = parentContext.getTraceState();
+ traceId = parentSpanContext.getTraceIdAsHexString();
+ traceState = parentSpanContext.getTraceState();
}
List immutableLinks =
links == null
@@ -230,7 +216,12 @@ public Span startSpan() {
traceConfig
.getSampler()
.shouldSample(
- parentContext, traceId, spanName, spanKind, immutableAttributes, immutableLinks);
+ parentSpanContext,
+ traceId,
+ spanName,
+ spanKind,
+ immutableAttributes,
+ immutableLinks);
Sampler.Decision samplingDecision = samplingResult.getDecision();
SpanContext spanContext =
@@ -263,11 +254,11 @@ public void consume(AttributeKey key, T value) {
spanName,
instrumentationLibraryInfo,
spanKind,
- parentContext.getSpanIdAsHexString(),
- parentContext.isRemote(),
+ parentSpanContext.getSpanIdAsHexString(),
+ parentSpanContext.isRemote(),
traceConfig,
spanProcessor,
- getClock(parentSpan(parentType, parent), clock),
+ getClock(parentSpan, clock),
resource,
recordedAttributes,
immutableLinks,
@@ -289,37 +280,4 @@ private static Clock getClock(Span parent, Clock clock) {
return MonotonicClock.create(clock);
}
}
-
- private static SpanContext parent(
- ParentType parentType, Span explicitParent, SpanContext remoteParent) {
- switch (parentType) {
- case NO_PARENT:
- return SpanContext.getInvalid();
- case CURRENT_CONTEXT:
- return TracingContextUtils.getCurrentSpan().getContext();
- case EXPLICIT_PARENT:
- return explicitParent.getContext();
- case EXPLICIT_REMOTE_PARENT:
- return remoteParent;
- }
- throw new IllegalStateException("Unknown parent type");
- }
-
- private static Span parentSpan(ParentType parentType, Span explicitParent) {
- switch (parentType) {
- case CURRENT_CONTEXT:
- return TracingContextUtils.getCurrentSpan();
- case EXPLICIT_PARENT:
- return explicitParent;
- default:
- return DefaultSpan.getInvalid();
- }
- }
-
- private enum ParentType {
- CURRENT_CONTEXT,
- EXPLICIT_PARENT,
- EXPLICIT_REMOTE_PARENT,
- NO_PARENT,
- }
}
diff --git a/sdk/tracing/src/test/java/io/opentelemetry/sdk/trace/SpanBuilderSdkTest.java b/sdk/tracing/src/test/java/io/opentelemetry/sdk/trace/SpanBuilderSdkTest.java
index 3ac0a9fd619..b31e31b65e2 100644
--- a/sdk/tracing/src/test/java/io/opentelemetry/sdk/trace/SpanBuilderSdkTest.java
+++ b/sdk/tracing/src/test/java/io/opentelemetry/sdk/trace/SpanBuilderSdkTest.java
@@ -74,14 +74,7 @@ void setSpanKind_null() {
@Test
void setParent_null() {
assertThrows(
- NullPointerException.class, () -> tracerSdk.spanBuilder(SPAN_NAME).setParent((Span) null));
- }
-
- @Test
- void setRemoteParent_null() {
- assertThrows(
- NullPointerException.class,
- () -> tracerSdk.spanBuilder(SPAN_NAME).setParent((SpanContext) null));
+ NullPointerException.class, () -> tracerSdk.spanBuilder(SPAN_NAME).setParent(null));
}
@Test
@@ -600,7 +593,7 @@ void noParent() {
tracerSdk
.spanBuilder(SPAN_NAME)
.setNoParent()
- .setParent(parent)
+ .setParent(Context.current())
.setNoParent()
.startSpan();
try {
@@ -623,7 +616,11 @@ void noParent_override() {
try {
RecordEventsReadableSpan span =
(RecordEventsReadableSpan)
- tracerSdk.spanBuilder(SPAN_NAME).setNoParent().setParent(parent).startSpan();
+ tracerSdk
+ .spanBuilder(SPAN_NAME)
+ .setNoParent()
+ .setParent(TracingContextUtils.withSpan(parent, Context.current()))
+ .startSpan();
try {
assertThat(span.getContext().getTraceIdAsHexString())
.isEqualTo(parent.getContext().getTraceIdAsHexString());
@@ -635,7 +632,7 @@ void noParent_override() {
tracerSdk
.spanBuilder(SPAN_NAME)
.setNoParent()
- .setParent(parent.getContext())
+ .setParent(TracingContextUtils.withSpan(parent, Context.current()))
.startSpan();
try {
assertThat(span2.getContext().getTraceIdAsHexString())
@@ -661,7 +658,7 @@ void overrideNoParent_remoteParent() {
tracerSdk
.spanBuilder(SPAN_NAME)
.setNoParent()
- .setParent(parent.getContext())
+ .setParent(TracingContextUtils.withSpan(parent, Context.current()))
.startSpan();
try {
assertThat(span.getContext().getTraceIdAsHexString())
@@ -747,7 +744,10 @@ void parent_invalidContext() {
RecordEventsReadableSpan span =
(RecordEventsReadableSpan)
- tracerSdk.spanBuilder(SPAN_NAME).setParent(parent.getContext()).startSpan();
+ tracerSdk
+ .spanBuilder(SPAN_NAME)
+ .setParent(TracingContextUtils.withSpan(parent, Context.current()))
+ .startSpan();
try {
assertThat(span.getContext().getTraceIdAsHexString())
.isNotEqualTo(parent.getContext().getTraceIdAsHexString());
@@ -768,9 +768,9 @@ void startTimestamp_null() {
@Test
void parent_clockIsSame() {
Span parent = tracerSdk.spanBuilder(SPAN_NAME).startSpan();
- try {
+ try (Scope scope = tracerSdk.withSpan(parent)) {
RecordEventsReadableSpan span =
- (RecordEventsReadableSpan) tracerSdk.spanBuilder(SPAN_NAME).setParent(parent).startSpan();
+ (RecordEventsReadableSpan) tracerSdk.spanBuilder(SPAN_NAME).startSpan();
assertThat(span.getClock()).isSameAs(((RecordEventsReadableSpan) parent).getClock());
} finally {
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/actorpropagation/Actor.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/actorpropagation/Actor.java
index a0dd0f37376..c08205039d7 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/actorpropagation/Actor.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/actorpropagation/Actor.java
@@ -16,6 +16,7 @@
package io.opentelemetry.sdk.extensions.trace.testbed.actorpropagation;
+import io.grpc.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Span.Kind;
@@ -44,7 +45,7 @@ public void close() {
}
Future> tell(final String message) {
- final Span parent = tracer.getCurrentSpan();
+ final Context parent = Context.current();
phaser.register();
return executor.submit(
() -> {
@@ -68,7 +69,7 @@ Future> tell(final String message) {
}
Future ask(final String message) {
- final Span parent = tracer.getCurrentSpan();
+ final Context parent = Context.current();
phaser.register();
return executor.submit(
() -> {
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/clientserver/Server.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/clientserver/Server.java
index 0ed2c20fa95..953ee7b257d 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/clientserver/Server.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/clientserver/Server.java
@@ -22,9 +22,7 @@
import io.opentelemetry.context.propagation.TextMapPropagator.Getter;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Span.Kind;
-import io.opentelemetry.trace.SpanContext;
import io.opentelemetry.trace.Tracer;
-import io.opentelemetry.trace.TracingContextUtils;
import java.util.concurrent.ArrayBlockingQueue;
import javax.annotation.Nullable;
@@ -52,9 +50,8 @@ public String get(Message carrier, String key) {
return carrier.get(key);
}
});
- SpanContext spanContext = TracingContextUtils.getSpan(context).getContext();
Span span =
- tracer.spanBuilder("receive").setSpanKind(Kind.SERVER).setParent(spanContext).startSpan();
+ tracer.spanBuilder("receive").setSpanKind(Kind.SERVER).setParent(context).startSpan();
span.setAttribute("component", "example-server");
try (Scope ignored = tracer.withSpan(span)) {
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/Client.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/Client.java
index ffc2ba1046d..137144c68ba 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/Client.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/Client.java
@@ -31,7 +31,7 @@ public Client(RequestHandler requestHandler) {
}
public Future send(final Object message) {
- final Context context = new Context();
+ final RequestHandlerContext requestHandlerContext = new RequestHandlerContext();
return executor.submit(
() -> {
TestUtils.sleep();
@@ -39,7 +39,7 @@ public Future send(final Object message) {
.submit(
() -> {
TestUtils.sleep();
- requestHandler.beforeRequest(message, context);
+ requestHandler.beforeRequest(message, requestHandlerContext);
})
.get();
@@ -47,7 +47,7 @@ public Future send(final Object message) {
.submit(
() -> {
TestUtils.sleep();
- requestHandler.afterResponse(message, context);
+ requestHandler.afterResponse(message, requestHandlerContext);
})
.get();
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/HandlerTest.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/HandlerTest.java
index dcf06715888..81edb9bf4fa 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/HandlerTest.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/HandlerTest.java
@@ -18,6 +18,7 @@
import static org.assertj.core.api.Assertions.assertThat;
+import io.grpc.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
import io.opentelemetry.sdk.extensions.trace.testbed.TestUtils;
@@ -27,6 +28,7 @@
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.SpanId;
import io.opentelemetry.trace.Tracer;
+import io.opentelemetry.trace.TracingContextUtils;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -108,7 +110,10 @@ void bad_solution_to_set_parent() throws Exception {
Client client;
Span parentSpan = tracer.spanBuilder("parent").startSpan();
try (Scope ignored = tracer.withSpan(parentSpan)) {
- client = new Client(new RequestHandler(tracer, parentSpan.getContext()));
+ client =
+ new Client(
+ new RequestHandler(
+ tracer, TracingContextUtils.withSpan(parentSpan, Context.current())));
String response = client.send("correct_parent").get(15, TimeUnit.SECONDS);
assertThat(response).isEqualTo("correct_parent:response");
} finally {
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/RequestHandler.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/RequestHandler.java
index 27055f15d41..aec60bf15a7 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/RequestHandler.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/RequestHandler.java
@@ -16,9 +16,9 @@
package io.opentelemetry.sdk.extensions.trace.testbed.concurrentcommonrequesthandler;
+import io.grpc.Context;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Span.Kind;
-import io.opentelemetry.trace.SpanContext;
import io.opentelemetry.trace.Tracer;
/**
@@ -30,18 +30,18 @@ final class RequestHandler {
private final Tracer tracer;
- private final SpanContext parentContext;
+ private final Context parentContext;
public RequestHandler(Tracer tracer) {
this(tracer, null);
}
- public RequestHandler(Tracer tracer, SpanContext parentContext) {
+ public RequestHandler(Tracer tracer, Context parentContext) {
this.tracer = tracer;
this.parentContext = parentContext;
}
- public void beforeRequest(Object request, Context context) {
+ public void beforeRequest(Object request, RequestHandlerContext requestHandlerContext) {
// we cannot use active span because we don't know in which thread it is executed
// and we cannot therefore activate span. thread can come from common thread pool.
Span.Builder spanBuilder =
@@ -51,11 +51,11 @@ public void beforeRequest(Object request, Context context) {
spanBuilder.setParent(parentContext);
}
- context.put("span", spanBuilder.startSpan());
+ requestHandlerContext.put("span", spanBuilder.startSpan());
}
- public void afterResponse(Object response, Context context) {
- Object spanObject = context.get("span");
+ public void afterResponse(Object response, RequestHandlerContext requestHandlerContext) {
+ Object spanObject = requestHandlerContext.get("span");
if (spanObject instanceof Span) {
Span span = (Span) spanObject;
span.end();
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/Context.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/RequestHandlerContext.java
similarity index 91%
rename from sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/Context.java
rename to sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/RequestHandlerContext.java
index 4ec2157f7de..b401a2bdb01 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/Context.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/concurrentcommonrequesthandler/RequestHandlerContext.java
@@ -18,4 +18,4 @@
import java.util.HashMap;
-final class Context extends HashMap {}
+final class RequestHandlerContext extends HashMap {}
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/multiplecallbacks/Client.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/multiplecallbacks/Client.java
index 71dd4328469..3ab1217921b 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/multiplecallbacks/Client.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/multiplecallbacks/Client.java
@@ -16,6 +16,7 @@
package io.opentelemetry.sdk.extensions.trace.testbed.multiplecallbacks;
+import io.grpc.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Tracer;
@@ -35,7 +36,7 @@ public Client(Tracer tracer, CountDownLatch parentDoneLatch) {
}
public Future send(final Object message) {
- final Span parent = tracer.getCurrentSpan();
+ final Context parent = Context.current();
return executor.submit(
() -> {
diff --git a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/promisepropagation/Promise.java b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/promisepropagation/Promise.java
index cccdfdb36d1..81c54f3b52d 100644
--- a/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/promisepropagation/Promise.java
+++ b/sdk_extensions/testbed/src/test/java/io/opentelemetry/sdk/extensions/trace/testbed/promisepropagation/Promise.java
@@ -16,6 +16,7 @@
package io.opentelemetry.sdk.extensions.trace.testbed.promisepropagation;
+import io.grpc.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Tracer;
@@ -25,7 +26,7 @@
final class Promise {
private final PromiseContext context;
private final Tracer tracer;
- private final Span parentSpan;
+ private final Context parent;
private final Collection> successCallbacks = new ArrayList<>();
private final Collection errorCallbacks = new ArrayList<>();
@@ -35,7 +36,7 @@ final class Promise {
// Passed along here for testing. Normally should be referenced via GlobalTracer.get().
this.tracer = tracer;
- parentSpan = tracer.getCurrentSpan();
+ parent = Context.current();
}
void onSuccess(SuccessCallback successCallback) {
@@ -51,7 +52,7 @@ void success(final T result) {
for (final SuccessCallback callback : successCallbacks) {
context.submit(
() -> {
- Span childSpan = tracer.spanBuilder("success").setParent(parentSpan).startSpan();
+ Span childSpan = tracer.spanBuilder("success").setParent(parent).startSpan();
childSpan.setAttribute("component", "success");
try (Scope ignored = tracer.withSpan(childSpan)) {
callback.accept(result);
@@ -68,7 +69,7 @@ void error(final Throwable error) {
for (final ErrorCallback callback : errorCallbacks) {
context.submit(
() -> {
- Span childSpan = tracer.spanBuilder("error").setParent(parentSpan).startSpan();
+ Span childSpan = tracer.spanBuilder("error").setParent(parent).startSpan();
childSpan.setAttribute("component", "error");
try (Scope ignored = tracer.withSpan(childSpan)) {
callback.accept(error);