diff --git a/brave/src/main/java/brave/baggage/BaggagePropagation.java b/brave/src/main/java/brave/baggage/BaggagePropagation.java index 5c7d99097..276aaeebd 100644 --- a/brave/src/main/java/brave/baggage/BaggagePropagation.java +++ b/brave/src/main/java/brave/baggage/BaggagePropagation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -18,7 +18,6 @@ import brave.internal.baggage.BaggageCodec; import brave.internal.baggage.BaggageFields; import brave.internal.collect.Lists; -import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.ExtraFieldPropagation; import brave.propagation.Propagation; import brave.propagation.TraceContext; @@ -198,10 +197,6 @@ static final class Factory extends Propagation.Factory implements Propagation BaggagePropagation create(KeyFactory keyFactory) { - return new BaggagePropagation(StringPropagationAdapter.create(get(), keyFactory)); - } - @Override public BaggagePropagation get() { return new BaggagePropagation(this); } diff --git a/brave/src/main/java/brave/internal/propagation/StringPropagationAdapter.java b/brave/src/main/java/brave/internal/propagation/StringPropagationAdapter.java index 0d090db15..2396857ee 100644 --- a/brave/src/main/java/brave/internal/propagation/StringPropagationAdapter.java +++ b/brave/src/main/java/brave/internal/propagation/StringPropagationAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -70,7 +70,10 @@ * } * * @since 5.12 + * @deprecated As of Brave 5.18, throw an {@link UnsupportedOperationException} in + * {@link #create(Propagation, KeyFactory)} instead of implementing it. */ +@Deprecated public final class StringPropagationAdapter implements Propagation { public static Propagation create(Propagation delegate, KeyFactory keyFactory) { if (delegate == null) throw new NullPointerException("delegate == null"); diff --git a/brave/src/main/java/brave/propagation/B3SinglePropagation.java b/brave/src/main/java/brave/propagation/B3SinglePropagation.java index 4e7d2d18d..dc8dc7da0 100644 --- a/brave/src/main/java/brave/propagation/B3SinglePropagation.java +++ b/brave/src/main/java/brave/propagation/B3SinglePropagation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -18,9 +18,9 @@ /** * Implements the propagation format described in {@link B3SingleFormat}. * - * @deprecated Since 5.9, use {@link B3Propagation#newFactoryBuilder()} to control inject formats. + *

Use {@link B3Propagation#newFactoryBuilder()} to control inject formats. */ -@Deprecated public final class B3SinglePropagation { +public final class B3SinglePropagation { public static final Propagation.Factory FACTORY = B3Propagation.newFactoryBuilder() .injectFormat(B3Propagation.Format.SINGLE) .injectFormat(Span.Kind.CLIENT, B3Propagation.Format.SINGLE) diff --git a/brave/src/main/java/brave/propagation/ExtraFieldPropagation.java b/brave/src/main/java/brave/propagation/ExtraFieldPropagation.java index 64d411c2e..e1651b2d1 100644 --- a/brave/src/main/java/brave/propagation/ExtraFieldPropagation.java +++ b/brave/src/main/java/brave/propagation/ExtraFieldPropagation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -19,7 +19,6 @@ import brave.internal.Nullable; import brave.propagation.TraceContext.Extractor; import brave.propagation.TraceContext.Injector; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -190,24 +189,16 @@ public Factory build() { /** @deprecated Since 5.11 use {@link Propagation.Factory} */ public static class Factory extends Propagation.Factory { final Propagation.Factory delegate; - final String[] extraKeyNames; + final List extraKeyNames; Factory(Propagation.Factory delegate, String[] extraKeyNames) { this.delegate = delegate; - this.extraKeyNames = extraKeyNames; + this.extraKeyNames = unmodifiableList(Arrays.asList(extraKeyNames)); } /** {@inheritDoc} */ @Override public ExtraFieldPropagation get() { - return create(KeyFactory.STRING); - } - - /** {@inheritDoc} */ - @Deprecated @Override - public ExtraFieldPropagation create(Propagation.KeyFactory keyFactory) { - List extraKeys = new ArrayList(); - for (String extraKeyName : extraKeyNames) extraKeys.add(keyFactory.create(extraKeyName)); - return new ExtraFieldPropagation(delegate.create(keyFactory), unmodifiableList(extraKeys)); + return new ExtraFieldPropagation(delegate.get(), extraKeyNames); } @Override public boolean supportsJoin() { diff --git a/brave/src/main/java/brave/propagation/Propagation.java b/brave/src/main/java/brave/propagation/Propagation.java index 5cc76041a..53a650de4 100644 --- a/brave/src/main/java/brave/propagation/Propagation.java +++ b/brave/src/main/java/brave/propagation/Propagation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -17,7 +17,6 @@ import brave.Span.Kind; import brave.baggage.BaggagePropagation; import brave.internal.Nullable; -import brave.internal.propagation.StringPropagationAdapter; import java.util.List; /** @@ -32,9 +31,11 @@ * request is sent to the server. The server {@linkplain TraceContext.Extractor#extract extracts} a * trace context from these headers before processing the request. * - * @param Deprecated except when a {@link String}. + * @param Retained for compatibility with pre Brave 6.0, but always String. * @since 4.0 */ +// The generic type parameter K is always . Even if the deprecated methods are removed in +// Brave 6.0. This is to avoid a compilation break and revlock. public interface Propagation { /** * Defaults B3 formats based on {@link Request} type. When not a {@link Request} (e.g. in-process @@ -44,9 +45,9 @@ public interface Propagation { */ Propagation B3_STRING = B3Propagation.get(); /** - * @deprecated Since 5.9, use {@link B3Propagation#newFactoryBuilder()} to control inject formats. + * Implements the propagation format described in {@link B3SingleFormat}. */ - @Deprecated Propagation B3_SINGLE_STRING = B3SinglePropagation.FACTORY.get(); + Propagation B3_SINGLE_STRING = B3SinglePropagation.FACTORY.get(); /** @since 4.0 */ abstract class Factory { @@ -54,7 +55,7 @@ abstract class Factory { * Does the propagation implementation support sharing client and server span IDs. For example, * should an RPC server span share the same identifiers extracted from an incoming request? * - * In usual B3 Propagation, the + *

In usual B3 Propagation, the * parent span ID is sent across the wire so that the client and server can share the same * identifiers. Other propagation formats, like trace-context * only propagate the calling trace and span ID, with an assumption that the receiver always @@ -78,31 +79,28 @@ public boolean requires128BitTraceId() { } /** - * This is deprecated: end users and instrumentation should never call this, and instead use - * {@link #get()}. - * - *

Implementation advice

- * This is deprecated, but abstract. This means those implementing custom propagation formats - * will have to implement this until it is removed in Brave 6. If you are able to use a tool - * such as "maven-shade-plugin", consider using {@link StringPropagationAdapter}. - * - * @param Deprecated except when a {@link String}. - * @see KeyFactory#STRING - * @since 4.0 - * @deprecated Since 5.12, use {@link #get()} + * @deprecated end users and instrumentation should never call this, and instead use + * {@link #get()}. This will not be removed, to avoid rev-lock upgrading to Brave 6. */ - @Deprecated - public abstract Propagation create(KeyFactory keyFactory); + @Deprecated public Propagation create(KeyFactory unused) { + // In Brave 5.12, this was abstract, but not used: `get()` dispatched + // to this. Brave 5.18 implemented this with the below exception to force + // `get()` to be overridden. Doing so allows us to make `get()` abstract + // in Brave 6.0, but we will have to leave this here regardless, to + // prevent revlock upgrading. + throw new UnsupportedOperationException("This was replaced with PropagationFactory.get() in Brave 5.12"); + } /** * Returns a possibly cached propagation instance. * - *

Implementations should override and implement this method directly. - * * @since 5.12 */ public Propagation get() { - return create(KeyFactory.STRING); + // In Brave 5.12, this dispatched to the deprecated abstract method + // `create()`. In Brave 5.18, we throw an exception instead to ensure it + // is implemented prior to Brave 6.0 making this abstract. + throw new UnsupportedOperationException("As of Brave 5.18, you must implement PropagationFactory.get()"); } /** @@ -126,7 +124,8 @@ public TraceContext decorate(TraceContext context) { /** * @since 4.0 - * @deprecated since 5.12 non-string keys are no longer supported + * @deprecated since 5.12 non-string keys are no longer supported. This will not be removed, to + * avoid rev-lock upgrading to Brave 6. */ @Deprecated interface KeyFactory { @@ -147,7 +146,7 @@ interface KeyFactory { * Replaces a propagated key with the given value. * * @param Usually, but not always, an instance of {@link Request}. - * @param Deprecated except when a {@link String}. + * @param Retained for compatibility with pre Brave 6.0, but always String. * @see RemoteSetter * @since 4.0 */ @@ -212,7 +211,7 @@ interface Setter { * Gets the first value of the given propagation key or returns {@code null}. * * @param Usually, but not always, an instance of {@link Request}. - * @param Deprecated except when a {@link String}. + * @param Retained for compatibility with pre Brave 6.0, but always String. * @see RemoteGetter * @since 4.0 */ diff --git a/brave/src/test/java/brave/TracerTest.java b/brave/src/test/java/brave/TracerTest.java index d5cf11cfe..0b238539b 100644 --- a/brave/src/test/java/brave/TracerTest.java +++ b/brave/src/test/java/brave/TracerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -19,8 +19,6 @@ import brave.baggage.BaggagePropagationConfig.SingleBaggageField; import brave.handler.MutableSpan; import brave.handler.SpanHandler; -import brave.internal.Platform; -import brave.internal.handler.OrphanTracker; import brave.propagation.B3Propagation; import brave.propagation.CurrentTraceContext; import brave.propagation.CurrentTraceContext.Scope; @@ -42,7 +40,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; - import zipkin2.Endpoint; import zipkin2.reporter.Reporter; @@ -68,8 +65,8 @@ public class TracerTest { .addSpanHandler(spans) .trackOrphans() .propagationFactory(new Propagation.Factory() { - @Deprecated @Override public Propagation create(Propagation.KeyFactory keyFactory) { - return propagationFactory.create(keyFactory); + @Override public Propagation get() { + return propagationFactory.get(); } @Override public boolean supportsJoin() { @@ -229,9 +226,8 @@ public class TracerTest { @Test void join_createsChildWhenUnsupportedByPropagation() { tracer = Tracing.newBuilder() .propagationFactory(new Propagation.Factory() { - @Override - @Deprecated public Propagation create(Propagation.KeyFactory keyFactory) { - return B3Propagation.FACTORY.create(keyFactory); + @Override public Propagation get() { + return B3Propagation.FACTORY.get(); } }) .addSpanHandler(spans).build().tracer(); diff --git a/brave/src/test/java/brave/TracingTest.java b/brave/src/test/java/brave/TracingTest.java index 61aff7e5c..00a540c5b 100644 --- a/brave/src/test/java/brave/TracingTest.java +++ b/brave/src/test/java/brave/TracingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -243,8 +243,8 @@ class TracingTest { AtomicBoolean sampledLocal = new AtomicBoolean(); try (Tracing tracing = Tracing.newBuilder() .propagationFactory(new Propagation.Factory() { - @Deprecated public Propagation create(Propagation.KeyFactory keyFactory) { - return B3SinglePropagation.FACTORY.create(keyFactory); + @Override public Propagation get() { + return B3SinglePropagation.FACTORY.get(); } @Override public TraceContext decorate(TraceContext context) { diff --git a/brave/src/test/java/brave/features/propagation/CustomTraceIdPropagation.java b/brave/src/test/java/brave/features/propagation/CustomTraceIdPropagation.java index 58f6aac36..216458262 100644 --- a/brave/src/test/java/brave/features/propagation/CustomTraceIdPropagation.java +++ b/brave/src/test/java/brave/features/propagation/CustomTraceIdPropagation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -41,7 +41,7 @@ public final class CustomTraceIdPropagation extends Propagation.Factory public static Propagation.Factory create(Propagation.Factory delegate, String customTraceIdName) { if (delegate == null) throw new NullPointerException("delegate == null"); if (customTraceIdName == null) throw new NullPointerException("customTraceIdName == null"); - if (!delegate.create(KeyFactory.STRING).keys().contains("b3")) { + if (!delegate.get().keys().contains("b3")) { throw new IllegalArgumentException("delegate must implement B3 propagation"); } return new CustomTraceIdPropagation(delegate, customTraceIdName); diff --git a/brave/src/test/java/brave/features/propagation/NonStringPropagationKeysTest.java b/brave/src/test/java/brave/features/propagation/NonStringPropagationKeysTest.java index 4f27012e2..6fd4c0082 100644 --- a/brave/src/test/java/brave/features/propagation/NonStringPropagationKeysTest.java +++ b/brave/src/test/java/brave/features/propagation/NonStringPropagationKeysTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -24,6 +24,8 @@ /** This shows propagation keys don't need to be Strings. For example, we can propagate over gRPC */ class NonStringPropagationKeysTest { TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true).build(); + + // Note: This class will be removed in Brave 6.0, but B3Propagation implements create meanwhile. Propagation> grpcPropagation = B3Propagation.FACTORY.create( name -> Metadata.Key.of(name, Metadata.ASCII_STRING_MARSHALLER) ); @@ -31,7 +33,6 @@ class NonStringPropagationKeysTest { TraceContext.Injector injector = grpcPropagation.injector(Metadata::put); @Test void injectExtractTraceContext() { - Metadata metadata = new Metadata(); injector.inject(context, metadata); diff --git a/brave/src/test/java/brave/internal/extra/ExtraFactoryTest.java b/brave/src/test/java/brave/internal/extra/ExtraFactoryTest.java index b5b6acf19..8516700d6 100644 --- a/brave/src/test/java/brave/internal/extra/ExtraFactoryTest.java +++ b/brave/src/test/java/brave/internal/extra/ExtraFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -30,8 +30,8 @@ class ExtraFactoryTest { .build(); Propagation.Factory propagationFactory = new Propagation.Factory() { - @Deprecated @Override public Propagation create(Propagation.KeyFactory keyFactory) { - return B3Propagation.FACTORY.create(keyFactory); + @Override public Propagation get() { + return B3Propagation.FACTORY.get(); } @Override public TraceContext decorate(TraceContext context) { diff --git a/instrumentation/kafka-clients/src/test/java/brave/kafka/clients/ITKafkaTracing.java b/instrumentation/kafka-clients/src/test/java/brave/kafka/clients/ITKafkaTracing.java index 1b9112feb..9fc3a1b15 100644 --- a/instrumentation/kafka-clients/src/test/java/brave/kafka/clients/ITKafkaTracing.java +++ b/instrumentation/kafka-clients/src/test/java/brave/kafka/clients/ITKafkaTracing.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 The OpenZipkin Authors + * Copyright 2013-2024 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -16,7 +16,6 @@ import brave.Span.Kind; import brave.handler.MutableSpan; import brave.internal.codec.HexCodec; -import brave.internal.propagation.StringPropagationAdapter; import brave.messaging.MessagingRuleSampler; import brave.messaging.MessagingTracing; import brave.propagation.Propagation; @@ -213,10 +212,6 @@ static class TraceIdOnlyPropagation extends Propagation.Factory implements Propa @Override public Propagation get() { return this; } - - @Override public Propagation create(KeyFactory keyFactory) { - return StringPropagationAdapter.create(this, keyFactory); - } } @Test void continues_a_trace_when_only_trace_id_propagated() {