diff --git a/all/build.gradle b/all/build.gradle index 4d348aaaf3..75c928f59f 100644 --- a/all/build.gradle +++ b/all/build.gradle @@ -21,8 +21,8 @@ def subprojects = [ project(':opentelemetry-integration-tests'), project(':opentelemetry-integration-tests-tracecontext'), project(':opentelemetry-opentracing-shim'), + project(':opentelemetry-sdk-baggage'), project(':opentelemetry-sdk-common'), - project(':opentelemetry-sdk-correlation-context'), project(':opentelemetry-sdk-metrics'), project(':opentelemetry-sdk-tracing'), project(':opentelemetry-sdk'), diff --git a/api/src/main/java/io/opentelemetry/OpenTelemetry.java b/api/src/main/java/io/opentelemetry/OpenTelemetry.java index 8633c4e183..2ef0abfb36 100644 --- a/api/src/main/java/io/opentelemetry/OpenTelemetry.java +++ b/api/src/main/java/io/opentelemetry/OpenTelemetry.java @@ -16,11 +16,11 @@ package io.opentelemetry; +import io.opentelemetry.baggage.BaggageManager; +import io.opentelemetry.baggage.DefaultBaggageManager; +import io.opentelemetry.baggage.spi.BaggageManagerFactory; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.DefaultContextPropagators; -import io.opentelemetry.correlationcontext.CorrelationContextManager; -import io.opentelemetry.correlationcontext.DefaultCorrelationContextManager; -import io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory; import io.opentelemetry.internal.Obfuscated; import io.opentelemetry.internal.Utils; import io.opentelemetry.metrics.DefaultMeterProvider; @@ -38,13 +38,13 @@ import javax.annotation.concurrent.ThreadSafe; /** * This class provides a static global accessor for telemetry objects {@link Tracer}, {@link Meter} - * and {@link CorrelationContextManager}. + * and {@link BaggageManager}. * *

The telemetry objects are lazy-loaded singletons resolved via {@link ServiceLoader} mechanism. * * @see TracerProvider * @see MeterProviderFactory - * @see CorrelationContextManagerFactory + * @see BaggageManagerFactory */ @ThreadSafe public final class OpenTelemetry { @@ -54,7 +54,7 @@ public final class OpenTelemetry { private final TracerProvider tracerProvider; private final MeterProvider meterProvider; - private final CorrelationContextManager contextManager; + private final BaggageManager contextManager; private volatile ContextPropagators propagators = DefaultContextPropagators.builder().build(); @@ -144,15 +144,14 @@ public final class OpenTelemetry { } /** - * Returns a singleton {@link CorrelationContextManager}. + * Returns a singleton {@link BaggageManager}. * - * @return registered manager or default via {@link - * DefaultCorrelationContextManager#getInstance()}. + * @return registered manager or default via {@link DefaultBaggageManager#getInstance()}. * @throws IllegalStateException if a specified manager (via system properties) could not be * found. * @since 0.1.0 */ - public static CorrelationContextManager getCorrelationContextManager() { + public static BaggageManager getBaggageManager() { return getInstance().contextManager; } @@ -209,12 +208,11 @@ public final class OpenTelemetry { meterProviderFactory != null ? meterProviderFactory.create() : DefaultMeterProvider.getInstance(); - CorrelationContextManagerFactory contextManagerProvider = - loadSpi(CorrelationContextManagerFactory.class); + BaggageManagerFactory contextManagerProvider = loadSpi(BaggageManagerFactory.class); contextManager = contextManagerProvider != null ? contextManagerProvider.create() - : DefaultCorrelationContextManager.getInstance(); + : DefaultBaggageManager.getInstance(); } /** diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContext.java b/api/src/main/java/io/opentelemetry/baggage/Baggage.java similarity index 54% rename from api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContext.java rename to api/src/main/java/io/opentelemetry/baggage/Baggage.java index 418c3b9334..1a09fd5379 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContext.java +++ b/api/src/main/java/io/opentelemetry/baggage/Baggage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; import io.grpc.Context; import java.util.Collection; @@ -25,19 +25,19 @@ import javax.annotation.concurrent.Immutable; * A map from {@link String} to {@link String} and {@link EntryMetadata} that can be used to label * anything that is associated with a specific operation. * - *

For example, {@code CorrelationContext}s can be used to label stats, log messages, or - * debugging information. + *

For example, {@code Baggage}s can be used to label stats, log messages, or debugging + * information. * - * @since 0.1.0 + * @since 0.9.0 */ @Immutable -public interface CorrelationContext { +public interface Baggage { /** - * Returns an immutable collection of the entries in this {@code CorrelationContext}. Order of - * entries is not guaranteed. + * Returns an immutable collection of the entries in this {@code Baggage}. Order of entries is not + * guaranteed. * - * @return an immutable collection of the entries in this {@code CorrelationContext}. - * @since 0.1.0 + * @return an immutable collection of the entries in this {@code Baggage}. + * @since 0.9.0 */ Collection getEntries(); @@ -46,47 +46,45 @@ public interface CorrelationContext { * * @param entryKey entry key to return the value for. * @return the value associated with the given key, or {@code null} if no {@code Entry} with the - * given {@code entryKey} is in this {@code CorrelationContext}. + * given {@code entryKey} is in this {@code Baggage}. */ @Nullable String getEntryValue(String entryKey); /** - * Builder for the {@link CorrelationContext} class. + * Builder for the {@link Baggage} class. * - * @since 0.1.0 + * @since 0.9.0 */ interface Builder { /** - * Sets the parent {@link CorrelationContext} to use. If no parent is provided, the value of - * {@link CorrelationContextManager#getCurrentContext()} at {@link #build()} time will be used - * as parent, unless {@link #setNoParent()} was called. + * Sets the parent {@link Baggage} to use. If no parent is provided, the value of {@link + * BaggageManager#getCurrentBaggage()} at {@link #build()} time will be used as parent, unless + * {@link #setNoParent()} was called. * - *

This must be used to create a {@link CorrelationContext} when manual Context - * propagation is used. + *

This must be used to create a {@link Baggage} when manual Context propagation is + * used. * *

If called multiple times, only the last specified value will be used. * - * @param parent the {@link CorrelationContext} used as parent, not null. + * @param parent the {@link Baggage} used as parent, not null. * @return this. * @throws NullPointerException if {@code parent} is {@code null}. * @see #setNoParent() - * @since 0.1.0 + * @since 0.9.0 */ - Builder setParent(CorrelationContext parent); + Builder setParent(Baggage parent); /** - * Sets the parent {@link CorrelationContext} to use from the specified {@code Context}. If no - * parent {@link CorrelationContext} is provided, the value of {@link - * CorrelationContextManager#getCurrentContext()} at {@link #build()} time will be used as - * parent, unless {@link #setNoParent()} was called. + * Sets the parent {@link Baggage} to use from the specified {@code Context}. If no parent + * {@link Baggage} is provided, the value of {@link BaggageManager#getCurrentBaggage()} at + * {@link #build()} time will be used as parent, unless {@link #setNoParent()} was called. * - *

If no parent {@link CorrelationContext} is available in the specified {@code Context}, the - * resulting {@link CorrelationContext} will become a root instance, as if {@link - * #setNoParent()} had been called. + *

If no parent {@link Baggage} is available in the specified {@code Context}, the resulting + * {@link Baggage} will become a root instance, as if {@link #setNoParent()} had been called. * - *

This must be used to create a {@link CorrelationContext} when manual Context - * propagation is used. + *

This must be used to create a {@link Baggage} when manual Context propagation is + * used. * *

If called multiple times, only the last specified value will be used. * @@ -94,18 +92,17 @@ public interface CorrelationContext { * @return this. * @throws NullPointerException if {@code context} is {@code null}. * @see #setNoParent() - * @since 0.7.0 + * @since 0.9.0 */ Builder setParent(Context context); /** - * Sets the option to become a root {@link CorrelationContext} with no parent. If not - * called, the value provided using {@link #setParent(CorrelationContext)} or otherwise {@link - * CorrelationContextManager#getCurrentContext()} at {@link #build()} time will be used as - * parent. + * Sets the option to become a root {@link Baggage} with no parent. If not called, the + * value provided using {@link #setParent(Baggage)} or otherwise {@link + * BaggageManager#getCurrentBaggage()} at {@link #build()} time will be used as parent. * * @return this. - * @since 0.1.0 + * @since 0.9.0 */ Builder setNoParent(); @@ -116,7 +113,7 @@ public interface CorrelationContext { * @param value the {@code String} value to set for the given key. * @param entryMetadata the {@code EntryMetadata} associated with this {@link Entry}. * @return this - * @since 0.1.0 + * @since 0.9.0 */ Builder put(String key, String value, EntryMetadata entryMetadata); @@ -125,16 +122,16 @@ public interface CorrelationContext { * * @param key the {@code String} key which will be removed. * @return this - * @since 0.1.0 + * @since 0.9.0 */ Builder remove(String key); /** - * Creates a {@code CorrelationContext} from this builder. + * Creates a {@code Baggage} from this builder. * - * @return a {@code CorrelationContext} with the same entries as this builder. - * @since 0.1.0 + * @return a {@code Baggage} with the same entries as this builder. + * @since 0.9.0 */ - CorrelationContext build(); + Baggage build(); } } diff --git a/api/src/main/java/io/opentelemetry/baggage/BaggageManager.java b/api/src/main/java/io/opentelemetry/baggage/BaggageManager.java new file mode 100644 index 0000000000..6c8e6fd083 --- /dev/null +++ b/api/src/main/java/io/opentelemetry/baggage/BaggageManager.java @@ -0,0 +1,64 @@ +/* + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.baggage; + +import io.opentelemetry.context.Scope; +import javax.annotation.concurrent.ThreadSafe; + +/** + * Object for creating new {@link Baggage}s and {@code Baggage}s based on the current context. + * + *

This class returns {@link Baggage.Builder builders} that can be used to create the + * implementation-dependent {@link Baggage}s. + * + *

Implementations may have different constraints and are free to convert entry contexts to their + * own subtypes. This means callers cannot assume the {@link #getCurrentBaggage() current context} + * is the same instance as the one {@link #withContext(Baggage) placed into scope}. + * + * @since 0.9.0 + */ +@ThreadSafe +public interface BaggageManager { + + /** + * Returns the current {@code Baggage}. + * + * @return the current {@code Baggage}. + * @since 0.9.0 + */ + Baggage getCurrentBaggage(); + + /** + * Returns a new {@link Baggage.Builder}. + * + * @return a new {@code Baggage.Builder}. + * @since 0.9.0 + */ + Baggage.Builder baggageBuilder(); + + /** + * Enters the scope of code where the given {@code Baggage} is in the current context (replacing + * the previous {@code Baggage}) and returns an object that represents that scope. The scope is + * exited when the returned object is closed. + * + * @param distContext the {@code Baggage} to be set as the current context. + * @return an object that defines a scope where the given {@code Baggage} is set as the current + * context. + * @since 0.9.0 + */ + Scope withContext(Baggage distContext); +} diff --git a/api/src/main/java/io/opentelemetry/baggage/BaggageUtils.java b/api/src/main/java/io/opentelemetry/baggage/BaggageUtils.java new file mode 100644 index 0000000000..e075291a9b --- /dev/null +++ b/api/src/main/java/io/opentelemetry/baggage/BaggageUtils.java @@ -0,0 +1,98 @@ +/* + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.baggage; + +import io.grpc.Context; +import io.opentelemetry.context.ContextUtils; +import io.opentelemetry.context.Scope; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; + +/** + * Utility methods for accessing the {@link Baggage} contained in the {@link io.grpc.Context}. + * + * @since 0.9.0 + */ +@Immutable +public final class BaggageUtils { + private static final Context.Key CORR_CONTEXT_KEY = + Context.key("opentelemetry-corr-context-key"); + + /** + * Creates a new {@code Context} with the given value set. + * + * @param baggage the value to be set. + * @param context the parent {@code Context}. + * @return a new context with the given value set. + * @since 0.9.0 + */ + public static Context withBaggage(Baggage baggage, Context context) { + return context.withValue(CORR_CONTEXT_KEY, baggage); + } + + /** + * Returns the {@link Baggage} from the {@linkplain Context#current current context}, falling back + * to an empty {@link Baggage}. + * + * @return the {@link Baggage} from the {@linkplain Context#current current context}. + * @since 0.9.0 + */ + public static Baggage getCurrentBaggage() { + return getBaggage(Context.current()); + } + + /** + * Returns the {@link Baggage} from the specified {@code Context}, falling back to an empty {@link + * Baggage}. + * + * @param context the specified {@code Context}. + * @return the {@link Baggage} from the specified {@code Context}. + * @since 0.9.0 + */ + public static Baggage getBaggage(Context context) { + Baggage baggage = CORR_CONTEXT_KEY.get(context); + return baggage == null ? EmptyBaggage.getInstance() : baggage; + } + + /** + * Returns the {@link Baggage} from the specified {@code Context}. If none is found, this method + * returns {code null}. + * + * @param context the specified {@code Context}. + * @return the {@link Baggage} from the specified {@code Context}. + * @since 0.9.0 + */ + @Nullable + public static Baggage getBaggageWithoutDefault(Context context) { + return CORR_CONTEXT_KEY.get(context); + } + + /** + * Returns a new {@link Scope} encapsulating the provided {@link Baggage} added to the current + * {@code Context}. + * + * @param baggage the {@link Baggage} to be added to the current {@code Context}. + * @return the {@link Scope} for the updated {@code Context}. + * @since 0.9.0 + */ + public static Scope currentContextWith(Baggage baggage) { + Context context = withBaggage(baggage, Context.current()); + return ContextUtils.withScopedContext(context); + } + + private BaggageUtils() {} +} diff --git a/api/src/main/java/io/opentelemetry/baggage/DefaultBaggageManager.java b/api/src/main/java/io/opentelemetry/baggage/DefaultBaggageManager.java new file mode 100644 index 0000000000..e4c252895d --- /dev/null +++ b/api/src/main/java/io/opentelemetry/baggage/DefaultBaggageManager.java @@ -0,0 +1,98 @@ +/* + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.baggage; + +import io.grpc.Context; +import io.opentelemetry.context.Scope; +import io.opentelemetry.internal.Utils; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.ThreadSafe; + +/** + * No-op implementations of {@link BaggageManager}. + * + * @since 0.9.0 + */ +@ThreadSafe +public final class DefaultBaggageManager implements BaggageManager { + private static final DefaultBaggageManager INSTANCE = new DefaultBaggageManager(); + + /** + * Returns a {@code BaggageManager} singleton that is the default implementation for {@link + * BaggageManager}. + * + * @return a {@code BaggageManager} singleton that is the default implementation for {@link + * BaggageManager}. + */ + public static BaggageManager getInstance() { + return INSTANCE; + } + + @Override + public Baggage getCurrentBaggage() { + return BaggageUtils.getCurrentBaggage(); + } + + @Override + public Baggage.Builder baggageBuilder() { + return new NoopBaggageBuilder(); + } + + @Override + public Scope withContext(Baggage distContext) { + return BaggageUtils.currentContextWith(distContext); + } + + @Immutable + private static final class NoopBaggageBuilder implements Baggage.Builder { + @Override + public Baggage.Builder setParent(Baggage parent) { + Utils.checkNotNull(parent, "parent"); + return this; + } + + @Override + public Baggage.Builder setParent(Context context) { + Utils.checkNotNull(context, "context"); + return this; + } + + @Override + public Baggage.Builder setNoParent() { + return this; + } + + @Override + public Baggage.Builder put(String key, String value, EntryMetadata entryMetadata) { + Utils.checkNotNull(key, "key"); + Utils.checkNotNull(value, "value"); + Utils.checkNotNull(entryMetadata, "entryMetadata"); + return this; + } + + @Override + public Baggage.Builder remove(String key) { + Utils.checkNotNull(key, "key"); + return this; + } + + @Override + public Baggage build() { + return EmptyBaggage.getInstance(); + } + } +} diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/EmptyCorrelationContext.java b/api/src/main/java/io/opentelemetry/baggage/EmptyBaggage.java similarity index 63% rename from api/src/main/java/io/opentelemetry/correlationcontext/EmptyCorrelationContext.java rename to api/src/main/java/io/opentelemetry/baggage/EmptyBaggage.java index e290157f7b..00703f80b0 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/EmptyCorrelationContext.java +++ b/api/src/main/java/io/opentelemetry/baggage/EmptyBaggage.java @@ -14,29 +14,27 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; import java.util.Collection; import java.util.Collections; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -/** - * An immutable implementation of the {@link CorrelationContext} that does not contain any entries. - */ +/** An immutable implementation of the {@link Baggage} that does not contain any entries. */ @Immutable -public class EmptyCorrelationContext implements CorrelationContext { +public class EmptyBaggage implements Baggage { /** - * Returns the single instance of the {@link EmptyCorrelationContext} class. + * Returns the single instance of the {@link EmptyBaggage} class. * - * @return the single instance of the {@code EmptyCorrelationContext} class. - * @since 0.1.0 + * @return the single instance of the {@code EmptyBaggage} class. + * @since 0.9.0 */ - public static CorrelationContext getInstance() { + public static Baggage getInstance() { return INSTANCE; } - private static final CorrelationContext INSTANCE = new EmptyCorrelationContext(); + private static final Baggage INSTANCE = new EmptyBaggage(); @Override public Collection getEntries() { @@ -49,5 +47,5 @@ public class EmptyCorrelationContext implements CorrelationContext { return null; } - private EmptyCorrelationContext() {} + private EmptyBaggage() {} } diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/Entry.java b/api/src/main/java/io/opentelemetry/baggage/Entry.java similarity index 92% rename from api/src/main/java/io/opentelemetry/correlationcontext/Entry.java rename to api/src/main/java/io/opentelemetry/baggage/Entry.java index 3bdf0329d3..b225b43ac0 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/Entry.java +++ b/api/src/main/java/io/opentelemetry/baggage/Entry.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; import com.google.auto.value.AutoValue; -import io.opentelemetry.correlationcontext.EntryMetadata.EntryTtl; +import io.opentelemetry.baggage.EntryMetadata.EntryTtl; import io.opentelemetry.internal.StringUtils; import io.opentelemetry.internal.Utils; import javax.annotation.concurrent.Immutable; @@ -25,7 +25,7 @@ import javax.annotation.concurrent.Immutable; /** * String-String key-value pair, along with {@link EntryMetadata}. * - * @since 0.1.0 + * @since 0.9.0 */ @Immutable @AutoValue @@ -33,14 +33,14 @@ public abstract class Entry { /** * The maximum length for an entry key name. The value is {@value #MAX_KEY_LENGTH}. * - * @since 0.1.0 + * @since 0.9.0 */ public static final int MAX_KEY_LENGTH = 255; /** * The maximum length for a entry value. The value is {@value #MAX_VALUE_LENGTH}. * - * @since 0.1.0 + * @since 0.9.0 */ public static final int MAX_VALUE_LENGTH = 255; @@ -57,7 +57,7 @@ public abstract class Entry { * @param value the entry value. * @param entryMetadata the entry metadata. * @return a {@code Entry}. - * @since 0.1.0 + * @since 0.9.0 */ public static Entry create(String key, String value, EntryMetadata entryMetadata) { Utils.checkArgument(keyIsValid(key), "Invalid entry key name: %s", key); @@ -69,7 +69,7 @@ public abstract class Entry { * Returns the entry's key. * * @return the entry's key. - * @since 0.1.0 + * @since 0.9.0 */ public abstract String getKey(); @@ -77,7 +77,7 @@ public abstract class Entry { * Returns the entry's value. * * @return the entry's value. - * @since 0.1.0 + * @since 0.9.0 */ public abstract String getValue(); @@ -85,7 +85,7 @@ public abstract class Entry { * Returns the {@link EntryMetadata} associated with this {@link Entry}. * * @return the {@code EntryMetadata}. - * @since 0.1.0 + * @since 0.9.0 */ public abstract EntryMetadata getEntryMetadata(); diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/EntryMetadata.java b/api/src/main/java/io/opentelemetry/baggage/EntryMetadata.java similarity index 94% rename from api/src/main/java/io/opentelemetry/correlationcontext/EntryMetadata.java rename to api/src/main/java/io/opentelemetry/baggage/EntryMetadata.java index a9908642dc..730d12fdcc 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/EntryMetadata.java +++ b/api/src/main/java/io/opentelemetry/baggage/EntryMetadata.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; import com.google.auto.value.AutoValue; import javax.annotation.concurrent.Immutable; @@ -25,7 +25,7 @@ import javax.annotation.concurrent.Immutable; *

For now only the property {@link EntryTtl} is defined. In future, additional properties may be * added to address specific situations. * - * @since 0.1.0 + * @since 0.9.0 */ @Immutable @AutoValue @@ -38,7 +38,7 @@ public abstract class EntryMetadata { * * @param entryTtl TTL of an {@code Entry}. * @return an {@code EntryMetadata}. - * @since 0.1.0 + * @since 0.9.0 */ public static EntryMetadata create(EntryTtl entryTtl) { return new AutoValue_EntryMetadata(entryTtl); @@ -48,7 +48,7 @@ public abstract class EntryMetadata { * Returns the {@link EntryTtl} of this {@link EntryMetadata}. * * @return the {@code EntryTtl}. - * @since 0.1.0 + * @since 0.9.0 */ public abstract EntryTtl getEntryTtl(); @@ -63,7 +63,7 @@ public abstract class EntryMetadata { * *

For now, only special values of {@link EntryTtl} are supported. * - * @since 0.1.0 + * @since 0.9.0 */ public enum EntryTtl { @@ -71,7 +71,7 @@ public abstract class EntryMetadata { * An {@link Entry} with {@link EntryTtl#NO_PROPAGATION} is considered to have local scope and * is used within the process where it's created. * - * @since 0.1.0 + * @since 0.9.0 */ NO_PROPAGATION(0), @@ -83,7 +83,7 @@ public abstract class EntryMetadata { *

{@link EntryTtl#UNLIMITED_PROPAGATION} is typical used to track a request, which may be * processed across multiple entities. * - * @since 0.1.0 + * @since 0.9.0 */ UNLIMITED_PROPAGATION(-1); diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/package-info.java b/api/src/main/java/io/opentelemetry/baggage/package-info.java similarity index 81% rename from api/src/main/java/io/opentelemetry/correlationcontext/package-info.java rename to api/src/main/java/io/opentelemetry/baggage/package-info.java index 9fc8b574d4..ba0a199a66 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/package-info.java +++ b/api/src/main/java/io/opentelemetry/baggage/package-info.java @@ -21,12 +21,11 @@ * to label anything that is associated with a specific operation. For example, the {@code * opentelemetry.stats} package labels all stats with the current entries. * - *

{@link io.opentelemetry.correlationcontext.Entry Entrys} are key-value pairs of {@link - * java.lang.String}s. They are stored as a map in a {@link - * io.opentelemetry.correlationcontext.CorrelationContext}. + *

{@link io.opentelemetry.baggage.Entry Entrys} are key-value pairs of {@link + * java.lang.String}s. They are stored as a map in a {@link io.opentelemetry.baggage.Baggage}. * *

Note that entries are independent of the tracing data that is propagated in the {@code * io.grpc.Context}, such as trace ID. */ // TODO: Add code examples. -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/spi/CorrelationContextManagerFactory.java b/api/src/main/java/io/opentelemetry/baggage/spi/BaggageManagerFactory.java similarity index 52% rename from api/src/main/java/io/opentelemetry/correlationcontext/spi/CorrelationContextManagerFactory.java rename to api/src/main/java/io/opentelemetry/baggage/spi/BaggageManagerFactory.java index 161f0dd4cf..84e4c6daff 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/spi/CorrelationContextManagerFactory.java +++ b/api/src/main/java/io/opentelemetry/baggage/spi/BaggageManagerFactory.java @@ -14,30 +14,29 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext.spi; +package io.opentelemetry.baggage.spi; -import io.opentelemetry.correlationcontext.CorrelationContextManager; +import io.opentelemetry.baggage.BaggageManager; import javax.annotation.concurrent.ThreadSafe; /** - * CorrelationContextManagerFactory is a service provider for {@link CorrelationContextManager}. - * Fully qualified class name of the implementation should be registered in {@code - * META-INF/services/io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory}.
+ * BaggageManagerFactory is a service provider for {@link BaggageManager}. Fully qualified class + * name of the implementation should be registered in {@code + * META-INF/services/io.opentelemetry.baggage.spi.BaggageManagerFactory}.
*
* A specific implementation can be selected by a system property {@code - * io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory} with value of fully - * qualified class name. + * io.opentelemetry.baggage.spi.BaggageManagerFactory} with value of fully qualified class name. * * @see io.opentelemetry.OpenTelemetry */ @ThreadSafe -public interface CorrelationContextManagerFactory { +public interface BaggageManagerFactory { /** - * Creates a new {@code CorrelationContextManager} instance. + * Creates a new {@code BaggageManager} instance. * - * @return a {@code CorrelationContextManager} instance. - * @since 0.1.0 + * @return a {@code BaggageManager} instance. + * @since 0.9.0 */ - CorrelationContextManager create(); + BaggageManager create(); } diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContextManager.java b/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContextManager.java deleted file mode 100644 index be1285d6f6..0000000000 --- a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContextManager.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.correlationcontext; - -import io.opentelemetry.context.Scope; -import javax.annotation.concurrent.ThreadSafe; - -/** - * Object for creating new {@link CorrelationContext}s and {@code CorrelationContext}s based on the - * current context. - * - *

This class returns {@link CorrelationContext.Builder builders} that can be used to create the - * implementation-dependent {@link CorrelationContext}s. - * - *

Implementations may have different constraints and are free to convert entry contexts to their - * own subtypes. This means callers cannot assume the {@link #getCurrentContext() current context} - * is the same instance as the one {@link #withContext(CorrelationContext) placed into scope}. - * - * @since 0.1.0 - */ -@ThreadSafe -public interface CorrelationContextManager { - - /** - * Returns the current {@code CorrelationContext}. - * - * @return the current {@code CorrelationContext}. - * @since 0.1.0 - */ - CorrelationContext getCurrentContext(); - - /** - * Returns a new {@code Builder}. - * - * @return a new {@code Builder}. - * @since 0.1.0 - */ - CorrelationContext.Builder contextBuilder(); - - /** - * Enters the scope of code where the given {@code CorrelationContext} is in the current context - * (replacing the previous {@code CorrelationContext}) and returns an object that represents that - * scope. The scope is exited when the returned object is closed. - * - * @param distContext the {@code CorrelationContext} to be set as the current context. - * @return an object that defines a scope where the given {@code CorrelationContext} is set as the - * current context. - * @since 0.1.0 - */ - Scope withContext(CorrelationContext distContext); -} diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationsContextUtils.java b/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationsContextUtils.java deleted file mode 100644 index a676381bf2..0000000000 --- a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationsContextUtils.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.correlationcontext; - -import io.grpc.Context; -import io.opentelemetry.context.ContextUtils; -import io.opentelemetry.context.Scope; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -/** - * Utility methods for accessing the {@link CorrelationContext} contained in the {@link - * io.grpc.Context}. - * - * @since 0.1.0 - */ -@Immutable -public final class CorrelationsContextUtils { - private static final Context.Key CORR_CONTEXT_KEY = - Context.key("opentelemetry-corr-context-key"); - - /** - * Creates a new {@code Context} with the given value set. - * - * @param corrContext the value to be set. - * @param context the parent {@code Context}. - * @return a new context with the given value set. - * @since 0.1.0 - */ - public static Context withCorrelationContext(CorrelationContext corrContext, Context context) { - return context.withValue(CORR_CONTEXT_KEY, corrContext); - } - - /** - * Returns the {@link CorrelationContext} from the current {@code Context}, falling back to an - * empty {@link CorrelationContext}. - * - * @return the {@link CorrelationContext} from the current {@code Context}. - * @since 0.3.0 - */ - public static CorrelationContext getCurrentCorrelationContext() { - return getCorrelationContext(Context.current()); - } - - /** - * Returns the {@link CorrelationContext} from the specified {@code Context}, falling back to an - * empty {@link CorrelationContext}. - * - * @param context the specified {@code Context}. - * @return the {@link CorrelationContext} from the specified {@code Context}. - * @since 0.3.0 - */ - public static CorrelationContext getCorrelationContext(Context context) { - CorrelationContext corrContext = CORR_CONTEXT_KEY.get(context); - return corrContext == null ? EmptyCorrelationContext.getInstance() : corrContext; - } - - /** - * Returns the {@link CorrelationContext} from the specified {@code Context}. If none is found, - * this method returns {code null}. - * - * @param context the specified {@code Context}. - * @return the {@link CorrelationContext} from the specified {@code Context}. - * @since 0.1.0 - */ - @Nullable - public static CorrelationContext getCorrelationContextWithoutDefault(Context context) { - return CORR_CONTEXT_KEY.get(context); - } - - /** - * Returns a new {@link Scope} encapsulating the provided {@link CorrelationContext} added to the - * current {@code Context}. - * - * @param corrContext the {@link CorrelationContext} to be added to the current {@code Context}. - * @return the {@link Scope} for the updated {@code Context}. - * @since 0.1.0 - */ - public static Scope currentContextWith(CorrelationContext corrContext) { - Context context = withCorrelationContext(corrContext, Context.current()); - return ContextUtils.withScopedContext(context); - } - - private CorrelationsContextUtils() {} -} diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManager.java b/api/src/main/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManager.java deleted file mode 100644 index 04e03797ef..0000000000 --- a/api/src/main/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManager.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.correlationcontext; - -import io.grpc.Context; -import io.opentelemetry.context.Scope; -import io.opentelemetry.internal.Utils; -import javax.annotation.concurrent.Immutable; -import javax.annotation.concurrent.ThreadSafe; - -/** - * No-op implementations of {@link CorrelationContextManager}. - * - * @since 0.1.0 - */ -@ThreadSafe -public final class DefaultCorrelationContextManager implements CorrelationContextManager { - private static final DefaultCorrelationContextManager INSTANCE = - new DefaultCorrelationContextManager(); - - /** - * Returns a {@code CorrelationContextManager} singleton that is the default implementation for - * {@link CorrelationContextManager}. - * - * @return a {@code CorrelationContextManager} singleton that is the default implementation for - * {@link CorrelationContextManager}. - */ - public static CorrelationContextManager getInstance() { - return INSTANCE; - } - - @Override - public CorrelationContext getCurrentContext() { - return CorrelationsContextUtils.getCurrentCorrelationContext(); - } - - @Override - public CorrelationContext.Builder contextBuilder() { - return new NoopCorrelationContextBuilder(); - } - - @Override - public Scope withContext(CorrelationContext distContext) { - return CorrelationsContextUtils.currentContextWith(distContext); - } - - @Immutable - private static final class NoopCorrelationContextBuilder implements CorrelationContext.Builder { - @Override - public CorrelationContext.Builder setParent(CorrelationContext parent) { - Utils.checkNotNull(parent, "parent"); - return this; - } - - @Override - public CorrelationContext.Builder setParent(Context context) { - Utils.checkNotNull(context, "context"); - return this; - } - - @Override - public CorrelationContext.Builder setNoParent() { - return this; - } - - @Override - public CorrelationContext.Builder put(String key, String value, EntryMetadata entryMetadata) { - Utils.checkNotNull(key, "key"); - Utils.checkNotNull(value, "value"); - Utils.checkNotNull(entryMetadata, "entryMetadata"); - return this; - } - - @Override - public CorrelationContext.Builder remove(String key) { - Utils.checkNotNull(key, "key"); - return this; - } - - @Override - public CorrelationContext build() { - return EmptyCorrelationContext.getInstance(); - } - } -} diff --git a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java index 4531929d57..e2f62ba2f1 100644 --- a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java +++ b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java @@ -20,13 +20,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.BaggageManager; +import io.opentelemetry.baggage.DefaultBaggageManager; +import io.opentelemetry.baggage.spi.BaggageManagerFactory; import io.opentelemetry.context.Scope; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.DefaultContextPropagators; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.CorrelationContextManager; -import io.opentelemetry.correlationcontext.DefaultCorrelationContextManager; -import io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory; import io.opentelemetry.metrics.BatchRecorder; import io.opentelemetry.metrics.DefaultMeterProvider; import io.opentelemetry.metrics.DoubleCounter; @@ -71,7 +71,7 @@ class OpenTelemetryTest { OpenTelemetry.reset(); System.clearProperty(TracerProviderFactory.class.getName()); System.clearProperty(MeterProviderFactory.class.getName()); - System.clearProperty(CorrelationContextManagerFactory.class.getName()); + System.clearProperty(BaggageManagerFactory.class.getName()); } @Test @@ -80,10 +80,8 @@ class OpenTelemetryTest { assertThat(OpenTelemetry.getTracerProvider()).isSameAs(OpenTelemetry.getTracerProvider()); assertThat(OpenTelemetry.getMeterProvider()).isInstanceOf(DefaultMeterProvider.class); assertThat(OpenTelemetry.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider()); - assertThat(OpenTelemetry.getCorrelationContextManager()) - .isInstanceOf(DefaultCorrelationContextManager.class); - assertThat(OpenTelemetry.getCorrelationContextManager()) - .isSameAs(OpenTelemetry.getCorrelationContextManager()); + assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(DefaultBaggageManager.class); + assertThat(OpenTelemetry.getBaggageManager()).isSameAs(OpenTelemetry.getBaggageManager()); assertThat(OpenTelemetry.getPropagators()).isInstanceOf(DefaultContextPropagators.class); assertThat(OpenTelemetry.getPropagators()).isSameAs(OpenTelemetry.getPropagators()); } @@ -169,48 +167,38 @@ class OpenTelemetryTest { } @Test - void testCorrelationContextManagerLoadArbitrary() throws IOException { + void testBaggageManagerLoadArbitrary() throws IOException { File serviceFile = createService( - CorrelationContextManagerFactory.class, - FirstCorrelationContextManager.class, - SecondCorrelationContextManager.class); + BaggageManagerFactory.class, FirstBaggageManager.class, SecondBaggageManager.class); try { assertTrue( - (OpenTelemetry.getCorrelationContextManager() instanceof FirstCorrelationContextManager) - || (OpenTelemetry.getCorrelationContextManager() - instanceof SecondCorrelationContextManager)); - assertThat(OpenTelemetry.getCorrelationContextManager()) - .isEqualTo(OpenTelemetry.getCorrelationContextManager()); + (OpenTelemetry.getBaggageManager() instanceof FirstBaggageManager) + || (OpenTelemetry.getBaggageManager() instanceof SecondBaggageManager)); + assertThat(OpenTelemetry.getBaggageManager()).isEqualTo(OpenTelemetry.getBaggageManager()); } finally { serviceFile.delete(); } } @Test - void testCorrelationContextManagerSystemProperty() throws IOException { + void testBaggageManagerSystemProperty() throws IOException { File serviceFile = createService( - CorrelationContextManagerFactory.class, - FirstCorrelationContextManager.class, - SecondCorrelationContextManager.class); - System.setProperty( - CorrelationContextManagerFactory.class.getName(), - SecondCorrelationContextManager.class.getName()); + BaggageManagerFactory.class, FirstBaggageManager.class, SecondBaggageManager.class); + System.setProperty(BaggageManagerFactory.class.getName(), SecondBaggageManager.class.getName()); try { - assertThat(OpenTelemetry.getCorrelationContextManager()) - .isInstanceOf(SecondCorrelationContextManager.class); - assertThat(OpenTelemetry.getCorrelationContextManager()) - .isEqualTo(OpenTelemetry.getCorrelationContextManager()); + assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(SecondBaggageManager.class); + assertThat(OpenTelemetry.getBaggageManager()).isEqualTo(OpenTelemetry.getBaggageManager()); } finally { serviceFile.delete(); } } @Test - void testCorrelationContextManagerNotFound() { - System.setProperty(CorrelationContextManagerFactory.class.getName(), "io.does.not.exists"); - assertThrows(IllegalStateException.class, () -> OpenTelemetry.getCorrelationContextManager()); + void testBaggageManagerNotFound() { + System.setProperty(BaggageManagerFactory.class.getName(), "io.does.not.exists"); + assertThrows(IllegalStateException.class, () -> OpenTelemetry.getBaggageManager()); } @Test @@ -406,35 +394,34 @@ class OpenTelemetryTest { } } - public static class SecondCorrelationContextManager extends FirstCorrelationContextManager { + public static class SecondBaggageManager extends FirstBaggageManager { @Override - public CorrelationContextManager create() { - return new SecondCorrelationContextManager(); + public BaggageManager create() { + return new SecondBaggageManager(); } } - public static class FirstCorrelationContextManager - implements CorrelationContextManager, CorrelationContextManagerFactory { + public static class FirstBaggageManager implements BaggageManager, BaggageManagerFactory { @Override - public CorrelationContextManager create() { - return new FirstCorrelationContextManager(); + public BaggageManager create() { + return new FirstBaggageManager(); } @Nullable @Override - public CorrelationContext getCurrentContext() { + public Baggage getCurrentBaggage() { return null; } @Nullable @Override - public CorrelationContext.Builder contextBuilder() { + public Baggage.Builder baggageBuilder() { return null; } @Nullable @Override - public Scope withContext(CorrelationContext distContext) { + public Scope withContext(Baggage distContext) { return null; } } diff --git a/api/src/test/java/io/opentelemetry/baggage/BaggageUtilsTest.java b/api/src/test/java/io/opentelemetry/baggage/BaggageUtilsTest.java new file mode 100644 index 0000000000..a75ec1b361 --- /dev/null +++ b/api/src/test/java/io/opentelemetry/baggage/BaggageUtilsTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.baggage; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.grpc.Context; +import org.junit.jupiter.api.Test; + +class BaggageUtilsTest { + + @Test + void testGetCurrentBaggage_Default() { + Baggage baggage = BaggageUtils.getCurrentBaggage(); + assertThat(baggage).isSameAs(EmptyBaggage.getInstance()); + } + + @Test + void testGetCurrentBaggage_SetCorrContext() { + Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build(); + Context orig = BaggageUtils.withBaggage(baggage, Context.current()).attach(); + try { + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(baggage); + } finally { + Context.current().detach(orig); + } + } + + @Test + void testGetBaggage_DefaultContext() { + Baggage baggage = BaggageUtils.getBaggage(Context.current()); + assertThat(baggage).isSameAs(EmptyBaggage.getInstance()); + } + + @Test + void testGetBaggage_ExplicitContext() { + Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build(); + Context context = BaggageUtils.withBaggage(baggage, Context.current()); + assertThat(BaggageUtils.getBaggage(context)).isSameAs(baggage); + } + + @Test + void testGetBaggageWithoutDefault_DefaultContext() { + Baggage baggage = BaggageUtils.getBaggageWithoutDefault(Context.current()); + assertThat(baggage).isNull(); + } + + @Test + void testGetBaggageWithoutDefault_ExplicitContext() { + Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build(); + Context context = BaggageUtils.withBaggage(baggage, Context.current()); + assertThat(BaggageUtils.getBaggage(context)).isSameAs(baggage); + } +} diff --git a/api/src/test/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManagerTest.java b/api/src/test/java/io/opentelemetry/baggage/DefaultBaggageManagerTest.java similarity index 50% rename from api/src/test/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManagerTest.java rename to api/src/test/java/io/opentelemetry/baggage/DefaultBaggageManagerTest.java index a11d2884bf..7d83a39ea5 100644 --- a/api/src/test/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManagerTest.java +++ b/api/src/test/java/io/opentelemetry/baggage/DefaultBaggageManagerTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -25,14 +25,13 @@ import java.util.Collection; import java.util.Collections; import org.junit.jupiter.api.Test; -class DefaultCorrelationContextManagerTest { - private static final CorrelationContextManager defaultCorrelationContextManager = - DefaultCorrelationContextManager.getInstance(); +class DefaultBaggageManagerTest { + private static final BaggageManager DEFAULT_BAGGAGE_MANAGER = DefaultBaggageManager.getInstance(); private static final String KEY = "key"; private static final String VALUE = "value"; - private static final CorrelationContext DIST_CONTEXT = - new CorrelationContext() { + private static final Baggage DIST_CONTEXT = + new Baggage() { @Override public Collection getEntries() { @@ -48,21 +47,19 @@ class DefaultCorrelationContextManagerTest { @Test void builderMethod() { - assertThat(defaultCorrelationContextManager.contextBuilder().build().getEntries()).isEmpty(); + assertThat(DEFAULT_BAGGAGE_MANAGER.baggageBuilder().build().getEntries()).isEmpty(); } @Test void getCurrentContext_DefaultContext() { - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(EmptyCorrelationContext.getInstance()); + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); } @Test void getCurrentContext_ContextSetToNull() { - Context orig = - CorrelationsContextUtils.withCorrelationContext(null, Context.current()).attach(); + Context orig = BaggageUtils.withBaggage(null, Context.current()).attach(); try { - CorrelationContext distContext = defaultCorrelationContextManager.getCurrentContext(); + Baggage distContext = DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage(); assertThat(distContext).isNotNull(); assertThat(distContext.getEntries()).isEmpty(); } finally { @@ -72,69 +69,61 @@ class DefaultCorrelationContextManagerTest { @Test void withContext() { - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(EmptyCorrelationContext.getInstance()); - try (Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT)) { - assertThat(defaultCorrelationContextManager.getCurrentContext()).isSameAs(DIST_CONTEXT); + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); + try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withContext(DIST_CONTEXT)) { + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT); } - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(EmptyCorrelationContext.getInstance()); + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); } @Test void withContext_nullContext() { - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(EmptyCorrelationContext.getInstance()); - try (Scope wtm = defaultCorrelationContextManager.withContext(null)) { - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(EmptyCorrelationContext.getInstance()); + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); + try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withContext(null)) { + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); } - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(EmptyCorrelationContext.getInstance()); + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); } @Test void withContextUsingWrap() { Runnable runnable; - try (Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT)) { - assertThat(defaultCorrelationContextManager.getCurrentContext()).isSameAs(DIST_CONTEXT); + try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withContext(DIST_CONTEXT)) { + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT); runnable = Context.current() .wrap( () -> { - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(DIST_CONTEXT); + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT); }); } - assertThat(defaultCorrelationContextManager.getCurrentContext()) - .isSameAs(EmptyCorrelationContext.getInstance()); - // When we run the runnable we will have the CorrelationContext in the current Context. + assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); + // When we run the runnable we will have the Baggage in the current Context. runnable.run(); } @Test void noopContextBuilder_SetParent_DisallowsNullParent() { - CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder(); - assertThrows( - NullPointerException.class, () -> noopBuilder.setParent((CorrelationContext) null)); + Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); + assertThrows(NullPointerException.class, () -> noopBuilder.setParent((Baggage) null)); } @Test void noopContextBuilder_SetParent_DisallowsNullContext() { - CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder(); + Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); assertThrows(NullPointerException.class, () -> noopBuilder.setParent((Context) null)); ; } @Test void noopContextBuilder_SetParent_fromContext() { - CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder(); + Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); noopBuilder.setParent(Context.current()); // No error. } @Test void noopContextBuilder_Put_DisallowsNullKey() { - CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder(); + Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); assertThrows( NullPointerException.class, () -> noopBuilder.put(null, VALUE, Entry.METADATA_UNLIMITED_PROPAGATION)); @@ -142,7 +131,7 @@ class DefaultCorrelationContextManagerTest { @Test void noopContextBuilder_Put_DisallowsNullValue() { - CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder(); + Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); assertThrows( NullPointerException.class, () -> noopBuilder.put(KEY, null, Entry.METADATA_UNLIMITED_PROPAGATION)); @@ -150,13 +139,13 @@ class DefaultCorrelationContextManagerTest { @Test void noopContextBuilder_Put_DisallowsNullEntryMetadata() { - CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder(); + Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); assertThrows(NullPointerException.class, () -> noopBuilder.put(KEY, VALUE, null)); } @Test void noopContextBuilder_Remove_DisallowsNullKey() { - CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder(); + Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); assertThrows(NullPointerException.class, () -> noopBuilder.remove(null)); } } diff --git a/api/src/test/java/io/opentelemetry/correlationcontext/EntryMetadataTest.java b/api/src/test/java/io/opentelemetry/baggage/EntryMetadataTest.java similarity index 91% rename from api/src/test/java/io/opentelemetry/correlationcontext/EntryMetadataTest.java rename to api/src/test/java/io/opentelemetry/baggage/EntryMetadataTest.java index 4d08ab14ea..637e7c1b07 100644 --- a/api/src/test/java/io/opentelemetry/correlationcontext/EntryMetadataTest.java +++ b/api/src/test/java/io/opentelemetry/baggage/EntryMetadataTest.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.testing.EqualsTester; -import io.opentelemetry.correlationcontext.EntryMetadata.EntryTtl; +import io.opentelemetry.baggage.EntryMetadata.EntryTtl; import org.junit.jupiter.api.Test; class EntryMetadataTest { diff --git a/api/src/test/java/io/opentelemetry/correlationcontext/EntryTest.java b/api/src/test/java/io/opentelemetry/baggage/EntryTest.java similarity index 97% rename from api/src/test/java/io/opentelemetry/correlationcontext/EntryTest.java rename to api/src/test/java/io/opentelemetry/baggage/EntryTest.java index bc3562fc93..33066cf23f 100644 --- a/api/src/test/java/io/opentelemetry/correlationcontext/EntryTest.java +++ b/api/src/test/java/io/opentelemetry/baggage/EntryTest.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package io.opentelemetry.correlationcontext; +package io.opentelemetry.baggage; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.testing.EqualsTester; -import io.opentelemetry.correlationcontext.EntryMetadata.EntryTtl; +import io.opentelemetry.baggage.EntryMetadata.EntryTtl; import java.util.Arrays; import org.junit.jupiter.api.Test; diff --git a/api/src/test/java/io/opentelemetry/correlationcontext/CorrelationsContextUtilsTest.java b/api/src/test/java/io/opentelemetry/correlationcontext/CorrelationsContextUtilsTest.java deleted file mode 100644 index 152b805b2d..0000000000 --- a/api/src/test/java/io/opentelemetry/correlationcontext/CorrelationsContextUtilsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.correlationcontext; - -import static org.assertj.core.api.Assertions.assertThat; - -import io.grpc.Context; -import org.junit.jupiter.api.Test; - -class CorrelationsContextUtilsTest { - - @Test - void testGetCurrentCorrelationContext_Default() { - CorrelationContext corrContext = CorrelationsContextUtils.getCurrentCorrelationContext(); - assertThat(corrContext).isSameAs(EmptyCorrelationContext.getInstance()); - } - - @Test - void testGetCurrentCorrelationContext_SetCorrContext() { - CorrelationContext corrContext = - DefaultCorrelationContextManager.getInstance().contextBuilder().build(); - Context orig = - CorrelationsContextUtils.withCorrelationContext(corrContext, Context.current()).attach(); - try { - assertThat(CorrelationsContextUtils.getCurrentCorrelationContext()).isSameAs(corrContext); - } finally { - Context.current().detach(orig); - } - } - - @Test - void testGetCorrelationContext_DefaultContext() { - CorrelationContext corrContext = - CorrelationsContextUtils.getCorrelationContext(Context.current()); - assertThat(corrContext).isSameAs(EmptyCorrelationContext.getInstance()); - } - - @Test - void testGetCorrelationContext_ExplicitContext() { - CorrelationContext corrContext = - DefaultCorrelationContextManager.getInstance().contextBuilder().build(); - Context context = - CorrelationsContextUtils.withCorrelationContext(corrContext, Context.current()); - assertThat(CorrelationsContextUtils.getCorrelationContext(context)).isSameAs(corrContext); - } - - @Test - void testGetCorrelationContextWithoutDefault_DefaultContext() { - CorrelationContext corrContext = - CorrelationsContextUtils.getCorrelationContextWithoutDefault(Context.current()); - assertThat(corrContext).isNull(); - } - - @Test - void testGetCorrelationContextWithoutDefault_ExplicitContext() { - CorrelationContext corrContext = - DefaultCorrelationContextManager.getInstance().contextBuilder().build(); - Context context = - CorrelationsContextUtils.withCorrelationContext(corrContext, Context.current()); - assertThat(CorrelationsContextUtils.getCorrelationContext(context)).isSameAs(corrContext); - } -} diff --git a/context_prop/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java b/context_prop/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java index ec0b9f46cb..3ab8a11f78 100644 --- a/context_prop/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java +++ b/context_prop/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java @@ -66,7 +66,7 @@ public final class DefaultContextPropagators implements ContextPropagators { *

{@code
    * ContextPropagators propagators = DefaultContextPropagators.builder()
    *     .addTextMapPropagator(new HttpTraceContext())
-   *     .addTextMapPropagator(new HttpCorrelationContext())
+   *     .addTextMapPropagator(new HttpBaggage())
    *     .addTextMapPropagator(new MyCustomContextPropagator())
    *     .build();
    * }
diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/BaseShimObject.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/BaseShimObject.java index 53f9389197..d84a61a34b 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/BaseShimObject.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/BaseShimObject.java @@ -16,8 +16,8 @@ package io.opentelemetry.opentracingshim; +import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.correlationcontext.CorrelationContextManager; import io.opentelemetry.trace.Tracer; abstract class BaseShimObject { @@ -35,7 +35,7 @@ abstract class BaseShimObject { return telemetryInfo.tracer(); } - CorrelationContextManager contextManager() { + BaggageManager contextManager() { return telemetryInfo.contextManager(); } diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java index 8448a9a332..ff6a6b9160 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java @@ -17,8 +17,8 @@ package io.opentelemetry.opentracingshim; import io.grpc.Context; +import io.opentelemetry.baggage.BaggageUtils; import io.opentelemetry.context.propagation.TextMapPropagator; -import io.opentelemetry.correlationcontext.CorrelationsContextUtils; import io.opentelemetry.trace.DefaultSpan; import io.opentelemetry.trace.Span; import io.opentelemetry.trace.TracingContextUtils; @@ -37,9 +37,7 @@ final class Propagation extends BaseShimObject { Context context = TracingContextUtils.withSpan( DefaultSpan.create(contextShim.getSpanContext()), Context.current()); - context = - CorrelationsContextUtils.withCorrelationContext( - contextShim.getCorrelationContext(), context); + context = BaggageUtils.withBaggage(contextShim.getBaggage(), context); propagators().getTextMapPropagator().inject(context, carrier, TextMapSetter.INSTANCE); } @@ -61,8 +59,7 @@ final class Propagation extends BaseShimObject { return null; } - return new SpanContextShim( - telemetryInfo, span.getContext(), CorrelationsContextUtils.getCorrelationContext(context)); + return new SpanContextShim(telemetryInfo, span.getContext(), BaggageUtils.getBaggage(context)); } static final class TextMapSetter implements TextMapPropagator.Setter { 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 2a4d4a91fb..db51e6788a 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java @@ -22,8 +22,8 @@ import static io.opentelemetry.common.AttributesKeys.longKey; import static io.opentelemetry.common.AttributesKeys.stringKey; import io.grpc.Context; +import io.opentelemetry.baggage.Baggage; 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; @@ -189,7 +189,7 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder { @SuppressWarnings({"rawtypes", "unchecked"}) @Override public Span start() { - CorrelationContext distContext = null; + Baggage distContext = null; io.opentelemetry.trace.Span.Builder builder = tracer().spanBuilder(spanName); if (ignoreActiveSpan && parentSpan == null && parentSpanContext == null) { @@ -197,12 +197,12 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder { } else if (parentSpan != null) { builder.setParent(TracingContextUtils.withSpan(parentSpan.getSpan(), Context.ROOT)); SpanContextShim contextShim = spanContextTable().get(parentSpan); - distContext = contextShim == null ? null : contextShim.getCorrelationContext(); + distContext = contextShim == null ? null : contextShim.getBaggage(); } else if (parentSpanContext != null) { builder.setParent( TracingContextUtils.withSpan( DefaultSpan.create(parentSpanContext.getSpanContext()), Context.ROOT)); - distContext = parentSpanContext.getCorrelationContext(); + distContext = parentSpanContext.getBaggage(); } for (io.opentelemetry.trace.SpanContext link : parentLinks) { @@ -226,7 +226,7 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder { SpanShim spanShim = new SpanShim(telemetryInfo(), span); - if (distContext != null && distContext != telemetryInfo().emptyCorrelationContext()) { + if (distContext != null && distContext != telemetryInfo().emptyBaggage()) { spanContextTable().create(spanShim, distContext); } diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShim.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShim.java index 32185cb63c..5b40651547 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShim.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShim.java @@ -16,9 +16,9 @@ package io.opentelemetry.opentracingshim; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.Entry; -import io.opentelemetry.correlationcontext.EntryMetadata; +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.Entry; +import io.opentelemetry.baggage.EntryMetadata; import io.opentracing.SpanContext; import java.util.Iterator; import java.util.Map; @@ -28,30 +28,30 @@ final class SpanContextShim extends BaseShimObject implements SpanContext { EntryMetadata.create(EntryMetadata.EntryTtl.UNLIMITED_PROPAGATION); private final io.opentelemetry.trace.SpanContext context; - private final CorrelationContext distContext; + private final Baggage distContext; public SpanContextShim(SpanShim spanShim) { this( spanShim.telemetryInfo(), spanShim.getSpan().getContext(), - spanShim.telemetryInfo().emptyCorrelationContext()); + spanShim.telemetryInfo().emptyBaggage()); } public SpanContextShim(TelemetryInfo telemetryInfo, io.opentelemetry.trace.SpanContext context) { - this(telemetryInfo, context, telemetryInfo.emptyCorrelationContext()); + this(telemetryInfo, context, telemetryInfo.emptyBaggage()); } public SpanContextShim( TelemetryInfo telemetryInfo, io.opentelemetry.trace.SpanContext context, - CorrelationContext distContext) { + Baggage distContext) { super(telemetryInfo); this.context = context; this.distContext = distContext; } SpanContextShim newWithKeyValue(String key, String value) { - CorrelationContext.Builder builder = contextManager().contextBuilder().setParent(distContext); + Baggage.Builder builder = contextManager().baggageBuilder().setParent(distContext); builder.put(key, value, DEFAULT_ENTRY_METADATA); return new SpanContextShim(telemetryInfo(), context, builder.build()); @@ -61,7 +61,7 @@ final class SpanContextShim extends BaseShimObject implements SpanContext { return context; } - CorrelationContext getCorrelationContext() { + Baggage getBaggage() { return distContext; } diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShimTable.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShimTable.java index 6bb736c7a2..34679a6406 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShimTable.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShimTable.java @@ -16,7 +16,7 @@ package io.opentelemetry.opentracingshim; -import io.opentelemetry.correlationcontext.CorrelationContext; +import io.opentelemetry.baggage.Baggage; import io.opentelemetry.trace.Span; import java.util.Map; import java.util.WeakHashMap; @@ -27,7 +27,7 @@ import javax.annotation.Nullable; /* * SpanContextShimTable stores and manages OpenTracing SpanContext instances, * which are expected to a unmodfiable union of SpanContext and Baggage - * (CorrelationContext/TagMap under OpenTelemetry). + * (Baggage/TagMap under OpenTelemetry). * * This requires that changes on a given Span and its (new) SpanContext * are visible in all threads at *any* moment. The current approach uses @@ -85,10 +85,10 @@ final class SpanContextShimTable { } public SpanContextShim create(SpanShim spanShim) { - return create(spanShim, spanShim.telemetryInfo().emptyCorrelationContext()); + return create(spanShim, spanShim.telemetryInfo().emptyBaggage()); } - public SpanContextShim create(SpanShim spanShim, CorrelationContext distContext) { + public SpanContextShim create(SpanShim spanShim, Baggage distContext) { lock.writeLock().lock(); try { SpanContextShim contextShim = shimsMap.get(spanShim.getSpan()); diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TelemetryInfo.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TelemetryInfo.java index 1af5988001..e46d81ca60 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TelemetryInfo.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TelemetryInfo.java @@ -16,28 +16,27 @@ package io.opentelemetry.opentracingshim; +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.CorrelationContextManager; import io.opentelemetry.trace.Tracer; /** - * Utility class that holds a Tracer, a CorrelationContextManager, and related objects that are core - * part of the OT Shim layer. + * Utility class that holds a Tracer, a BaggageManager, and related objects that are core part of + * the OT Shim layer. */ final class TelemetryInfo { private final Tracer tracer; - private final CorrelationContextManager contextManager; - private final CorrelationContext emptyCorrelationContext; + private final BaggageManager contextManager; + private final Baggage emptyBaggage; private final ContextPropagators propagators; private final SpanContextShimTable spanContextTable; - TelemetryInfo( - Tracer tracer, CorrelationContextManager contextManager, ContextPropagators propagators) { + TelemetryInfo(Tracer tracer, BaggageManager contextManager, ContextPropagators propagators) { this.tracer = tracer; this.contextManager = contextManager; this.propagators = propagators; - this.emptyCorrelationContext = contextManager.contextBuilder().build(); + this.emptyBaggage = contextManager.baggageBuilder().build(); this.spanContextTable = new SpanContextShimTable(); } @@ -45,7 +44,7 @@ final class TelemetryInfo { return tracer; } - CorrelationContextManager contextManager() { + BaggageManager contextManager() { return contextManager; } @@ -53,8 +52,8 @@ final class TelemetryInfo { return spanContextTable; } - CorrelationContext emptyCorrelationContext() { - return emptyCorrelationContext; + Baggage emptyBaggage() { + return emptyBaggage; } ContextPropagators propagators() { diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TraceShim.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TraceShim.java index ae527d3b91..1cc17d2593 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TraceShim.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TraceShim.java @@ -17,7 +17,7 @@ package io.opentelemetry.opentracingshim; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.correlationcontext.CorrelationContextManager; +import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.trace.Tracer; import io.opentelemetry.trace.TracerProvider; import java.util.Objects; @@ -27,7 +27,7 @@ public final class TraceShim { /** * Creates a {@code io.opentracing.Tracer} shim out of {@code OpenTelemetry.getTracer()} and - * {@code OpenTelemetry.getCorrelationContextManager()}. + * {@code OpenTelemetry.getBaggageManager()}. * * @return a {@code io.opentracing.Tracer}. * @since 0.1.0 @@ -36,21 +36,21 @@ public final class TraceShim { return new TracerShim( new TelemetryInfo( getTracer(OpenTelemetry.getTracerProvider()), - OpenTelemetry.getCorrelationContextManager(), + OpenTelemetry.getBaggageManager(), OpenTelemetry.getPropagators())); } /** * Creates a {@code io.opentracing.Tracer} shim out the specified {@code Tracer} and {@code - * CorrelationContextManager}. + * BaggageManager}. * * @param tracerProvider the {@code TracerProvider} used by this shim. - * @param contextManager the {@code CorrelationContextManager} used by this shim. + * @param contextManager the {@code BaggageManager} used by this shim. * @return a {@code io.opentracing.Tracer}. * @since 0.1.0 */ public static io.opentracing.Tracer createTracerShim( - TracerProvider tracerProvider, CorrelationContextManager contextManager) { + TracerProvider tracerProvider, BaggageManager contextManager) { return new TracerShim( new TelemetryInfo( getTracer(Objects.requireNonNull(tracerProvider, "tracerProvider")), diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java index b705be8a3c..0151b22b31 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java @@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.trace.Tracer; import org.junit.jupiter.api.Test; @@ -30,7 +30,7 @@ class SpanBuilderShimTest { private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build(); private final Tracer tracer = tracerSdkFactory.get("SpanShimTest"); private final TelemetryInfo telemetryInfo = - new TelemetryInfo(tracer, new CorrelationContextManagerSdk(), OpenTelemetry.getPropagators()); + new TelemetryInfo(tracer, new BaggageManagerSdk(), OpenTelemetry.getPropagators()); private static final String SPAN_NAME = "Span"; diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java index 81d1e2c768..2c690f634b 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java @@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.trace.Span; import io.opentelemetry.trace.Tracer; @@ -37,7 +37,7 @@ class SpanShimTest { private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build(); private final Tracer tracer = tracerSdkFactory.get("SpanShimTest"); private final TelemetryInfo telemetryInfo = - new TelemetryInfo(tracer, new CorrelationContextManagerSdk(), OpenTelemetry.getPropagators()); + new TelemetryInfo(tracer, new BaggageManagerSdk(), OpenTelemetry.getPropagators()); private Span span; private static final String SPAN_NAME = "Span"; diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TraceShimTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TraceShimTest.java index 69de13366c..b2ec85dceb 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TraceShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TraceShimTest.java @@ -16,13 +16,13 @@ package io.opentelemetry.opentracingshim; -import static io.opentelemetry.OpenTelemetry.getCorrelationContextManager; +import static io.opentelemetry.OpenTelemetry.getBaggageManager; import static io.opentelemetry.OpenTelemetry.getTracerProvider; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import org.junit.jupiter.api.Test; @@ -32,14 +32,14 @@ class TraceShimTest { void createTracerShim_default() { TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim(); assertEquals(OpenTelemetry.getTracer("opentracingshim"), tracerShim.tracer()); - assertEquals(OpenTelemetry.getCorrelationContextManager(), tracerShim.contextManager()); + assertEquals(OpenTelemetry.getBaggageManager(), tracerShim.contextManager()); } @Test void createTracerShim_nullTracer() { assertThrows( NullPointerException.class, - () -> TraceShim.createTracerShim(null, getCorrelationContextManager()), + () -> TraceShim.createTracerShim(null, getBaggageManager()), "tracerProvider"); } @@ -54,7 +54,7 @@ class TraceShimTest { @Test void createTracerShim() { TracerSdkProvider sdk = TracerSdkProvider.builder().build(); - CorrelationContextManagerSdk contextManager = new CorrelationContextManagerSdk(); + BaggageManagerSdk contextManager = new BaggageManagerSdk(); TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim(sdk, contextManager); assertEquals(sdk.get("opentracingshim"), tracerShim.tracer()); assertEquals(contextManager, tracerShim.contextManager()); diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java index 92c8b20e12..b203f2cde1 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java @@ -43,7 +43,7 @@ class TracerShimTest { new TracerShim( new TelemetryInfo( OpenTelemetry.getTracer("opentracingshim"), - OpenTelemetry.getCorrelationContextManager(), + OpenTelemetry.getBaggageManager(), OpenTelemetry.getPropagators())); } diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/OpenTelemetryInteroperabilityTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/OpenTelemetryInteroperabilityTest.java index 8d9d94df96..8b082bd1f5 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/OpenTelemetryInteroperabilityTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/OpenTelemetryInteroperabilityTest.java @@ -19,7 +19,7 @@ package io.opentelemetry.opentracingshim.testbed; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import io.opentelemetry.correlationcontext.DefaultCorrelationContextManager; +import io.opentelemetry.baggage.DefaultBaggageManager; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; import io.opentelemetry.sdk.trace.TracerSdkProvider; @@ -38,7 +38,7 @@ class OpenTelemetryInteroperabilityTest { private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); private final Tracer otTracer = - TraceShim.createTracerShim(sdk, DefaultCorrelationContextManager.getInstance()); + TraceShim.createTracerShim(sdk, DefaultBaggageManager.getInstance()); @BeforeEach void before() { diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/activespanreplacement/ActiveSpanReplacementTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/activespanreplacement/ActiveSpanReplacementTest.java index 11c3f185fd..e630fd6df8 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/activespanreplacement/ActiveSpanReplacementTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/activespanreplacement/ActiveSpanReplacementTest.java @@ -27,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.SpanId; @@ -46,7 +46,7 @@ class ActiveSpanReplacementTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final ExecutorService executor = Executors.newCachedThreadPool(); @Test diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/actorpropagation/ActorPropagationTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/actorpropagation/ActorPropagationTest.java index c907ec229e..4f6f4294fe 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/actorpropagation/ActorPropagationTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/actorpropagation/ActorPropagationTest.java @@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.Span.Kind; @@ -51,7 +51,7 @@ class ActorPropagationTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private Phaser phaser; @BeforeEach diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/baggagehandling/BaggageHandlingTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/baggagehandling/BaggageHandlingTest.java index 0be448f152..7b8a0d32c6 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/baggagehandling/BaggageHandlingTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/baggagehandling/BaggageHandlingTest.java @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentracing.Span; import io.opentracing.Tracer; @@ -34,7 +34,7 @@ public final class BaggageHandlingTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final ExecutorService executor = Executors.newCachedThreadPool(); @Test diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/clientserver/TestClientServerTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/clientserver/TestClientServerTest.java index 0ef59edffd..fb80e5bd55 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/clientserver/TestClientServerTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/clientserver/TestClientServerTest.java @@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.Span.Kind; @@ -42,7 +42,7 @@ class TestClientServerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final ArrayBlockingQueue queue = new ArrayBlockingQueue<>(10); private Server server; diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/concurrentcommonrequesthandler/HandlerTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/concurrentcommonrequesthandler/HandlerTest.java index 78e0078f68..a6f2c44b20 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/concurrentcommonrequesthandler/HandlerTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/concurrentcommonrequesthandler/HandlerTest.java @@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.Span.Kind; @@ -50,7 +50,7 @@ class HandlerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final Client client = new Client(new RequestHandler(tracer)); @BeforeEach diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/errorreporting/ErrorReportingTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/errorreporting/ErrorReportingTest.java index 9dfde9904b..2a79b1ad81 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/errorreporting/ErrorReportingTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/errorreporting/ErrorReportingTest.java @@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.data.SpanData.Event; @@ -48,7 +48,7 @@ public final class ErrorReportingTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final ExecutorService executor = Executors.newCachedThreadPool(); /* Very simple error handling **/ diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/latespanfinish/LateSpanFinishTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/latespanfinish/LateSpanFinishTest.java index a1b672f33e..f0b14b7fff 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/latespanfinish/LateSpanFinishTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/latespanfinish/LateSpanFinishTest.java @@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Scope; @@ -41,7 +41,7 @@ public final class LateSpanFinishTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final ExecutorService executor = Executors.newCachedThreadPool(); @Test diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/listenerperrequest/ListenerTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/listenerperrequest/ListenerTest.java index 8f1ae6a066..382ebe51bc 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/listenerperrequest/ListenerTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/listenerperrequest/ListenerTest.java @@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.Span; @@ -34,7 +34,7 @@ class ListenerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); @Test void test() throws Exception { diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/multiplecallbacks/MultipleCallbacksTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/multiplecallbacks/MultipleCallbacksTest.java index 9c6e4f4d58..a9639517f9 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/multiplecallbacks/MultipleCallbacksTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/multiplecallbacks/MultipleCallbacksTest.java @@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Scope; @@ -46,7 +46,7 @@ class MultipleCallbacksTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); @Test void test() { diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/nestedcallbacks/NestedCallbacksTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/nestedcallbacks/NestedCallbacksTest.java index 4dd658580c..85e7569014 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/nestedcallbacks/NestedCallbacksTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/nestedcallbacks/NestedCallbacksTest.java @@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.common.ReadableAttributes; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Scope; @@ -44,7 +44,7 @@ public final class NestedCallbacksTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final ExecutorService executor = Executors.newCachedThreadPool(); @Test diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/promisepropagation/PromisePropagationTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/promisepropagation/PromisePropagationTest.java index 937d746e1a..c5719df671 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/promisepropagation/PromisePropagationTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/promisepropagation/PromisePropagationTest.java @@ -23,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.common.AttributeKey; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.SpanId; @@ -50,7 +50,7 @@ class PromisePropagationTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private Phaser phaser; @BeforeEach diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/statelesscommonrequesthandler/HandlerTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/statelesscommonrequesthandler/HandlerTest.java index b787599d9a..9e604ece30 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/statelesscommonrequesthandler/HandlerTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/statelesscommonrequesthandler/HandlerTest.java @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Tracer; @@ -39,7 +39,7 @@ public final class HandlerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); private final Client client = new Client(new RequestHandler(tracer)); @BeforeEach diff --git a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/suspendresumepropagation/SuspendResumePropagationTest.java b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/suspendresumepropagation/SuspendResumePropagationTest.java index 6b3591e1d1..766922b769 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/suspendresumepropagation/SuspendResumePropagationTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/suspendresumepropagation/SuspendResumePropagationTest.java @@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.SpanId; @@ -39,7 +39,7 @@ class SuspendResumePropagationTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerProvider(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); @BeforeEach void before() {} diff --git a/sdk/all/build.gradle b/sdk/all/build.gradle index cbb7540e07..d395bc4fee 100644 --- a/sdk/all/build.gradle +++ b/sdk/all/build.gradle @@ -13,7 +13,7 @@ ext.propertiesDir = "build/generated/properties/io/opentelemetry/sdk" dependencies { api project(':opentelemetry-api'), project(':opentelemetry-sdk-common'), - project(':opentelemetry-sdk-correlation-context'), + project(':opentelemetry-sdk-baggage'), project(':opentelemetry-sdk-metrics'), project(':opentelemetry-sdk-tracing') diff --git a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java index 2ddffecf96..78bf63a451 100644 --- a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java +++ b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java @@ -18,14 +18,14 @@ package io.opentelemetry.sdk; import io.opentelemetry.OpenTelemetry; import io.opentelemetry.internal.Obfuscated; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.metrics.MeterSdkProvider; import io.opentelemetry.sdk.trace.TracerSdkProvider; import javax.annotation.concurrent.ThreadSafe; /** * This class provides a static global accessor for SDK telemetry objects {@link TracerSdkProvider}, - * {@link MeterSdkProvider} and {@link CorrelationContextManagerSdk}. + * {@link MeterSdkProvider} and {@link BaggageManagerSdk}. * *

This is a convenience class getting and casting the telemetry objects from {@link * OpenTelemetry}. @@ -53,12 +53,12 @@ public final class OpenTelemetrySdk { } /** - * Returns a {@link CorrelationContextManagerSdk}. + * Returns a {@link BaggageManagerSdk}. * - * @return context manager returned by {@link OpenTelemetry#getCorrelationContextManager()}. + * @return context manager returned by {@link OpenTelemetry#getBaggageManager()}. */ - public static CorrelationContextManagerSdk getCorrelationContextManager() { - return (CorrelationContextManagerSdk) OpenTelemetry.getCorrelationContextManager(); + public static BaggageManagerSdk getBaggageManager() { + return (BaggageManagerSdk) OpenTelemetry.getBaggageManager(); } private OpenTelemetrySdk() {} diff --git a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java index a408fa5316..606adde456 100644 --- a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java +++ b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java @@ -27,8 +27,7 @@ class OpenTelemetrySdkTest { void testDefault() { assertThat(OpenTelemetrySdk.getTracerProvider().get("")) .isSameAs(OpenTelemetry.getTracerProvider().get("")); - assertThat(OpenTelemetrySdk.getCorrelationContextManager()) - .isSameAs(OpenTelemetry.getCorrelationContextManager()); + assertThat(OpenTelemetrySdk.getBaggageManager()).isSameAs(OpenTelemetry.getBaggageManager()); assertThat(OpenTelemetrySdk.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider()); } diff --git a/sdk/correlation_context/build.gradle b/sdk/baggage/build.gradle similarity index 89% rename from sdk/correlation_context/build.gradle rename to sdk/baggage/build.gradle index af0c04a07a..87512f6337 100644 --- a/sdk/correlation_context/build.gradle +++ b/sdk/baggage/build.gradle @@ -5,9 +5,9 @@ plugins { id "ru.vyarus.animalsniffer" } -description = 'OpenTelemetry SDK Correlation Context' -ext.moduleName = "io.opentelemetry.sdk.correlationcontext" -ext.propertiesDir = "build/generated/properties/io/opentelemetry/sdk/correlationcontext" +description = 'OpenTelemetry SDK Baggage' +ext.moduleName = "io.opentelemetry.sdk.baggage" +ext.propertiesDir = "build/generated/properties/io/opentelemetry/sdk/baggage" dependencies { api project(':opentelemetry-api'), diff --git a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageManagerSdk.java b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageManagerSdk.java new file mode 100644 index 0000000000..377ce4670a --- /dev/null +++ b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageManagerSdk.java @@ -0,0 +1,41 @@ +/* + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.sdk.baggage; + +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.BaggageManager; +import io.opentelemetry.baggage.BaggageUtils; +import io.opentelemetry.context.Scope; + +/** {@link BaggageManagerSdk} is SDK implementation of {@link BaggageManager}. */ +public class BaggageManagerSdk implements BaggageManager { + + @Override + public Baggage getCurrentBaggage() { + return BaggageUtils.getCurrentBaggage(); + } + + @Override + public Baggage.Builder baggageBuilder() { + return new BaggageSdk.Builder(); + } + + @Override + public Scope withContext(Baggage distContext) { + return BaggageUtils.currentContextWith(distContext); + } +} diff --git a/sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextSdk.java b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageSdk.java similarity index 70% rename from sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextSdk.java rename to sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageSdk.java index 6b9736fb81..831c7a10c9 100644 --- a/sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextSdk.java +++ b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageSdk.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package io.opentelemetry.sdk.correlationcontext; +package io.opentelemetry.sdk.baggage; import io.grpc.Context; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.CorrelationsContextUtils; -import io.opentelemetry.correlationcontext.Entry; -import io.opentelemetry.correlationcontext.EntryMetadata; +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.BaggageUtils; +import io.opentelemetry.baggage.Entry; +import io.opentelemetry.baggage.EntryMetadata; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -34,19 +34,19 @@ import javax.annotation.concurrent.Immutable; @Immutable // TODO: Migrate to AutoValue // @AutoValue -class CorrelationContextSdk implements CorrelationContext { +class BaggageSdk implements Baggage { // The types of the EntryKey and Entry must match for each entry. private final Map entries; - @Nullable private final CorrelationContext parent; + @Nullable private final Baggage parent; /** - * Creates a new {@link CorrelationContextSdk} with the given entries. + * Creates a new {@link BaggageSdk} with the given entries. * - * @param entries the initial entries for this {@code CorrelationContextSdk}. + * @param entries the initial entries for this {@code BaggageSdk}. * @param parent providing a default set of entries */ - private CorrelationContextSdk(Map entries, CorrelationContext parent) { + private BaggageSdk(Map entries, Baggage parent) { this.entries = Collections.unmodifiableMap(new HashMap<>(Objects.requireNonNull(entries, "entries"))); this.parent = parent; @@ -88,11 +88,11 @@ class CorrelationContextSdk implements CorrelationContext { if (this == o) { return true; } - if (o == null || !(o instanceof CorrelationContextSdk)) { + if (o == null || !(o instanceof BaggageSdk)) { return false; } - CorrelationContextSdk distContextSdk = (CorrelationContextSdk) o; + BaggageSdk distContextSdk = (BaggageSdk) o; if (!entries.equals(distContextSdk.entries)) { return false; @@ -109,38 +109,38 @@ class CorrelationContextSdk implements CorrelationContext { // TODO: Migrate to AutoValue.Builder // @AutoValue.Builder - static class Builder implements CorrelationContext.Builder { - @Nullable private CorrelationContext parent; + static class Builder implements Baggage.Builder { + @Nullable private Baggage parent; private boolean noImplicitParent; private final Map entries; - /** Create a new empty CorrelationContext builder. */ + /** Create a new empty Baggage builder. */ Builder() { this.entries = new HashMap<>(); } @Override - public CorrelationContext.Builder setParent(CorrelationContext parent) { + public Baggage.Builder setParent(Baggage parent) { this.parent = Objects.requireNonNull(parent, "parent"); return this; } @Override - public CorrelationContext.Builder setParent(Context context) { + public Baggage.Builder setParent(Context context) { Objects.requireNonNull(context, "context"); - setParent(CorrelationsContextUtils.getCorrelationContext(context)); + setParent(BaggageUtils.getBaggage(context)); return this; } @Override - public CorrelationContext.Builder setNoParent() { + public Baggage.Builder setNoParent() { this.parent = null; noImplicitParent = true; return this; } @Override - public CorrelationContext.Builder put(String key, String value, EntryMetadata entryMetadata) { + public Baggage.Builder put(String key, String value, EntryMetadata entryMetadata) { entries.put( Objects.requireNonNull(key, "key"), Entry.create( @@ -151,7 +151,7 @@ class CorrelationContextSdk implements CorrelationContext { } @Override - public CorrelationContext.Builder remove(String key) { + public Baggage.Builder remove(String key) { entries.remove(Objects.requireNonNull(key, "key")); if (parent != null && parent.getEntryValue(key) != null) { entries.put(key, null); @@ -160,11 +160,11 @@ class CorrelationContextSdk implements CorrelationContext { } @Override - public CorrelationContextSdk build() { + public BaggageSdk build() { if (parent == null && !noImplicitParent) { - parent = OpenTelemetry.getCorrelationContextManager().getCurrentContext(); + parent = OpenTelemetry.getBaggageManager().getCurrentBaggage(); } - return new CorrelationContextSdk(entries, parent); + return new BaggageSdk(entries, parent); } } } diff --git a/sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/spi/CorrelationContextManagerFactorySdk.java b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdk.java similarity index 56% rename from sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/spi/CorrelationContextManagerFactorySdk.java rename to sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdk.java index 7b87df1ec8..a89d712916 100644 --- a/sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/spi/CorrelationContextManagerFactorySdk.java +++ b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdk.java @@ -14,23 +14,22 @@ * limitations under the License. */ -package io.opentelemetry.sdk.correlationcontext.spi; +package io.opentelemetry.sdk.baggage.spi; -import io.opentelemetry.correlationcontext.CorrelationContextManager; -import io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.baggage.BaggageManager; +import io.opentelemetry.baggage.spi.BaggageManagerFactory; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; /** - * {@code CorrelationContextManager} provider implementation for {@link - * CorrelationContextManagerFactory}. + * {@code BaggageManager} provider implementation for {@link BaggageManagerFactory}. * *

This class is not intended to be used in application code and it is used only by {@link * io.opentelemetry.OpenTelemetry}. */ -public final class CorrelationContextManagerFactorySdk implements CorrelationContextManagerFactory { +public final class BaggageManagerFactorySdk implements BaggageManagerFactory { @Override - public CorrelationContextManager create() { - return new CorrelationContextManagerSdk(); + public BaggageManager create() { + return new BaggageManagerSdk(); } } diff --git a/sdk/baggage/src/main/resources/META-INF/services/io.opentelemetry.baggage.spi.BaggageManagerFactory b/sdk/baggage/src/main/resources/META-INF/services/io.opentelemetry.baggage.spi.BaggageManagerFactory new file mode 100644 index 0000000000..df5ae9c7e6 --- /dev/null +++ b/sdk/baggage/src/main/resources/META-INF/services/io.opentelemetry.baggage.spi.BaggageManagerFactory @@ -0,0 +1 @@ +io.opentelemetry.sdk.baggage.spi.BaggageManagerFactorySdk diff --git a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdkTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageManagerSdkTest.java similarity index 54% rename from sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdkTest.java rename to sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageManagerSdkTest.java index 5a28cfd51e..306734e1be 100644 --- a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdkTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageManagerSdkTest.java @@ -14,27 +14,27 @@ * limitations under the License. */ -package io.opentelemetry.sdk.correlationcontext; +package io.opentelemetry.sdk.baggage; import static org.assertj.core.api.Assertions.assertThat; import io.grpc.Context; +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.BaggageUtils; +import io.opentelemetry.baggage.EmptyBaggage; import io.opentelemetry.context.Scope; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.CorrelationsContextUtils; -import io.opentelemetry.correlationcontext.EmptyCorrelationContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -/** Unit tests for {@link CorrelationContextManagerSdk}. */ +/** Unit tests for {@link BaggageManagerSdk}. */ // Need to suppress warnings for MustBeClosed because Android 14 does not support // try-with-resources. @SuppressWarnings("MustBeClosedChecker") -class CorrelationContextManagerSdkTest { - @Mock private CorrelationContext distContext; - private final CorrelationContextManagerSdk contextManager = new CorrelationContextManagerSdk(); +class BaggageManagerSdkTest { + @Mock private Baggage distContext; + private final BaggageManagerSdk contextManager = new BaggageManagerSdk(); @BeforeEach void setUp() { @@ -43,15 +43,14 @@ class CorrelationContextManagerSdkTest { @Test void testGetCurrentContext_DefaultContext() { - assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance()); + assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); } @Test void testGetCurrentContext_ContextSetToNull() { - Context orig = - CorrelationsContextUtils.withCorrelationContext(null, Context.current()).attach(); + Context orig = BaggageUtils.withBaggage(null, Context.current()).attach(); try { - CorrelationContext distContext = contextManager.getCurrentContext(); + Baggage distContext = contextManager.getCurrentBaggage(); assertThat(distContext).isNotNull(); assertThat(distContext.getEntries()).isEmpty(); } finally { @@ -60,28 +59,28 @@ class CorrelationContextManagerSdkTest { } @Test - void testWithCorrelationContext() { - assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance()); + void testWithBaggage() { + assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); try (Scope wtm = contextManager.withContext(distContext)) { - assertThat(contextManager.getCurrentContext()).isSameAs(distContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(distContext); } - assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance()); + assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); } @Test - void testWithCorrelationContextUsingWrap() { + void testWithBaggageUsingWrap() { Runnable runnable; try (Scope wtm = contextManager.withContext(distContext)) { - assertThat(contextManager.getCurrentContext()).isSameAs(distContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(distContext); runnable = Context.current() .wrap( () -> { - assertThat(contextManager.getCurrentContext()).isSameAs(distContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(distContext); }); } - assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance()); - // When we run the runnable we will have the CorrelationContext in the current Context. + assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); + // When we run the runnable we will have the Baggage in the current Context. runnable.run(); } } diff --git a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextSdkTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageSdkTest.java similarity index 53% rename from sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextSdkTest.java rename to sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageSdkTest.java index 7bc36f9237..ba962c9b13 100644 --- a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextSdkTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageSdkTest.java @@ -14,30 +14,29 @@ * limitations under the License. */ -package io.opentelemetry.sdk.correlationcontext; +package io.opentelemetry.sdk.baggage; -import static io.opentelemetry.sdk.correlationcontext.CorrelationContextTestUtil.listToCorrelationContext; +import static io.opentelemetry.sdk.baggage.BaggageTestUtil.listToBaggage; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.testing.EqualsTester; import io.grpc.Context; +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.BaggageManager; +import io.opentelemetry.baggage.BaggageUtils; +import io.opentelemetry.baggage.Entry; +import io.opentelemetry.baggage.EntryMetadata; import io.opentelemetry.context.Scope; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.CorrelationContextManager; -import io.opentelemetry.correlationcontext.CorrelationsContextUtils; -import io.opentelemetry.correlationcontext.Entry; -import io.opentelemetry.correlationcontext.EntryMetadata; import org.junit.jupiter.api.Test; /** - * Tests for {@link CorrelationContextSdk} and {@link CorrelationContextSdk.Builder}. + * Tests for {@link BaggageSdk} and {@link BaggageSdk.Builder}. * - *

Tests for scope management with {@link CorrelationContextManagerSdk} are in {@link - * ScopedCorrelationContextTest}. + *

Tests for scope management with {@link BaggageManagerSdk} are in {@link ScopedBaggageTest}. */ -class CorrelationContextSdkTest { - private final CorrelationContextManager contextManager = new CorrelationContextManagerSdk(); +class BaggageSdkTest { + private final BaggageManager contextManager = new BaggageManagerSdk(); private static final EntryMetadata TMD = EntryMetadata.create(EntryMetadata.EntryTtl.UNLIMITED_PROPAGATION); @@ -53,23 +52,23 @@ class CorrelationContextSdkTest { @Test void getEntries_empty() { - CorrelationContextSdk distContext = new CorrelationContextSdk.Builder().build(); + BaggageSdk distContext = new BaggageSdk.Builder().build(); assertThat(distContext.getEntries()).isEmpty(); } @Test void getEntries_nonEmpty() { - CorrelationContextSdk distContext = listToCorrelationContext(T1, T2); + BaggageSdk distContext = listToBaggage(T1, T2); assertThat(distContext.getEntries()).containsExactly(T1, T2); } @Test void getEntries_chain() { Entry t1alt = Entry.create(K1, V2, TMD); - CorrelationContextSdk parent = listToCorrelationContext(T1, T2); - CorrelationContext distContext = + BaggageSdk parent = listToBaggage(T1, T2); + Baggage distContext = contextManager - .contextBuilder() + .baggageBuilder() .setParent(parent) .put(t1alt.getKey(), t1alt.getValue(), t1alt.getEntryMetadata()) .build(); @@ -78,10 +77,10 @@ class CorrelationContextSdkTest { @Test void put_newKey() { - CorrelationContextSdk distContext = listToCorrelationContext(T1); + BaggageSdk distContext = listToBaggage(T1); assertThat( contextManager - .contextBuilder() + .baggageBuilder() .setParent(distContext) .put(K2, V2, TMD) .build() @@ -91,10 +90,10 @@ class CorrelationContextSdkTest { @Test void put_existingKey() { - CorrelationContextSdk distContext = listToCorrelationContext(T1); + BaggageSdk distContext = listToBaggage(T1); assertThat( contextManager - .contextBuilder() + .baggageBuilder() .setParent(distContext) .put(K1, V2, TMD) .build() @@ -104,71 +103,61 @@ class CorrelationContextSdkTest { @Test void put_nullKey() { - CorrelationContextSdk distContext = listToCorrelationContext(T1); - CorrelationContext.Builder builder = contextManager.contextBuilder().setParent(distContext); + BaggageSdk distContext = listToBaggage(T1); + Baggage.Builder builder = contextManager.baggageBuilder().setParent(distContext); assertThrows(NullPointerException.class, () -> builder.put(null, V2, TMD), "key"); } @Test void put_nullValue() { - CorrelationContextSdk distContext = listToCorrelationContext(T1); - CorrelationContext.Builder builder = contextManager.contextBuilder().setParent(distContext); + BaggageSdk distContext = listToBaggage(T1); + Baggage.Builder builder = contextManager.baggageBuilder().setParent(distContext); assertThrows(NullPointerException.class, () -> builder.put(K2, null, TMD), "value"); } @Test void setParent_nullValue() { - CorrelationContextSdk parent = listToCorrelationContext(T1); + BaggageSdk parent = listToBaggage(T1); assertThrows( NullPointerException.class, - () -> - contextManager - .contextBuilder() - .setParent(parent) - .setParent((CorrelationContext) null) - .build()); + () -> contextManager.baggageBuilder().setParent(parent).setParent((Baggage) null).build()); } @Test void setParent_nullContext() { assertThrows( NullPointerException.class, - () -> contextManager.contextBuilder().setParent((Context) null)); + () -> contextManager.baggageBuilder().setParent((Context) null)); } @Test void setParent_fromContext() { - CorrelationContextSdk parent = listToCorrelationContext(T1); - Context context = - CorrelationsContextUtils.withCorrelationContext( - listToCorrelationContext(T2), Context.current()); - CorrelationContext corrContext = - contextManager.contextBuilder().setParent(parent).setParent(context).build(); - assertThat(corrContext.getEntries()).containsExactly(T2); + BaggageSdk parent = listToBaggage(T1); + Context context = BaggageUtils.withBaggage(listToBaggage(T2), Context.current()); + Baggage baggage = contextManager.baggageBuilder().setParent(parent).setParent(context).build(); + assertThat(baggage.getEntries()).containsExactly(T2); } @Test void setParent_fromEmptyContext() { Context emptyContext = Context.current(); - CorrelationContextSdk parent = listToCorrelationContext(T1); - try (Scope scope = CorrelationsContextUtils.currentContextWith(parent)) { - CorrelationContext corrContext = - contextManager.contextBuilder().setParent(emptyContext).build(); - assertThat(corrContext.getEntries()).isEmpty(); + BaggageSdk parent = listToBaggage(T1); + try (Scope scope = BaggageUtils.currentContextWith(parent)) { + Baggage baggage = contextManager.baggageBuilder().setParent(emptyContext).build(); + assertThat(baggage.getEntries()).isEmpty(); } } @Test void setParent_setNoParent() { - CorrelationContextSdk parent = listToCorrelationContext(T1); - CorrelationContext distContext = - contextManager.contextBuilder().setParent(parent).setNoParent().build(); + BaggageSdk parent = listToBaggage(T1); + Baggage distContext = contextManager.baggageBuilder().setParent(parent).setNoParent().build(); assertThat(distContext.getEntries()).isEmpty(); } @Test void remove_existingKey() { - CorrelationContextSdk.Builder builder = new CorrelationContextSdk.Builder(); + BaggageSdk.Builder builder = new BaggageSdk.Builder(); builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata()); builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata()); @@ -177,7 +166,7 @@ class CorrelationContextSdkTest { @Test void remove_differentKey() { - CorrelationContextSdk.Builder builder = new CorrelationContextSdk.Builder(); + BaggageSdk.Builder builder = new BaggageSdk.Builder(); builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata()); builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata()); @@ -186,15 +175,15 @@ class CorrelationContextSdkTest { @Test void remove_keyFromParent() { - CorrelationContextSdk distContext = listToCorrelationContext(T1, T2); + BaggageSdk distContext = listToBaggage(T1, T2); assertThat( - contextManager.contextBuilder().setParent(distContext).remove(K1).build().getEntries()) + contextManager.baggageBuilder().setParent(distContext).remove(K1).build().getEntries()) .containsExactly(T2); } @Test void remove_nullKey() { - CorrelationContext.Builder builder = contextManager.contextBuilder(); + Baggage.Builder builder = contextManager.baggageBuilder(); assertThrows(NullPointerException.class, () -> builder.remove(null), "key"); } @@ -202,11 +191,11 @@ class CorrelationContextSdkTest { void testEquals() { new EqualsTester() .addEqualityGroup( - contextManager.contextBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(), - contextManager.contextBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(), - contextManager.contextBuilder().put(K2, V2, TMD).put(K1, V1, TMD).build()) - .addEqualityGroup(contextManager.contextBuilder().put(K1, V1, TMD).put(K2, V1, TMD).build()) - .addEqualityGroup(contextManager.contextBuilder().put(K1, V2, TMD).put(K2, V1, TMD).build()) + contextManager.baggageBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(), + contextManager.baggageBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(), + contextManager.baggageBuilder().put(K2, V2, TMD).put(K1, V1, TMD).build()) + .addEqualityGroup(contextManager.baggageBuilder().put(K1, V1, TMD).put(K2, V1, TMD).build()) + .addEqualityGroup(contextManager.baggageBuilder().put(K1, V2, TMD).put(K2, V1, TMD).build()) .testEquals(); } } diff --git a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextTestUtil.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageTestUtil.java similarity index 63% rename from sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextTestUtil.java rename to sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageTestUtil.java index 0db4f7860f..798af00af5 100644 --- a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextTestUtil.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageTestUtil.java @@ -14,25 +14,25 @@ * limitations under the License. */ -package io.opentelemetry.sdk.correlationcontext; +package io.opentelemetry.sdk.baggage; -import io.opentelemetry.correlationcontext.Entry; +import io.opentelemetry.baggage.Entry; import java.util.Arrays; import java.util.List; -class CorrelationContextTestUtil { +class BaggageTestUtil { - static CorrelationContextSdk listToCorrelationContext(Entry... entries) { - return listToCorrelationContext(Arrays.asList(entries)); + static BaggageSdk listToBaggage(Entry... entries) { + return listToBaggage(Arrays.asList(entries)); } - static CorrelationContextSdk listToCorrelationContext(List entries) { - CorrelationContextSdk.Builder builder = new CorrelationContextSdk.Builder(); + static BaggageSdk listToBaggage(List entries) { + BaggageSdk.Builder builder = new BaggageSdk.Builder(); for (Entry entry : entries) { builder.put(entry.getKey(), entry.getValue(), entry.getEntryMetadata()); } return builder.build(); } - private CorrelationContextTestUtil() {} + private BaggageTestUtil() {} } diff --git a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/ScopedCorrelationContextTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java similarity index 59% rename from sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/ScopedCorrelationContextTest.java rename to sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java index a49fd1429b..e0425cf671 100644 --- a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/ScopedCorrelationContextTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java @@ -14,23 +14,23 @@ * limitations under the License. */ -package io.opentelemetry.sdk.correlationcontext; +package io.opentelemetry.sdk.baggage; import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.baggage.Baggage; +import io.opentelemetry.baggage.BaggageManager; +import io.opentelemetry.baggage.EmptyBaggage; +import io.opentelemetry.baggage.Entry; +import io.opentelemetry.baggage.EntryMetadata; import io.opentelemetry.context.Scope; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.CorrelationContextManager; -import io.opentelemetry.correlationcontext.EmptyCorrelationContext; -import io.opentelemetry.correlationcontext.Entry; -import io.opentelemetry.correlationcontext.EntryMetadata; import org.junit.jupiter.api.Test; /** - * Unit tests for the methods in {@link CorrelationContextManagerSdk} and {@link - * CorrelationContextSdk.Builder} that interact with the current {@link CorrelationContextSdk}. + * Unit tests for the methods in {@link BaggageManagerSdk} and {@link BaggageSdk.Builder} that + * interact with the current {@link BaggageSdk}. */ -class ScopedCorrelationContextTest { +class ScopedBaggageTest { private static final String KEY_1 = "key 1"; private static final String KEY_2 = "key 2"; private static final String KEY_3 = "key 3"; @@ -45,120 +45,120 @@ class ScopedCorrelationContextTest { private static final EntryMetadata METADATA_NO_PROPAGATION = EntryMetadata.create(EntryMetadata.EntryTtl.NO_PROPAGATION); - private final CorrelationContextManager contextManager = new CorrelationContextManagerSdk(); + private final BaggageManager contextManager = new BaggageManagerSdk(); @Test - void emptyCorrelationContext() { - CorrelationContext defaultCorrelationContext = contextManager.getCurrentContext(); - assertThat(defaultCorrelationContext.getEntries()).isEmpty(); - assertThat(defaultCorrelationContext).isInstanceOf(EmptyCorrelationContext.class); + void emptyBaggage() { + Baggage defaultBaggage = contextManager.getCurrentBaggage(); + assertThat(defaultBaggage.getEntries()).isEmpty(); + assertThat(defaultBaggage).isInstanceOf(EmptyBaggage.class); } @Test void withContext() { - assertThat(contextManager.getCurrentContext().getEntries()).isEmpty(); - CorrelationContext scopedEntries = - contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + Baggage scopedEntries = + contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); try (Scope scope = contextManager.withContext(scopedEntries)) { - assertThat(contextManager.getCurrentContext()).isSameAs(scopedEntries); + assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedEntries); } - assertThat(contextManager.getCurrentContext().getEntries()).isEmpty(); + assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); } @Test void createBuilderFromCurrentEntries() { - CorrelationContext scopedDistContext = - contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + Baggage scopedDistContext = + contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); try (Scope scope = contextManager.withContext(scopedDistContext)) { - CorrelationContext newEntries = + Baggage newEntries = contextManager - .contextBuilder() + .baggageBuilder() .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) .build(); assertThat(newEntries.getEntries()) .containsExactlyInAnyOrder( Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION), Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)); - assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext); } } @Test void setCurrentEntriesWithBuilder() { - assertThat(contextManager.getCurrentContext().getEntries()).isEmpty(); - CorrelationContext scopedDistContext = - contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + Baggage scopedDistContext = + contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); try (Scope scope = contextManager.withContext(scopedDistContext)) { - assertThat(contextManager.getCurrentContext().getEntries()) + assertThat(contextManager.getCurrentBaggage().getEntries()) .containsExactly(Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION)); - assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext); } - assertThat(contextManager.getCurrentContext().getEntries()).isEmpty(); + assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); } @Test void addToCurrentEntriesWithBuilder() { - CorrelationContext scopedDistContext = - contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + Baggage scopedDistContext = + contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); try (Scope scope1 = contextManager.withContext(scopedDistContext)) { - CorrelationContext innerDistContext = + Baggage innerDistContext = contextManager - .contextBuilder() + .baggageBuilder() .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) .build(); try (Scope scope2 = contextManager.withContext(innerDistContext)) { - assertThat(contextManager.getCurrentContext().getEntries()) + assertThat(contextManager.getCurrentBaggage().getEntries()) .containsExactlyInAnyOrder( Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION), Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)); - assertThat(contextManager.getCurrentContext()).isSameAs(innerDistContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(innerDistContext); } - assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext); } } @Test - void multiScopeCorrelationContextWithMetadata() { - CorrelationContext scopedDistContext = + void multiScopeBaggageWithMetadata() { + Baggage scopedDistContext = contextManager - .contextBuilder() + .baggageBuilder() .put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION) .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) .build(); try (Scope scope1 = contextManager.withContext(scopedDistContext)) { - CorrelationContext innerDistContext = + Baggage innerDistContext = contextManager - .contextBuilder() + .baggageBuilder() .put(KEY_3, VALUE_3, METADATA_NO_PROPAGATION) .put(KEY_2, VALUE_4, METADATA_NO_PROPAGATION) .build(); try (Scope scope2 = contextManager.withContext(innerDistContext)) { - assertThat(contextManager.getCurrentContext().getEntries()) + assertThat(contextManager.getCurrentBaggage().getEntries()) .containsExactlyInAnyOrder( Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION), Entry.create(KEY_2, VALUE_4, METADATA_NO_PROPAGATION), Entry.create(KEY_3, VALUE_3, METADATA_NO_PROPAGATION)); - assertThat(contextManager.getCurrentContext()).isSameAs(innerDistContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(innerDistContext); } - assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext); + assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext); } } @Test void setNoParent_doesNotInheritContext() { - assertThat(contextManager.getCurrentContext().getEntries()).isEmpty(); - CorrelationContext scopedDistContext = - contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + Baggage scopedDistContext = + contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); try (Scope scope = contextManager.withContext(scopedDistContext)) { - CorrelationContext innerDistContext = + Baggage innerDistContext = contextManager - .contextBuilder() + .baggageBuilder() .setNoParent() .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) .build(); assertThat(innerDistContext.getEntries()) .containsExactly(Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)); } - assertThat(contextManager.getCurrentContext().getEntries()).isEmpty(); + assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); } } diff --git a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/spi/CorrelationContextManagerFactorySdkTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdkTest.java similarity index 72% rename from sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/spi/CorrelationContextManagerFactorySdkTest.java rename to sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdkTest.java index 96aa30bf95..c8e5481ee6 100644 --- a/sdk/correlation_context/src/test/java/io/opentelemetry/sdk/correlationcontext/spi/CorrelationContextManagerFactorySdkTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdkTest.java @@ -14,19 +14,18 @@ * limitations under the License. */ -package io.opentelemetry.sdk.correlationcontext.spi; +package io.opentelemetry.sdk.baggage.spi; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk; +import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import org.junit.jupiter.api.Test; -class CorrelationContextManagerFactorySdkTest { +class BaggageManagerFactorySdkTest { @Test void testDefault() { - assertThat(OpenTelemetry.getCorrelationContextManager()) - .isInstanceOf(CorrelationContextManagerSdk.class); + assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(BaggageManagerSdk.class); } } diff --git a/sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdk.java b/sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdk.java deleted file mode 100644 index 1e009d0a65..0000000000 --- a/sdk/correlation_context/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdk.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.sdk.correlationcontext; - -import io.opentelemetry.context.Scope; -import io.opentelemetry.correlationcontext.CorrelationContext; -import io.opentelemetry.correlationcontext.CorrelationContextManager; -import io.opentelemetry.correlationcontext.CorrelationsContextUtils; - -/** - * {@link CorrelationContextManagerSdk} is SDK implementation of {@link CorrelationContextManager}. - */ -public class CorrelationContextManagerSdk implements CorrelationContextManager { - - @Override - public CorrelationContext getCurrentContext() { - return CorrelationsContextUtils.getCurrentCorrelationContext(); - } - - @Override - public CorrelationContext.Builder contextBuilder() { - return new CorrelationContextSdk.Builder(); - } - - @Override - public Scope withContext(CorrelationContext distContext) { - return CorrelationsContextUtils.currentContextWith(distContext); - } -} diff --git a/sdk/correlation_context/src/main/resources/META-INF/services/io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory b/sdk/correlation_context/src/main/resources/META-INF/services/io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory deleted file mode 100644 index 77ca54e08d..0000000000 --- a/sdk/correlation_context/src/main/resources/META-INF/services/io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory +++ /dev/null @@ -1 +0,0 @@ -io.opentelemetry.sdk.correlationcontext.spi.CorrelationContextManagerFactorySdk diff --git a/settings.gradle b/settings.gradle index 3542bfc94c..bfcdc69c41 100644 --- a/settings.gradle +++ b/settings.gradle @@ -35,8 +35,8 @@ include ":opentelemetry-all", ":opentelemetry-integration-tests-tracecontext", ":opentelemetry-opentracing-shim", ":opentelemetry-proto", + ":opentelemetry-sdk-baggage", ":opentelemetry-sdk-common", - ":opentelemetry-sdk-correlation-context", ":opentelemetry-sdk-metrics", ":opentelemetry-sdk-tracing", ":opentelemetry-sdk", @@ -53,14 +53,14 @@ include ":opentelemetry-all", rootProject.children.each { it.projectDir = "$rootDir/" + it.name - .replace("opentelemetry-integration-tests-", "integration_tests/") - .replace("opentelemetry-exporters-", "exporters/") - .replace("opentelemetry-extension-", "extensions/") - .replace("opentelemetry-sdk-extension-", "sdk_extensions/") - .replace("opentelemetry-sdk-", "sdk/") - .replace("logging-", "logging/") - .replace("opentelemetry-", "") - .replace("-", "_") as File + .replace("opentelemetry-integration-tests-", "integration_tests/") + .replace("opentelemetry-exporters-", "exporters/") + .replace("opentelemetry-extension-", "extensions/") + .replace("opentelemetry-sdk-extension-", "sdk_extensions/") + .replace("opentelemetry-sdk-", "sdk/") + .replace("logging-", "logging/") + .replace("opentelemetry-", "") + .replace("-", "_") as File } project(":opentelemetry-sdk").projectDir = "$rootDir/sdk/all" as File