diff --git a/api/src/main/java/io/opentelemetry/distributedcontext/DistributedContext.java b/api/src/main/java/io/opentelemetry/distributedcontext/DistributedContext.java index 0fa4ffa9f8..f07ac1e950 100644 --- a/api/src/main/java/io/opentelemetry/distributedcontext/DistributedContext.java +++ b/api/src/main/java/io/opentelemetry/distributedcontext/DistributedContext.java @@ -57,16 +57,16 @@ public interface DistributedContext { */ interface Builder { /** - * Sets the parent {@link DistributedContext} to use. If not set, the value of {@link - * DistributedContextManager#getCurrentContext()} at {@link #build()} time will be used as - * parent. + * Sets the parent {@link DistributedContext} to use. If no parent is provided, the value of + * {@link DistributedContextManager#getCurrentContext()} at {@link #build()} time will be used + * as parent, unless {@link #setNoParent()} was called. * *
This must be used to create a {@link DistributedContext} when manual Context * propagation is used. * *
If called multiple times, only the last specified value will be used.
*
- * @param parent the {@link DistributedContext} used as parent.
+ * @param parent the {@link DistributedContext} used as parent, not null.
* @return this.
* @throws NullPointerException if {@code parent} is {@code null}.
* @see #setNoParent()
@@ -75,9 +75,10 @@ public interface DistributedContext {
Builder setParent(DistributedContext parent);
/**
- * Sets the option to become a {@link DistributedContext} with no parent. If not set, the value
- * of {@link DistributedContextManager#getCurrentContext()} at {@link #build()} time will be
- * used as parent.
+ * Sets the option to become a root {@link DistributedContext} with no parent. If not
+ * called, the value provided using {@link #setParent(DistributedContext)} or otherwise {@link
+ * DistributedContextManager#getCurrentContext()} at {@link #build()} time will be used as
+ * parent.
*
* @return this.
* @since 0.1.0
diff --git a/api/src/test/java/io/opentelemetry/distributedcontext/DefaultDistributedContextManagerTest.java b/api/src/test/java/io/opentelemetry/distributedcontext/DefaultDistributedContextManagerTest.java
index 5260ffdd27..93fbf19025 100644
--- a/api/src/test/java/io/opentelemetry/distributedcontext/DefaultDistributedContextManagerTest.java
+++ b/api/src/test/java/io/opentelemetry/distributedcontext/DefaultDistributedContextManagerTest.java
@@ -135,7 +135,7 @@ public final class DefaultDistributedContextManagerTest {
}
@Test
- public void noopContextBuilder_SetParent_DisallowsNullKey() {
+ public void noopContextBuilder_SetParent_DisallowsNullParent() {
DistributedContext.Builder noopBuilder = defaultDistributedContextManager.contextBuilder();
thrown.expect(NullPointerException.class);
noopBuilder.setParent(null);
diff --git a/sdk/src/main/java/io/opentelemetry/sdk/distributedcontext/DistributedContextSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/distributedcontext/DistributedContextSdk.java
index be845601bc..bd0d61fbd8 100644
--- a/sdk/src/main/java/io/opentelemetry/sdk/distributedcontext/DistributedContextSdk.java
+++ b/sdk/src/main/java/io/opentelemetry/sdk/distributedcontext/DistributedContextSdk.java
@@ -18,11 +18,13 @@ package io.opentelemetry.sdk.distributedcontext;
import static io.opentelemetry.internal.Utils.checkNotNull;
+import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.distributedcontext.DistributedContext;
import io.opentelemetry.distributedcontext.Entry;
import io.opentelemetry.distributedcontext.EntryKey;
import io.opentelemetry.distributedcontext.EntryMetadata;
import io.opentelemetry.distributedcontext.EntryValue;
+import io.opentelemetry.internal.Utils;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -111,6 +113,7 @@ class DistributedContextSdk implements DistributedContext {
// @AutoValue.Builder
static class Builder implements DistributedContext.Builder {
@Nullable private DistributedContext parent;
+ private boolean noImplicitParent;
private final Map