From d591eecb82cb9d9eda3f4f6c5e09bf7dfb0d6ee8 Mon Sep 17 00:00:00 2001 From: jkwatson Date: Fri, 16 Oct 2020 16:17:06 -0700 Subject: [PATCH 1/4] Make the baggage API fully functional in the API and get rid of the BaggageManager that was needed previously. --- .../java/io/opentelemetry/OpenTelemetry.java | 19 +- .../io/opentelemetry/baggage/Baggage.java | 25 ++- .../opentelemetry/baggage/BaggageUtils.java | 2 +- .../baggage/DefaultBaggageManager.java | 77 -------- .../opentelemetry/baggage/EmptyBaggage.java | 39 ---- .../baggage/ImmutableBaggage.java | 45 +++-- .../propagation/W3CBaggagePropagator.java | 17 +- .../io/opentelemetry/OpenTelemetryTest.java | 79 +------- .../baggage/BaggageUtilsTest.java | 10 +- .../baggage/DefaultBaggageManagerTest.java | 127 ------------- .../propagation/W3CBaggagePropagatorTest.java | 173 +++--------------- .../opentracingshim/BaseShimObject.java | 6 +- .../opentracingshim/SpanContextShim.java | 2 +- .../opentracingshim/TelemetryInfo.java | 12 +- .../opentracingshim/TraceShim.java | 10 +- .../opentracingshim/SpanBuilderShimTest.java | 4 +- .../opentracingshim/SpanShimTest.java | 4 +- .../opentracingshim/TraceShimTest.java | 20 +- .../opentracingshim/TracerShimTest.java | 5 +- .../OpenTelemetryInteroperabilityTest.java | 5 +- .../ActiveSpanReplacementTest.java | 3 +- .../ActorPropagationTest.java | 3 +- .../baggagehandling/BaggageHandlingTest.java | 3 +- .../clientserver/TestClientServerTest.java | 3 +- .../HandlerTest.java | 3 +- .../errorreporting/ErrorReportingTest.java | 3 +- .../latespanfinish/LateSpanFinishTest.java | 3 +- .../listenerperrequest/ListenerTest.java | 3 +- .../MultipleCallbacksTest.java | 3 +- .../nestedcallbacks/NestedCallbacksTest.java | 3 +- .../PromisePropagationTest.java | 3 +- .../HandlerTest.java | 3 +- .../SuspendResumePropagationTest.java | 3 +- .../opentelemetry/sdk/OpenTelemetrySdk.java | 10 - .../sdk/OpenTelemetrySdkTest.java | 1 - .../sdk/baggage/BaggageManagerSdk.java | 30 --- .../sdk/baggage/package-info.java | 14 -- .../baggage/spi/BaggageManagerFactorySdk.java | 24 --- .../sdk/baggage/spi/package-info.java | 10 - .../sdk/baggage/BaggageManagerSdkTest.java | 28 ++- .../sdk/baggage/BaggageTestUtil.java | 7 +- ...SdkTest.java => ImmutableBaggageTest.java} | 81 +++----- .../sdk/baggage/ScopedBaggageTest.java | 91 ++++----- .../spi/BaggageManagerFactorySdkTest.java | 20 -- 44 files changed, 209 insertions(+), 827 deletions(-) delete mode 100644 api/src/main/java/io/opentelemetry/baggage/DefaultBaggageManager.java delete mode 100644 api/src/main/java/io/opentelemetry/baggage/EmptyBaggage.java rename sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageSdk.java => api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java (75%) delete mode 100644 api/src/test/java/io/opentelemetry/baggage/DefaultBaggageManagerTest.java delete mode 100644 sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageManagerSdk.java delete mode 100644 sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/package-info.java delete mode 100644 sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdk.java delete mode 100644 sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/package-info.java rename sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/{BaggageSdkTest.java => ImmutableBaggageTest.java} (61%) delete mode 100644 sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdkTest.java diff --git a/api/src/main/java/io/opentelemetry/OpenTelemetry.java b/api/src/main/java/io/opentelemetry/OpenTelemetry.java index 224e6b3a515..7c0873c0114 100644 --- a/api/src/main/java/io/opentelemetry/OpenTelemetry.java +++ b/api/src/main/java/io/opentelemetry/OpenTelemetry.java @@ -6,7 +6,6 @@ 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; @@ -37,13 +36,13 @@ */ @ThreadSafe public final class OpenTelemetry { + private static final Object mutex = new Object(); @Nullable private static volatile OpenTelemetry instance; private final TracerProvider tracerProvider; private final MeterProvider meterProvider; - private final BaggageManager contextManager; private volatile ContextPropagators propagators = DefaultContextPropagators.builder().build(); @@ -126,17 +125,6 @@ public static Meter getMeter(String instrumentationName, String instrumentationV return getMeterProvider().get(instrumentationName, instrumentationVersion); } - /** - * Returns a singleton {@link BaggageManager}. - * - * @return registered manager or default via {@link DefaultBaggageManager#getInstance()}. - * @throws IllegalStateException if a specified manager (via system properties) could not be - * found. - */ - public static BaggageManager getBaggageManager() { - return getInstance().contextManager; - } - /** * Returns a {@link ContextPropagators} object, which can be used to access the set of registered * propagators for each supported format. @@ -188,11 +176,6 @@ private OpenTelemetry() { meterProviderFactory != null ? meterProviderFactory.create() : DefaultMeterProvider.getInstance(); - BaggageManagerFactory contextManagerProvider = loadSpi(BaggageManagerFactory.class); - contextManager = - contextManagerProvider != null - ? contextManagerProvider.create() - : DefaultBaggageManager.getInstance(); } /** diff --git a/api/src/main/java/io/opentelemetry/baggage/Baggage.java b/api/src/main/java/io/opentelemetry/baggage/Baggage.java index a010d3074e7..f6c05347443 100644 --- a/api/src/main/java/io/opentelemetry/baggage/Baggage.java +++ b/api/src/main/java/io/opentelemetry/baggage/Baggage.java @@ -19,6 +19,15 @@ */ @Immutable public interface Baggage { + + static Baggage empty() { + return ImmutableBaggage.EMPTY; + } + + static Builder builder() { + return ImmutableBaggage.builder(); + } + /** * Returns an immutable collection of the entries in this {@code Baggage}. Order of entries is not * guaranteed. @@ -39,10 +48,11 @@ public interface Baggage { /** Builder for the {@link Baggage} class. */ interface Builder { + /** * 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. + * {@link Baggage} is provided, the value of {@link BaggageUtils#getCurrentBaggage()} at {@link + * #build()} time will be used as parent, unless {@link #setNoParent()} was 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. @@ -62,7 +72,7 @@ interface Builder { /** * Sets the option to become a root {@link Baggage} with no parent. If not called, the * value provided using {@link #setParent(Context)} or otherwise {@link - * BaggageManager#getCurrentBaggage()} at {@link #build()} time will be used as parent. + * BaggageUtils#getCurrentBaggage()} at {@link #build()} time will be used as parent. * * @return this. */ @@ -78,6 +88,15 @@ interface Builder { */ Builder put(String key, String value, EntryMetadata entryMetadata); + /** + * Adds the key/value pair with empty metadata regardless of whether the key is present. + * + * @param key the {@code String} key which will be set. + * @param value the {@code String} value to set for the given key. + * @return this + */ + Builder put(String key, String value); + /** * Removes the key if it exists. * diff --git a/api/src/main/java/io/opentelemetry/baggage/BaggageUtils.java b/api/src/main/java/io/opentelemetry/baggage/BaggageUtils.java index abe173ca9f1..c550d4db6f9 100644 --- a/api/src/main/java/io/opentelemetry/baggage/BaggageUtils.java +++ b/api/src/main/java/io/opentelemetry/baggage/BaggageUtils.java @@ -47,7 +47,7 @@ public static Baggage getCurrentBaggage() { */ public static Baggage getBaggage(Context context) { Baggage baggage = context.getValue(CORR_CONTEXT_KEY); - return baggage == null ? EmptyBaggage.getInstance() : baggage; + return baggage == null ? Baggage.empty() : baggage; } /** diff --git a/api/src/main/java/io/opentelemetry/baggage/DefaultBaggageManager.java b/api/src/main/java/io/opentelemetry/baggage/DefaultBaggageManager.java deleted file mode 100644 index 92cda3899e1..00000000000 --- a/api/src/main/java/io/opentelemetry/baggage/DefaultBaggageManager.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.baggage; - -import io.opentelemetry.context.Context; -import io.opentelemetry.context.Scope; -import java.util.Objects; -import javax.annotation.concurrent.Immutable; -import javax.annotation.concurrent.ThreadSafe; - -/** No-op implementations of {@link BaggageManager}. */ -@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 withBaggage(Baggage baggage) { - return BaggageUtils.currentContextWith(baggage); - } - - @Immutable - private static final class NoopBaggageBuilder implements Baggage.Builder { - @Override - public Baggage.Builder setParent(Context context) { - Objects.requireNonNull(context, "context"); - return this; - } - - @Override - public Baggage.Builder setNoParent() { - return this; - } - - @Override - public Baggage.Builder put(String key, String value, EntryMetadata entryMetadata) { - Objects.requireNonNull(key, "key"); - Objects.requireNonNull(value, "value"); - Objects.requireNonNull(entryMetadata, "entryMetadata"); - return this; - } - - @Override - public Baggage.Builder remove(String key) { - Objects.requireNonNull(key, "key"); - return this; - } - - @Override - public Baggage build() { - return EmptyBaggage.getInstance(); - } - } -} diff --git a/api/src/main/java/io/opentelemetry/baggage/EmptyBaggage.java b/api/src/main/java/io/opentelemetry/baggage/EmptyBaggage.java deleted file mode 100644 index bab7b0230db..00000000000 --- a/api/src/main/java/io/opentelemetry/baggage/EmptyBaggage.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -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 Baggage} that does not contain any entries. */ -@Immutable -public class EmptyBaggage implements Baggage { - /** - * Returns the single instance of the {@link EmptyBaggage} class. - * - * @return the single instance of the {@code EmptyBaggage} class. - */ - public static Baggage getInstance() { - return INSTANCE; - } - - private static final Baggage INSTANCE = new EmptyBaggage(); - - @Override - public Collection getEntries() { - return Collections.emptyList(); - } - - @Nullable - @Override - public String getEntryValue(String entryKey) { - return null; - } - - private EmptyBaggage() {} -} diff --git a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageSdk.java b/api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java similarity index 75% rename from sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageSdk.java rename to api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java index f86b540d2b6..3965a13e340 100644 --- a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageSdk.java +++ b/api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java @@ -3,13 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.baggage; +package io.opentelemetry.baggage; -import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.baggage.Baggage; -import io.opentelemetry.baggage.BaggageUtils; -import io.opentelemetry.baggage.Entry; -import io.opentelemetry.baggage.EntryMetadata; import io.opentelemetry.context.Context; import java.util.Collection; import java.util.Collections; @@ -22,24 +17,29 @@ @Immutable // TODO: Migrate to AutoValue // @AutoValue -class BaggageSdk implements Baggage { +public class ImmutableBaggage implements Baggage { + static final Baggage EMPTY = new ImmutableBaggage.Builder().build(); // The types of the EntryKey and Entry must match for each entry. private final Map entries; @Nullable private final Baggage parent; /** - * Creates a new {@link BaggageSdk} with the given entries. + * Creates a new {@link ImmutableBaggage} with the given entries. * * @param entries the initial entries for this {@code BaggageSdk}. * @param parent providing a default set of entries */ - private BaggageSdk(Map entries, Baggage parent) { + private ImmutableBaggage(Map entries, Baggage parent) { this.entries = Collections.unmodifiableMap(new HashMap<>(Objects.requireNonNull(entries, "entries"))); this.parent = parent; } + public static Baggage.Builder builder() { + return new Builder(); + } + @Override public Collection getEntries() { Map combined = new HashMap<>(entries); @@ -72,16 +72,16 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof BaggageSdk)) { + if (!(o instanceof ImmutableBaggage)) { return false; } - BaggageSdk baggageSdk = (BaggageSdk) o; + ImmutableBaggage baggage = (ImmutableBaggage) o; - if (!entries.equals(baggageSdk.entries)) { + if (!entries.equals(baggage.entries)) { return false; } - return Objects.equals(parent, baggageSdk.parent); + return Objects.equals(parent, baggage.parent); } @Override @@ -91,6 +91,11 @@ public int hashCode() { return result; } + @Override + public String toString() { + return "ImmutableBaggage{" + "entries=" + entries + ", parent=" + parent + '}'; + } + // TODO: Migrate to AutoValue.Builder // @AutoValue.Builder static class Builder implements Baggage.Builder { @@ -128,6 +133,14 @@ public Baggage.Builder put(String key, String value, EntryMetadata entryMetadata return this; } + @Override + public Baggage.Builder put(String key, String value) { + entries.put( + Objects.requireNonNull(key, "key"), + Entry.create(key, Objects.requireNonNull(value, "value"), EntryMetadata.EMPTY)); + return this; + } + @Override public Baggage.Builder remove(String key) { entries.remove(Objects.requireNonNull(key, "key")); @@ -138,11 +151,11 @@ public Baggage.Builder remove(String key) { } @Override - public BaggageSdk build() { + public ImmutableBaggage build() { if (parent == null && !noImplicitParent) { - parent = OpenTelemetry.getBaggageManager().getCurrentBaggage(); + parent = BaggageUtils.getCurrentBaggage(); } - return new BaggageSdk(entries, parent); + return new ImmutableBaggage(entries, parent); } } } diff --git a/api/src/main/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagator.java b/api/src/main/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagator.java index ac57e08e38a..fce60cd7fc0 100644 --- a/api/src/main/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagator.java +++ b/api/src/main/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagator.java @@ -11,7 +11,6 @@ import io.opentelemetry.baggage.Baggage; import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.baggage.BaggageUtils; -import io.opentelemetry.baggage.EmptyBaggage; import io.opentelemetry.baggage.Entry; import io.opentelemetry.baggage.EntryMetadata; import io.opentelemetry.context.Context; @@ -26,15 +25,7 @@ public class W3CBaggagePropagator implements TextMapPropagator { private static final String FIELD = "baggage"; private static final List FIELDS = singletonList(FIELD); - private static final W3CBaggagePropagator INSTANCE = - new W3CBaggagePropagator(OpenTelemetry.getBaggageManager()); - - private final BaggageManager baggageManager; - - // visible for testing - W3CBaggagePropagator(BaggageManager baggageManager) { - this.baggageManager = baggageManager; - } + private static final W3CBaggagePropagator INSTANCE = new W3CBaggagePropagator(); /** * Singleton instance of the W3C Baggage Propagator. Uses the {@link BaggageManager} from the @@ -77,14 +68,14 @@ public Context extract(Context context, @Nullable C carrier, Getter gette return context; } if (baggageHeader.isEmpty()) { - return BaggageUtils.withBaggage(EmptyBaggage.getInstance(), context); + return BaggageUtils.withBaggage(Baggage.empty(), context); } - Baggage.Builder baggageBuilder = baggageManager.baggageBuilder(); + Baggage.Builder baggageBuilder = Baggage.builder(); try { extractEntries(baggageHeader, baggageBuilder); } catch (Exception e) { - return BaggageUtils.withBaggage(EmptyBaggage.getInstance(), context); + return BaggageUtils.withBaggage(Baggage.empty(), context); } return BaggageUtils.withBaggage(baggageBuilder.build(), context); } diff --git a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java index c76f4902e9c..d110d67ef5f 100644 --- a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java +++ b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java @@ -9,11 +9,6 @@ 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.metrics.BatchRecorder; @@ -60,7 +55,6 @@ void after() { OpenTelemetry.reset(); System.clearProperty(TracerProviderFactory.class.getName()); System.clearProperty(MeterProviderFactory.class.getName()); - System.clearProperty(BaggageManagerFactory.class.getName()); } @Test @@ -69,8 +63,6 @@ void testDefault() { assertThat(OpenTelemetry.getTracerProvider()).isSameAs(OpenTelemetry.getTracerProvider()); assertThat(OpenTelemetry.getMeterProvider()).isInstanceOf(DefaultMeterProvider.class); assertThat(OpenTelemetry.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider()); - assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(DefaultBaggageManager.class); - assertThat(OpenTelemetry.getBaggageManager()).isSameAs(OpenTelemetry.getBaggageManager()); assertThat(OpenTelemetry.getPropagators()).isInstanceOf(DefaultContextPropagators.class); assertThat(OpenTelemetry.getPropagators()).isSameAs(OpenTelemetry.getPropagators()); } @@ -155,41 +147,6 @@ void testMeterNotFound() { assertThrows(IllegalStateException.class, () -> OpenTelemetry.getMeterProvider()); } - @Test - void testBaggageManagerLoadArbitrary() throws IOException { - File serviceFile = - createService( - BaggageManagerFactory.class, FirstBaggageManager.class, SecondBaggageManager.class); - try { - assertTrue( - (OpenTelemetry.getBaggageManager() instanceof FirstBaggageManager) - || (OpenTelemetry.getBaggageManager() instanceof SecondBaggageManager)); - assertThat(OpenTelemetry.getBaggageManager()).isEqualTo(OpenTelemetry.getBaggageManager()); - } finally { - serviceFile.delete(); - } - } - - @Test - void testBaggageManagerSystemProperty() throws IOException { - File serviceFile = - createService( - BaggageManagerFactory.class, FirstBaggageManager.class, SecondBaggageManager.class); - System.setProperty(BaggageManagerFactory.class.getName(), SecondBaggageManager.class.getName()); - try { - assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(SecondBaggageManager.class); - assertThat(OpenTelemetry.getBaggageManager()).isEqualTo(OpenTelemetry.getBaggageManager()); - } finally { - serviceFile.delete(); - } - } - - @Test - void testBaggageManagerNotFound() { - System.setProperty(BaggageManagerFactory.class.getName(), "io.does.not.exists"); - assertThrows(IllegalStateException.class, () -> OpenTelemetry.getBaggageManager()); - } - @Test void testPropagatorsSet() { ContextPropagators propagators = DefaultContextPropagators.builder().build(); @@ -218,6 +175,7 @@ private static File createService(Class service, Class... impls) throws IO } public static class SecondTracerProviderFactory extends FirstTracerProviderFactory { + @Override public Tracer get(String instrumentationName) { return new SecondTracerProviderFactory(); @@ -236,6 +194,7 @@ public TracerProvider create() { public static class FirstTracerProviderFactory implements Tracer, TracerProvider, TracerProviderFactory { + @Override public Tracer get(String instrumentationName) { return new FirstTracerProviderFactory(); @@ -259,6 +218,7 @@ public TracerProvider create() { } public static class SecondMeterProviderFactory extends FirstMeterProviderFactory { + @Override public Meter get(String instrumentationName) { return new SecondMeterProviderFactory(); @@ -277,6 +237,7 @@ public MeterProvider create() { public static class FirstMeterProviderFactory implements Meter, MeterProviderFactory, MeterProvider { + @Override public MeterProvider create() { return new FirstMeterProviderFactory(); @@ -370,36 +331,4 @@ public Meter get(String instrumentationName, String instrumentationVersion) { return get(instrumentationName); } } - - public static class SecondBaggageManager extends FirstBaggageManager { - @Override - public BaggageManager create() { - return new SecondBaggageManager(); - } - } - - public static class FirstBaggageManager implements BaggageManager, BaggageManagerFactory { - @Override - public BaggageManager create() { - return new FirstBaggageManager(); - } - - @Nullable - @Override - public Baggage getCurrentBaggage() { - return null; - } - - @Nullable - @Override - public Baggage.Builder baggageBuilder() { - return null; - } - - @Nullable - @Override - public Scope withBaggage(Baggage baggage) { - return null; - } - } } diff --git a/api/src/test/java/io/opentelemetry/baggage/BaggageUtilsTest.java b/api/src/test/java/io/opentelemetry/baggage/BaggageUtilsTest.java index 5d31ca0221a..58f13537667 100644 --- a/api/src/test/java/io/opentelemetry/baggage/BaggageUtilsTest.java +++ b/api/src/test/java/io/opentelemetry/baggage/BaggageUtilsTest.java @@ -16,12 +16,12 @@ class BaggageUtilsTest { @Test void testGetCurrentBaggage_Default() { Baggage baggage = BaggageUtils.getCurrentBaggage(); - assertThat(baggage).isSameAs(EmptyBaggage.getInstance()); + assertThat(baggage).isSameAs(Baggage.empty()); } @Test void testGetCurrentBaggage_SetCorrContext() { - Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build(); + Baggage baggage = Baggage.empty(); try (Scope ignored = BaggageUtils.withBaggage(baggage, Context.current()).makeCurrent()) { assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(baggage); } @@ -30,12 +30,12 @@ void testGetCurrentBaggage_SetCorrContext() { @Test void testGetBaggage_DefaultContext() { Baggage baggage = BaggageUtils.getBaggage(Context.current()); - assertThat(baggage).isSameAs(EmptyBaggage.getInstance()); + assertThat(baggage).isSameAs(Baggage.empty()); } @Test void testGetBaggage_ExplicitContext() { - Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build(); + Baggage baggage = Baggage.empty(); Context context = BaggageUtils.withBaggage(baggage, Context.current()); assertThat(BaggageUtils.getBaggage(context)).isSameAs(baggage); } @@ -48,7 +48,7 @@ void testGetBaggageWithoutDefault_DefaultContext() { @Test void testGetBaggageWithoutDefault_ExplicitContext() { - Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build(); + Baggage baggage = Baggage.empty(); Context context = BaggageUtils.withBaggage(baggage, Context.current()); assertThat(BaggageUtils.getBaggage(context)).isSameAs(baggage); } diff --git a/api/src/test/java/io/opentelemetry/baggage/DefaultBaggageManagerTest.java b/api/src/test/java/io/opentelemetry/baggage/DefaultBaggageManagerTest.java deleted file mode 100644 index 4696f4077f2..00000000000 --- a/api/src/test/java/io/opentelemetry/baggage/DefaultBaggageManagerTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.baggage; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import io.opentelemetry.context.Context; -import io.opentelemetry.context.Scope; -import java.util.Collection; -import java.util.Collections; -import org.junit.jupiter.api.Test; - -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 EntryMetadata SAMPLE_METADATA = EntryMetadata.create("sample"); - - private static final Baggage DIST_CONTEXT = - new Baggage() { - - @Override - public Collection getEntries() { - return Collections.singletonList(Entry.create(KEY, VALUE, SAMPLE_METADATA)); - } - - @Override - public String getEntryValue(String entryKey) { - return VALUE; - } - }; - - @Test - void builderMethod() { - assertThat(DEFAULT_BAGGAGE_MANAGER.baggageBuilder().build().getEntries()).isEmpty(); - } - - @Test - void getCurrentContext_DefaultContext() { - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); - } - - @Test - void getCurrentContext_ContextSetToNull() { - try (Scope ignored = BaggageUtils.withBaggage(null, Context.current()).makeCurrent()) { - Baggage baggage = DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage(); - assertThat(baggage).isNotNull(); - assertThat(baggage.getEntries()).isEmpty(); - } - } - - @Test - void withContext() { - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); - try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withBaggage(DIST_CONTEXT)) { - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT); - } - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); - } - - @Test - void withContext_nullContext() { - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); - try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withBaggage(null)) { - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); - } - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); - } - - @Test - void withContextUsingWrap() { - Runnable runnable; - try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withBaggage(DIST_CONTEXT)) { - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT); - runnable = - Context.current() - .wrap( - () -> { - assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_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_DisallowsNullContext() { - Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); - assertThrows(NullPointerException.class, () -> noopBuilder.setParent((Context) null)); - ; - } - - @Test - void noopContextBuilder_SetParent_fromContext() { - Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); - noopBuilder.setParent(Context.current()); // No error. - } - - @Test - void noopContextBuilder_Put_DisallowsNullKey() { - Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); - assertThrows(NullPointerException.class, () -> noopBuilder.put(null, VALUE, SAMPLE_METADATA)); - } - - @Test - void noopContextBuilder_Put_DisallowsNullValue() { - Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); - assertThrows(NullPointerException.class, () -> noopBuilder.put(KEY, null, SAMPLE_METADATA)); - } - - @Test - void noopContextBuilder_Put_DisallowsNullEntryMetadata() { - Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); - assertThrows(NullPointerException.class, () -> noopBuilder.put(KEY, VALUE, null)); - } - - @Test - void noopContextBuilder_Remove_DisallowsNullKey() { - Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder(); - assertThrows(NullPointerException.class, () -> noopBuilder.remove(null)); - } -} diff --git a/api/src/test/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagatorTest.java b/api/src/test/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagatorTest.java index a16af75de03..6cc0445129a 100644 --- a/api/src/test/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagatorTest.java +++ b/api/src/test/java/io/opentelemetry/baggage/propagation/W3CBaggagePropagatorTest.java @@ -5,34 +5,20 @@ package io.opentelemetry.baggage.propagation; -import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import io.opentelemetry.baggage.Baggage; -import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.baggage.BaggageUtils; -import io.opentelemetry.baggage.EmptyBaggage; -import io.opentelemetry.baggage.Entry; import io.opentelemetry.baggage.EntryMetadata; import io.opentelemetry.context.Context; -import java.util.Collection; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; -import java.util.Objects; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -@ExtendWith(MockitoExtension.class) class W3CBaggagePropagatorTest { - @Mock private BaggageManager baggageManager; - @Test void fields() { assertThat(W3CBaggagePropagator.getInstance().fields()).containsExactly("baggage"); @@ -40,7 +26,7 @@ void fields() { @Test void extract_noBaggageHeader() { - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract(Context.root(), ImmutableMap.of(), Map::get); @@ -50,33 +36,29 @@ void extract_noBaggageHeader() { @Test void extract_emptyBaggageHeader() { - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", ""), ImmutableMap::get); - assertThat(BaggageUtils.getBaggage(result)).isEqualTo(EmptyBaggage.getInstance()); + assertThat(BaggageUtils.getBaggage(result)).isEqualTo(Baggage.empty()); } @Test void extract_singleEntry() { - when(baggageManager.baggageBuilder()).thenReturn(new TestBaggageBuilder()); - - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract( Context.root(), ImmutableMap.of("baggage", "key=value"), ImmutableMap::get); - Baggage expectedBaggage = new TestBaggage(ImmutableMap.of("key", Entry.create("key", "value"))); + Baggage expectedBaggage = Baggage.builder().put("key", "value").build(); assertThat(BaggageUtils.getBaggage(result)).isEqualTo(expectedBaggage); } @Test void extract_multiEntry() { - when(baggageManager.baggageBuilder()).thenReturn(new TestBaggageBuilder()); - - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract( @@ -84,33 +66,25 @@ void extract_multiEntry() { ImmutableMap.of("baggage", "key1=value1,key2=value2"), ImmutableMap::get); - Baggage expectedBaggage = - new TestBaggage( - ImmutableMap.of( - "key1", Entry.create("key1", "value1"), "key2", Entry.create("key2", "value2"))); + Baggage expectedBaggage = Baggage.builder().put("key1", "value1").put("key2", "value2").build(); assertThat(BaggageUtils.getBaggage(result)).isEqualTo(expectedBaggage); } @Test void extract_duplicateKeys() { - when(baggageManager.baggageBuilder()).thenReturn(new TestBaggageBuilder()); - - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract( Context.root(), ImmutableMap.of("baggage", "key=value1,key=value2"), ImmutableMap::get); - Baggage expectedBaggage = - new TestBaggage(ImmutableMap.of("key", Entry.create("key", "value2"))); + Baggage expectedBaggage = Baggage.builder().put("key", "value2").build(); assertThat(BaggageUtils.getBaggage(result)).isEqualTo(expectedBaggage); } @Test void extract_withMetadata() { - when(baggageManager.baggageBuilder()).thenReturn(new TestBaggageBuilder()); - - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract( @@ -119,19 +93,15 @@ void extract_withMetadata() { ImmutableMap::get); Baggage expectedBaggage = - new TestBaggage( - ImmutableMap.of( - "key", - Entry.create( - "key", "value", EntryMetadata.create("metadata-key=value;othermetadata")))); + Baggage.builder() + .put("key", "value", EntryMetadata.create("metadata-key=value;othermetadata")) + .build(); assertThat(BaggageUtils.getBaggage(result)).isEqualTo(expectedBaggage); } @Test void extract_fullComplexities() { - when(baggageManager.baggageBuilder()).thenReturn(new TestBaggageBuilder()); - - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract( @@ -143,15 +113,11 @@ void extract_fullComplexities() { ImmutableMap::get); Baggage expectedBaggage = - new TestBaggage( - ImmutableMap.of( - "key1", - Entry.create( - "key1", "value1", EntryMetadata.create("metadata-key = value; othermetadata")), - "key2", - Entry.create("key2", "value2", EntryMetadata.EMPTY), - "key3", - Entry.create("key3", "value3"))); + Baggage.builder() + .put("key1", "value1", EntryMetadata.create("metadata-key = value; othermetadata")) + .put("key2", "value2", EntryMetadata.EMPTY) + .put("key3", "value3") + .build(); assertThat(BaggageUtils.getBaggage(result)).isEqualTo(expectedBaggage); } @@ -161,9 +127,7 @@ void extract_fullComplexities() { */ @Test void extract_invalidHeader() { - when(baggageManager.baggageBuilder()).thenReturn(new TestBaggageBuilder()); - - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Context result = propagator.extract( @@ -174,12 +138,12 @@ void extract_invalidHeader() { + "value; othermetadata, key2 =value2 , key3 =\tvalue3 ; "), ImmutableMap::get); - assertThat(BaggageUtils.getBaggage(result)).isEqualTo(EmptyBaggage.getInstance()); + assertThat(BaggageUtils.getBaggage(result)).isEqualTo(Baggage.empty()); } @Test void inject_noBaggage() { - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Map carrier = new HashMap<>(); propagator.inject(Context.root(), carrier, Map::put); assertThat(carrier).isEmpty(); @@ -187,8 +151,8 @@ void inject_noBaggage() { @Test void inject_emptyBaggage() { - Baggage baggage = new TestBaggage(emptyMap()); - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + Baggage baggage = Baggage.empty(); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Map carrier = new HashMap<>(); propagator.inject(BaggageUtils.withBaggage(baggage, Context.root()), carrier, Map::put); assertThat(carrier).isEmpty(); @@ -196,13 +160,12 @@ void inject_emptyBaggage() { @Test void inject() { - LinkedHashMap data = new LinkedHashMap<>(); - data.put("nometa", Entry.create("nometa", "nometa-value")); - data.put( - "meta", - Entry.create("meta", "meta-value", EntryMetadata.create("somemetadata; someother=foo"))); - Baggage baggage = new TestBaggage(data); - W3CBaggagePropagator propagator = new W3CBaggagePropagator(baggageManager); + Baggage baggage = + Baggage.builder() + .put("nometa", "nometa-value") + .put("meta", "meta-value", EntryMetadata.create("somemetadata; someother=foo")) + .build(); + W3CBaggagePropagator propagator = new W3CBaggagePropagator(); Map carrier = new HashMap<>(); propagator.inject(BaggageUtils.withBaggage(baggage, Context.root()), carrier, Map::put); assertThat(carrier) @@ -210,80 +173,4 @@ void inject() { singletonMap( "baggage", "nometa=nometa-value,meta=meta-value;somemetadata; someother=foo")); } - - private static class TestBaggageBuilder implements Baggage.Builder { - - private final Map values = new HashMap<>(); - - @Override - public Baggage.Builder setParent(Context context) { - return this; - } - - @Override - public Baggage.Builder setNoParent() { - return this; - } - - @Override - public Baggage.Builder put(String key, String value, EntryMetadata entryMetadata) { - values.put(key, Entry.create(key, value, entryMetadata)); - return this; - } - - @Override - public Baggage.Builder remove(String key) { - values.remove(key); - return this; - } - - @Override - public Baggage build() { - return new TestBaggage(values); - } - } - - private static class TestBaggage implements Baggage { - - private final Map values; - - public TestBaggage(Map values) { - this.values = values; - } - - @Override - public Collection getEntries() { - return values.values(); - } - - @Override - public String getEntryValue(String entryKey) { - Entry entry = values.get(entryKey); - return entry == null ? null : entry.getValue(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof TestBaggage)) { - return false; - } - - TestBaggage that = (TestBaggage) o; - - return Objects.equals(values, that.values); - } - - @Override - public int hashCode() { - return values != null ? values.hashCode() : 0; - } - - @Override - public String toString() { - return "TestBaggage{" + "values=" + values + '}'; - } - } } 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 632e94b35da..cdf621837fb 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/BaseShimObject.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/BaseShimObject.java @@ -5,11 +5,11 @@ package io.opentelemetry.opentracingshim; -import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.trace.Tracer; abstract class BaseShimObject { + final TelemetryInfo telemetryInfo; BaseShimObject(TelemetryInfo telemetryInfo) { @@ -24,10 +24,6 @@ Tracer tracer() { return telemetryInfo.tracer(); } - BaggageManager contextManager() { - return telemetryInfo.contextManager(); - } - SpanContextShimTable spanContextTable() { return telemetryInfo.spanContextTable(); } 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 1c4191a6460..c936735c793 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShim.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/SpanContextShim.java @@ -40,7 +40,7 @@ public SpanContextShim( SpanContextShim newWithKeyValue(String key, String value) { Context parentContext = BaggageUtils.withBaggage(baggage, Context.current()); - Baggage.Builder builder = contextManager().baggageBuilder().setParent(parentContext); + Baggage.Builder builder = Baggage.builder().setParent(parentContext); builder.put(key, value, EntryMetadata.EMPTY); return new SpanContextShim(telemetryInfo(), context, builder.build()); 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 33700798b4c..2a665dc578f 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TelemetryInfo.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TelemetryInfo.java @@ -6,7 +6,6 @@ package io.opentelemetry.opentracingshim; import io.opentelemetry.baggage.Baggage; -import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.trace.Tracer; @@ -15,17 +14,16 @@ * the OT Shim layer. */ final class TelemetryInfo { + private final Tracer tracer; - private final BaggageManager contextManager; private final Baggage emptyBaggage; private final ContextPropagators propagators; private final SpanContextShimTable spanContextTable; - TelemetryInfo(Tracer tracer, BaggageManager contextManager, ContextPropagators propagators) { + TelemetryInfo(Tracer tracer, ContextPropagators propagators) { this.tracer = tracer; - this.contextManager = contextManager; this.propagators = propagators; - this.emptyBaggage = contextManager.baggageBuilder().build(); + this.emptyBaggage = Baggage.empty(); this.spanContextTable = new SpanContextShimTable(); } @@ -33,10 +31,6 @@ Tracer tracer() { return tracer; } - BaggageManager contextManager() { - return contextManager; - } - SpanContextShimTable spanContextTable() { return spanContextTable; } 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 b2be02a4cd2..605c4c8568b 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TraceShim.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TraceShim.java @@ -6,7 +6,6 @@ package io.opentelemetry.opentracingshim; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.baggage.BaggageManager; import io.opentelemetry.trace.Tracer; import io.opentelemetry.trace.TracerProvider; import java.util.Objects; @@ -23,9 +22,7 @@ private TraceShim() {} public static io.opentracing.Tracer createTracerShim() { return new TracerShim( new TelemetryInfo( - getTracer(OpenTelemetry.getTracerProvider()), - OpenTelemetry.getBaggageManager(), - OpenTelemetry.getPropagators())); + getTracer(OpenTelemetry.getTracerProvider()), OpenTelemetry.getPropagators())); } /** @@ -33,15 +30,12 @@ public static io.opentracing.Tracer createTracerShim() { * BaggageManager}. * * @param tracerProvider the {@code TracerProvider} used by this shim. - * @param contextManager the {@code BaggageManager} used by this shim. * @return a {@code io.opentracing.Tracer}. */ - public static io.opentracing.Tracer createTracerShim( - TracerProvider tracerProvider, BaggageManager contextManager) { + public static io.opentracing.Tracer createTracerShim(TracerProvider tracerProvider) { return new TracerShim( new TelemetryInfo( getTracer(Objects.requireNonNull(tracerProvider, "tracerProvider")), - Objects.requireNonNull(contextManager, "contextManager"), OpenTelemetry.getPropagators())); } 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 400a4117de6..80aa407d5a5 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java @@ -10,16 +10,16 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.trace.Tracer; import org.junit.jupiter.api.Test; class SpanBuilderShimTest { + private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build(); private final Tracer tracer = tracerSdkFactory.get("SpanShimTest"); private final TelemetryInfo telemetryInfo = - new TelemetryInfo(tracer, new BaggageManagerSdk(), OpenTelemetry.getPropagators()); + new TelemetryInfo(tracer, 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 b96804d55bf..fbab97e93cf 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java @@ -13,7 +13,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.trace.Span; import io.opentelemetry.trace.Tracer; @@ -23,10 +22,11 @@ import org.junit.jupiter.api.Test; class SpanShimTest { + private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build(); private final Tracer tracer = tracerSdkFactory.get("SpanShimTest"); private final TelemetryInfo telemetryInfo = - new TelemetryInfo(tracer, new BaggageManagerSdk(), OpenTelemetry.getPropagators()); + new TelemetryInfo(tracer, 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 2be4e2538a3..be6a545cf4f 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TraceShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TraceShimTest.java @@ -5,13 +5,10 @@ package io.opentelemetry.opentracingshim; -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.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import org.junit.jupiter.api.Test; @@ -21,31 +18,18 @@ class TraceShimTest { void createTracerShim_default() { TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim(); assertEquals(OpenTelemetry.getTracer("opentracingshim"), tracerShim.tracer()); - assertEquals(OpenTelemetry.getBaggageManager(), tracerShim.contextManager()); } @Test void createTracerShim_nullTracer() { assertThrows( - NullPointerException.class, - () -> TraceShim.createTracerShim(null, getBaggageManager()), - "tracerProvider"); - } - - @Test - void createTracerShim_nullContextManager() { - assertThrows( - NullPointerException.class, - () -> TraceShim.createTracerShim(getTracerProvider(), null), - "contextManager"); + NullPointerException.class, () -> TraceShim.createTracerShim(null), "tracerProvider"); } @Test void createTracerShim() { TracerSdkProvider sdk = TracerSdkProvider.builder().build(); - BaggageManagerSdk contextManager = new BaggageManagerSdk(); - TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim(sdk, contextManager); + TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim(sdk); 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 69ac3bb0096..dc68ff4c350 100644 --- a/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java +++ b/opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; class TracerShimTest { + TracerShim tracerShim; @BeforeEach @@ -30,9 +31,7 @@ void setUp() { tracerShim = new TracerShim( new TelemetryInfo( - OpenTelemetry.getTracer("opentracingshim"), - OpenTelemetry.getBaggageManager(), - OpenTelemetry.getPropagators())); + OpenTelemetry.getTracer("opentracingshim"), OpenTelemetry.getPropagators())); } @Test 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 c409eb659a8..ec33dee139b 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 @@ -10,7 +10,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.baggage.DefaultBaggageManager; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; import io.opentelemetry.sdk.OpenTelemetrySdk; @@ -29,9 +28,7 @@ class OpenTelemetryInteroperabilityTest { InMemoryTracing.builder() .setTracerSdkManagement(OpenTelemetrySdk.getTracerManagement()) .build(); - private final Tracer otTracer = - TraceShim.createTracerShim( - OpenTelemetry.getTracerProvider(), DefaultBaggageManager.getInstance()); + private final Tracer otTracer = TraceShim.createTracerShim(OpenTelemetry.getTracerProvider()); @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 ac31bdb6fa1..5c876dea055 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 @@ -16,7 +16,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.SpanId; @@ -35,7 +34,7 @@ class ActiveSpanReplacementTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 7845a654c8f..ba3ed4c314e 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 @@ -11,7 +11,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -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; @@ -40,7 +39,7 @@ class ActorPropagationTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 ca67dd0df97..97f9f4f447f 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 @@ -9,7 +9,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentracing.Span; import io.opentracing.Tracer; @@ -23,7 +22,7 @@ public final class BaggageHandlingTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 31fc2692e3d..e558e7cf5ec 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 @@ -14,7 +14,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -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; @@ -31,7 +30,7 @@ class TestClientServerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 b217a9f7951..cca40bcaed5 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 @@ -15,7 +15,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -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; @@ -39,7 +38,7 @@ class HandlerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 4952229848d..8ab0fc950f6 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 @@ -13,7 +13,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -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; @@ -37,7 +36,7 @@ public final class ErrorReportingTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 fdf5bb49783..7249649d5e3 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 @@ -13,7 +13,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Scope; @@ -30,7 +29,7 @@ public final class LateSpanFinishTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 1b91467b256..7a484351abe 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 @@ -10,7 +10,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.Span; @@ -23,7 +22,7 @@ class ListenerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); @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 e9c67b46b76..07477b4aaf9 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 @@ -13,7 +13,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Scope; @@ -35,7 +34,7 @@ class MultipleCallbacksTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); @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 6d3b62d014a..f1582f38e89 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 @@ -15,7 +15,6 @@ import io.opentelemetry.common.ReadableAttributes; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Scope; @@ -33,7 +32,7 @@ public final class NestedCallbacksTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 39767a2991b..1d10cce7ddc 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 @@ -12,7 +12,6 @@ import io.opentelemetry.common.AttributeKey; import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -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 +38,7 @@ class PromisePropagationTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 ba07ce36bf4..0e87056c433 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 @@ -9,7 +9,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentracing.Tracer; @@ -28,7 +27,7 @@ public final class HandlerTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); 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 2750410099a..4650471118a 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 @@ -9,7 +9,6 @@ import io.opentelemetry.exporters.inmemory.InMemoryTracing; import io.opentelemetry.opentracingshim.TraceShim; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.trace.TracerSdkProvider; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.trace.SpanId; @@ -28,7 +27,7 @@ class SuspendResumePropagationTest { private final TracerSdkProvider sdk = TracerSdkProvider.builder().build(); private final InMemoryTracing inMemoryTracing = InMemoryTracing.builder().setTracerSdkManagement(sdk).build(); - private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk()); + private final Tracer tracer = TraceShim.createTracerShim(sdk); @BeforeEach void before() {} 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 36cf0dce267..03817fe70c5 100644 --- a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java +++ b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java @@ -7,7 +7,6 @@ import io.opentelemetry.OpenTelemetry; import io.opentelemetry.internal.Obfuscated; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; import io.opentelemetry.sdk.metrics.MeterSdkProvider; import io.opentelemetry.sdk.trace.TracerSdkManagement; import javax.annotation.concurrent.ThreadSafe; @@ -41,14 +40,5 @@ public static MeterSdkProvider getMeterProvider() { return (MeterSdkProvider) OpenTelemetry.getMeterProvider(); } - /** - * Returns a {@link BaggageManagerSdk}. - * - * @return context manager returned by {@link OpenTelemetry#getBaggageManager()}. - */ - 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 8e513e38d00..1efcc32e310 100644 --- a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java +++ b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java @@ -17,7 +17,6 @@ class OpenTelemetrySdkTest { void testDefault() { assertThat(((TracerSdkProvider) OpenTelemetrySdk.getTracerManagement()).get("")) .isSameAs(OpenTelemetry.getTracerProvider().get("")); - assertThat(OpenTelemetrySdk.getBaggageManager()).isSameAs(OpenTelemetry.getBaggageManager()); assertThat(OpenTelemetrySdk.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider()); } 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 deleted file mode 100644 index 9be525dd83a..00000000000 --- a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/BaggageManagerSdk.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -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 withBaggage(Baggage baggage) { - return BaggageUtils.currentContextWith(baggage); - } -} diff --git a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/package-info.java b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/package-info.java deleted file mode 100644 index c4ac55914d9..00000000000 --- a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/package-info.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * The SDK implementation of baggage. - * - * @see io.opentelemetry.sdk.baggage.BaggageManagerSdk - */ -@ParametersAreNonnullByDefault -package io.opentelemetry.sdk.baggage; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdk.java b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdk.java deleted file mode 100644 index 7461e9a3faa..00000000000 --- a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdk.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.baggage.spi; - -import io.opentelemetry.baggage.BaggageManager; -import io.opentelemetry.baggage.spi.BaggageManagerFactory; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; - -/** - * {@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 BaggageManagerFactorySdk implements BaggageManagerFactory { - - @Override - public BaggageManager create() { - return new BaggageManagerSdk(); - } -} diff --git a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/package-info.java b/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/package-info.java deleted file mode 100644 index 6eb1f1dd348..00000000000 --- a/sdk/baggage/src/main/java/io/opentelemetry/sdk/baggage/spi/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -/** The SPI implementation which provides the SDK implementation of baggage. */ -@ParametersAreNonnullByDefault -package io.opentelemetry.sdk.baggage.spi; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageManagerSdkTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageManagerSdkTest.java index 9da3e1b0995..e837edcf23c 100644 --- a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageManagerSdkTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageManagerSdkTest.java @@ -9,7 +9,6 @@ import io.opentelemetry.baggage.Baggage; import io.opentelemetry.baggage.BaggageUtils; -import io.opentelemetry.baggage.EmptyBaggage; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; import org.junit.jupiter.api.BeforeEach; @@ -17,13 +16,10 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -/** Unit tests for {@link BaggageManagerSdk}. */ -// Need to suppress warnings for MustBeClosed because Android 14 does not support -// try-with-resources. -@SuppressWarnings("MustBeClosedChecker") +/** Unit tests for {@link Baggage} and {@link BaggageUtils}. TODO: move these where appropriate */ class BaggageManagerSdkTest { + @Mock private Baggage baggage; - private final BaggageManagerSdk contextManager = new BaggageManagerSdk(); @BeforeEach void setUp() { @@ -32,13 +28,13 @@ void setUp() { @Test void testGetCurrentContext_DefaultContext() { - assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(Baggage.empty()); } @Test void testGetCurrentContext_ContextSetToNull() { try (Scope ignored = BaggageUtils.withBaggage(null, Context.current()).makeCurrent()) { - Baggage baggage = contextManager.getCurrentBaggage(); + Baggage baggage = BaggageUtils.getCurrentBaggage(); assertThat(baggage).isNotNull(); assertThat(baggage.getEntries()).isEmpty(); } @@ -46,26 +42,26 @@ void testGetCurrentContext_ContextSetToNull() { @Test void testWithBaggage() { - assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); - try (Scope wtm = contextManager.withBaggage(baggage)) { - assertThat(contextManager.getCurrentBaggage()).isSameAs(baggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(Baggage.empty()); + try (Scope wtm = BaggageUtils.currentContextWith(baggage)) { + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(baggage); } - assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(Baggage.empty()); } @Test void testWithBaggageUsingWrap() { Runnable runnable; - try (Scope wtm = contextManager.withBaggage(baggage)) { - assertThat(contextManager.getCurrentBaggage()).isSameAs(baggage); + try (Scope wtm = BaggageUtils.currentContextWith(baggage)) { + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(baggage); runnable = Context.current() .wrap( () -> { - assertThat(contextManager.getCurrentBaggage()).isSameAs(baggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(baggage); }); } - assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance()); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(Baggage.empty()); // When we run the runnable we will have the Baggage in the current Context. runnable.run(); } diff --git a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageTestUtil.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageTestUtil.java index a2dde0e0a6e..9af16b0ac28 100644 --- a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageTestUtil.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageTestUtil.java @@ -5,18 +5,19 @@ package io.opentelemetry.sdk.baggage; +import io.opentelemetry.baggage.Baggage; import io.opentelemetry.baggage.Entry; import java.util.Arrays; import java.util.List; class BaggageTestUtil { - static BaggageSdk listToBaggage(Entry... entries) { + static Baggage listToBaggage(Entry... entries) { return listToBaggage(Arrays.asList(entries)); } - static BaggageSdk listToBaggage(List entries) { - BaggageSdk.Builder builder = new BaggageSdk.Builder(); + static Baggage listToBaggage(List entries) { + Baggage.Builder builder = Baggage.builder(); for (Entry entry : entries) { builder.put(entry.getKey(), entry.getValue(), entry.getEntryMetadata()); } diff --git a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageSdkTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ImmutableBaggageTest.java similarity index 61% rename from sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageSdkTest.java rename to sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ImmutableBaggageTest.java index bbe1fe571f7..c43b94259ce 100644 --- a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/BaggageSdkTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ImmutableBaggageTest.java @@ -11,7 +11,6 @@ import com.google.common.testing.EqualsTester; 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; @@ -20,13 +19,11 @@ import org.junit.jupiter.api.Test; /** - * Tests for {@link BaggageSdk} and {@link BaggageSdk.Builder}. + * Tests for {@link Baggage} and {@link Baggage.Builder}. * - *

Tests for scope management with {@link BaggageManagerSdk} are in {@link ScopedBaggageTest}. + *

Tests for scope management with {@link Baggage} are in {@link ScopedBaggageTest}. */ -class BaggageSdkTest { - - private final BaggageManager contextManager = new BaggageManagerSdk(); +class ImmutableBaggageTest { private static final EntryMetadata TMD = EntryMetadata.create("tmd"); @@ -41,13 +38,13 @@ class BaggageSdkTest { @Test void getEntries_empty() { - BaggageSdk baggage = new BaggageSdk.Builder().build(); + Baggage baggage = Baggage.empty(); assertThat(baggage.getEntries()).isEmpty(); } @Test void getEntries_nonEmpty() { - BaggageSdk baggage = listToBaggage(T1, T2); + Baggage baggage = listToBaggage(T1, T2); assertThat(baggage.getEntries()).containsExactly(T1, T2); } @@ -57,8 +54,7 @@ void getEntries_chain() { Baggage parent = listToBaggage(T1, T2); Context parentContext = BaggageUtils.withBaggage(parent, Context.root()); Baggage baggage = - contextManager - .baggageBuilder() + Baggage.builder() .setParent(parentContext) .put(t1alt.getKey(), t1alt.getValue(), t1alt.getEntryMetadata()) .build(); @@ -69,27 +65,15 @@ void getEntries_chain() { void put_newKey() { Baggage parent = listToBaggage(T1); Context parentContext = BaggageUtils.withBaggage(parent, Context.root()); - assertThat( - contextManager - .baggageBuilder() - .setParent(parentContext) - .put(K2, V2, TMD) - .build() - .getEntries()) + assertThat(Baggage.builder().setParent(parentContext).put(K2, V2, TMD).build().getEntries()) .containsExactly(T1, T2); } @Test void put_existingKey() { - BaggageSdk parent = listToBaggage(T1); + Baggage parent = listToBaggage(T1); Context parentContext = BaggageUtils.withBaggage(parent, Context.root()); - assertThat( - contextManager - .baggageBuilder() - .setParent(parentContext) - .put(K1, V2, TMD) - .build() - .getEntries()) + assertThat(Baggage.builder().setParent(parentContext).put(K1, V2, TMD).build().getEntries()) .containsExactly(Entry.create(K1, V2, TMD)); } @@ -97,54 +81,51 @@ void put_existingKey() { void put_nullKey() { Baggage parent = listToBaggage(T1); Context parentContext = BaggageUtils.withBaggage(parent, Context.root()); - Baggage.Builder builder = contextManager.baggageBuilder().setParent(parentContext); + Baggage.Builder builder = Baggage.builder().setParent(parentContext); assertThrows(NullPointerException.class, () -> builder.put(null, V2, TMD), "key"); } @Test void put_nullValue() { - BaggageSdk parent = listToBaggage(T1); + Baggage parent = listToBaggage(T1); Context parentContext = BaggageUtils.withBaggage(parent, Context.root()); - Baggage.Builder builder = contextManager.baggageBuilder().setParent(parentContext); + Baggage.Builder builder = Baggage.builder().setParent(parentContext); assertThrows(NullPointerException.class, () -> builder.put(K2, null, TMD), "value"); } @Test void setParent_nullContext() { - assertThrows( - NullPointerException.class, - () -> contextManager.baggageBuilder().setParent((Context) null)); + assertThrows(NullPointerException.class, () -> Baggage.builder().setParent((Context) null)); } @Test void setParent_fromContext() { Context context = BaggageUtils.withBaggage(listToBaggage(T2), Context.current()); - Baggage baggage = contextManager.baggageBuilder().setParent(context).build(); + Baggage baggage = Baggage.builder().setParent(context).build(); assertThat(baggage.getEntries()).containsExactly(T2); } @Test void setParent_fromEmptyContext() { Context emptyContext = Context.current(); - BaggageSdk parent = listToBaggage(T1); + Baggage parent = listToBaggage(T1); try (Scope scope = BaggageUtils.currentContextWith(parent)) { - Baggage baggage = contextManager.baggageBuilder().setParent(emptyContext).build(); + Baggage baggage = Baggage.builder().setParent(emptyContext).build(); assertThat(baggage.getEntries()).isEmpty(); } } @Test void setParent_setNoParent() { - BaggageSdk parent = listToBaggage(T1); + Baggage parent = listToBaggage(T1); Context parentContext = BaggageUtils.withBaggage(parent, Context.root()); - Baggage baggage = - contextManager.baggageBuilder().setParent(parentContext).setNoParent().build(); + Baggage baggage = Baggage.builder().setParent(parentContext).setNoParent().build(); assertThat(baggage.getEntries()).isEmpty(); } @Test void remove_existingKey() { - BaggageSdk.Builder builder = new BaggageSdk.Builder(); + Baggage.Builder builder = Baggage.builder(); builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata()); builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata()); @@ -153,7 +134,7 @@ void remove_existingKey() { @Test void remove_differentKey() { - BaggageSdk.Builder builder = new BaggageSdk.Builder(); + Baggage.Builder builder = Baggage.builder(); builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata()); builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata()); @@ -162,21 +143,15 @@ void remove_differentKey() { @Test void remove_keyFromParent() { - BaggageSdk parent = listToBaggage(T1, T2); + Baggage parent = listToBaggage(T1, T2); Context parentContext = BaggageUtils.withBaggage(parent, Context.root()); - assertThat( - contextManager - .baggageBuilder() - .setParent(parentContext) - .remove(K1) - .build() - .getEntries()) + assertThat(Baggage.builder().setParent(parentContext).remove(K1).build().getEntries()) .containsExactly(T2); } @Test void remove_nullKey() { - Baggage.Builder builder = contextManager.baggageBuilder(); + Baggage.Builder builder = Baggage.builder(); assertThrows(NullPointerException.class, () -> builder.remove(null), "key"); } @@ -184,11 +159,11 @@ void remove_nullKey() { void testEquals() { new EqualsTester() .addEqualityGroup( - 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()) + Baggage.builder().put(K1, V1, TMD).put(K2, V2, TMD).build(), + Baggage.builder().put(K1, V1, TMD).put(K2, V2, TMD).build(), + Baggage.builder().put(K2, V2, TMD).put(K1, V1, TMD).build()) + .addEqualityGroup(Baggage.builder().put(K1, V1, TMD).put(K2, V1, TMD).build()) + .addEqualityGroup(Baggage.builder().put(K1, V2, TMD).put(K2, V1, TMD).build()) .testEquals(); } } diff --git a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java index 33ddfab356f..e2430cfdaae 100644 --- a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java @@ -8,16 +8,16 @@ 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.BaggageUtils; import io.opentelemetry.baggage.Entry; import io.opentelemetry.baggage.EntryMetadata; +import io.opentelemetry.baggage.ImmutableBaggage; import io.opentelemetry.context.Scope; import org.junit.jupiter.api.Test; /** - * Unit tests for the methods in {@link BaggageManagerSdk} and {@link BaggageSdk.Builder} that - * interact with the current {@link BaggageSdk}. + * Unit tests for the methods in {@link BaggageUtils} and {@link ImmutableBaggage} that interact + * with the current {@link Baggage}. */ class ScopedBaggageTest { @@ -34,120 +34,109 @@ class ScopedBaggageTest { EntryMetadata.create("unlimited"); private static final EntryMetadata METADATA_NO_PROPAGATION = EntryMetadata.create("noprop"); - private final BaggageManager contextManager = new BaggageManagerSdk(); - @Test void emptyBaggage() { - Baggage defaultBaggage = contextManager.getCurrentBaggage(); + Baggage defaultBaggage = BaggageUtils.getCurrentBaggage(); assertThat(defaultBaggage.getEntries()).isEmpty(); - assertThat(defaultBaggage).isInstanceOf(EmptyBaggage.class); + assertThat(defaultBaggage).isInstanceOf(ImmutableBaggage.class); } @Test void withContext() { - assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + assertThat(BaggageUtils.getCurrentBaggage().getEntries()).isEmpty(); Baggage scopedEntries = - contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); - try (Scope scope = contextManager.withBaggage(scopedEntries)) { - assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedEntries); + Baggage.builder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + try (Scope scope = BaggageUtils.currentContextWith(scopedEntries)) { + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(scopedEntries); } - assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + assertThat(BaggageUtils.getCurrentBaggage().getEntries()).isEmpty(); } @Test void createBuilderFromCurrentEntries() { Baggage scopedBaggage = - contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); - try (Scope scope = contextManager.withBaggage(scopedBaggage)) { + Baggage.builder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + try (Scope scope = BaggageUtils.currentContextWith(scopedBaggage)) { Baggage newEntries = - contextManager - .baggageBuilder() - .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) - .build(); + Baggage.builder().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.getCurrentBaggage()).isSameAs(scopedBaggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(scopedBaggage); } } @Test void setCurrentEntriesWithBuilder() { - assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + assertThat(BaggageUtils.getCurrentBaggage().getEntries()).isEmpty(); Baggage scopedBaggage = - contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); - try (Scope scope = contextManager.withBaggage(scopedBaggage)) { - assertThat(contextManager.getCurrentBaggage().getEntries()) + Baggage.builder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + try (Scope scope = BaggageUtils.currentContextWith(scopedBaggage)) { + assertThat(BaggageUtils.getCurrentBaggage().getEntries()) .containsExactly(Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION)); - assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedBaggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(scopedBaggage); } - assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + assertThat(BaggageUtils.getCurrentBaggage().getEntries()).isEmpty(); } @Test void addToCurrentEntriesWithBuilder() { Baggage scopedBaggage = - contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); - try (Scope scope1 = contextManager.withBaggage(scopedBaggage)) { + Baggage.builder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + try (Scope scope1 = BaggageUtils.currentContextWith(scopedBaggage)) { Baggage innerBaggage = - contextManager - .baggageBuilder() - .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) - .build(); - try (Scope scope2 = contextManager.withBaggage(innerBaggage)) { - assertThat(contextManager.getCurrentBaggage().getEntries()) + Baggage.builder().put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION).build(); + try (Scope scope2 = BaggageUtils.currentContextWith(innerBaggage)) { + assertThat(BaggageUtils.getCurrentBaggage().getEntries()) .containsExactlyInAnyOrder( Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION), Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)); - assertThat(contextManager.getCurrentBaggage()).isSameAs(innerBaggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(innerBaggage); } - assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedBaggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(scopedBaggage); } } @Test void multiScopeBaggageWithMetadata() { Baggage scopedBaggage = - contextManager - .baggageBuilder() + Baggage.builder() .put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION) .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) .build(); - try (Scope scope1 = contextManager.withBaggage(scopedBaggage)) { + try (Scope scope1 = BaggageUtils.currentContextWith(scopedBaggage)) { Baggage innerBaggage = - contextManager - .baggageBuilder() + Baggage.builder() .put(KEY_3, VALUE_3, METADATA_NO_PROPAGATION) .put(KEY_2, VALUE_4, METADATA_NO_PROPAGATION) .build(); - try (Scope scope2 = contextManager.withBaggage(innerBaggage)) { - assertThat(contextManager.getCurrentBaggage().getEntries()) + try (Scope scope2 = BaggageUtils.currentContextWith(innerBaggage)) { + assertThat(BaggageUtils.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.getCurrentBaggage()).isSameAs(innerBaggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(innerBaggage); } - assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedBaggage); + assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(scopedBaggage); } } @Test void setNoParent_doesNotInheritContext() { - assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + assertThat(BaggageUtils.getCurrentBaggage().getEntries()).isEmpty(); Baggage scopedBaggage = - contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); - try (Scope scope = contextManager.withBaggage(scopedBaggage)) { + Baggage.builder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build(); + try (Scope scope = BaggageUtils.currentContextWith(scopedBaggage)) { Baggage innerBaggage = - contextManager - .baggageBuilder() + Baggage.builder() .setNoParent() .put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION) .build(); assertThat(innerBaggage.getEntries()) .containsExactly(Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)); } - assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty(); + assertThat(BaggageUtils.getCurrentBaggage().getEntries()).isEmpty(); } } diff --git a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdkTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdkTest.java deleted file mode 100644 index 958d7c78c4a..00000000000 --- a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/spi/BaggageManagerFactorySdkTest.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.baggage.spi; - -import static org.assertj.core.api.Assertions.assertThat; - -import io.opentelemetry.OpenTelemetry; -import io.opentelemetry.sdk.baggage.BaggageManagerSdk; -import org.junit.jupiter.api.Test; - -class BaggageManagerFactorySdkTest { - - @Test - void testDefault() { - assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(BaggageManagerSdk.class); - } -} From e2254ea150663ce6a8103504285f55b46d3fa249 Mon Sep 17 00:00:00 2001 From: jkwatson Date: Fri, 16 Oct 2020 16:36:35 -0700 Subject: [PATCH 2/4] javadoc cleanup --- .../src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 03817fe70c5..74c95b6b31c 100644 --- a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java +++ b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java @@ -13,7 +13,7 @@ /** * This class provides a static global accessor for SDK telemetry objects {@link - * TracerSdkManagement}, {@link MeterSdkProvider} and {@link BaggageManagerSdk}. + * TracerSdkManagement}, {@link MeterSdkProvider}. * *

This is a convenience class getting and casting the telemetry objects from {@link * OpenTelemetry}. @@ -22,6 +22,7 @@ */ @ThreadSafe public final class OpenTelemetrySdk { + /** * Returns a {@link TracerSdkManagement}. * From fd8fe967491b85fece84cd03fbf31d86326ffc1b Mon Sep 17 00:00:00 2001 From: jkwatson Date: Fri, 16 Oct 2020 16:40:29 -0700 Subject: [PATCH 3/4] more javadoc cleanup --- api/src/main/java/io/opentelemetry/baggage/Baggage.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/main/java/io/opentelemetry/baggage/Baggage.java b/api/src/main/java/io/opentelemetry/baggage/Baggage.java index f6c05347443..8b8489819cf 100644 --- a/api/src/main/java/io/opentelemetry/baggage/Baggage.java +++ b/api/src/main/java/io/opentelemetry/baggage/Baggage.java @@ -20,10 +20,12 @@ @Immutable public interface Baggage { + /** Baggage with no entries. */ static Baggage empty() { return ImmutableBaggage.EMPTY; } + /** Creates a new {@link Builder} for creating Baggage. */ static Builder builder() { return ImmutableBaggage.builder(); } From b50ce5c5f9939e3962f8b76ddc77cc6d33458acc Mon Sep 17 00:00:00 2001 From: jkwatson Date: Tue, 20 Oct 2020 20:58:46 -0700 Subject: [PATCH 4/4] make the ImmutableBaggage package access --- .../java/io/opentelemetry/baggage/ImmutableBaggage.java | 2 +- .../io/opentelemetry/sdk/baggage/ScopedBaggageTest.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java b/api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java index 3965a13e340..a8a9fc1ef47 100644 --- a/api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java +++ b/api/src/main/java/io/opentelemetry/baggage/ImmutableBaggage.java @@ -17,7 +17,7 @@ @Immutable // TODO: Migrate to AutoValue // @AutoValue -public class ImmutableBaggage implements Baggage { +class ImmutableBaggage implements Baggage { static final Baggage EMPTY = new ImmutableBaggage.Builder().build(); // The types of the EntryKey and Entry must match for each entry. diff --git a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java index e2430cfdaae..7a431024a92 100644 --- a/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java +++ b/sdk/baggage/src/test/java/io/opentelemetry/sdk/baggage/ScopedBaggageTest.java @@ -11,13 +11,12 @@ import io.opentelemetry.baggage.BaggageUtils; import io.opentelemetry.baggage.Entry; import io.opentelemetry.baggage.EntryMetadata; -import io.opentelemetry.baggage.ImmutableBaggage; import io.opentelemetry.context.Scope; import org.junit.jupiter.api.Test; /** - * Unit tests for the methods in {@link BaggageUtils} and {@link ImmutableBaggage} that interact - * with the current {@link Baggage}. + * Unit tests for the methods in {@link BaggageUtils} and {@link Baggage} that interact with the + * current {@link Baggage}. */ class ScopedBaggageTest { @@ -38,7 +37,6 @@ class ScopedBaggageTest { void emptyBaggage() { Baggage defaultBaggage = BaggageUtils.getCurrentBaggage(); assertThat(defaultBaggage.getEntries()).isEmpty(); - assertThat(defaultBaggage).isInstanceOf(ImmutableBaggage.class); } @Test