From 6ddb8dc65a19906acaf78bbe5e87079a14e77701 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 8 Jan 2024 16:46:58 +0800 Subject: [PATCH] Update to be compatible with Brave 5.18 Signed-off-by: Adrian Cole --- pom.xml | 2 -- spring-cloud-sleuth-autoconfigure/pom.xml | 1 + .../brave/BraveBaggageConfiguration.java | 6 ----- .../web/BraveHttpConfiguration.java | 11 ++------- .../brave/BraveAutoConfigurationTests.java | 14 +++++------ .../brave/BravePropagationTests.java | 5 ++-- .../CustomPropagationFactoryTests.java | 5 ++-- .../CompositePropagationFactorySupplier.java | 18 +++++--------- .../sleuth/brave/bridge/W3CPropagation.java | 7 +++--- .../.flattened-pom.xml | 12 ++++++++-- spring-cloud-sleuth-dependencies/pom.xml | 24 +++++++++++++++++-- spring-cloud-sleuth-zipkin/pom.xml | 1 + .../async/TraceAsyncIntegrationTests.java | 4 ++-- .../instrument/web/client/MergedFactory.java | 5 ++-- .../spring-cloud-sleuth-zipkin-tests/pom.xml | 6 +++-- tests/common/pom.xml | 5 ++-- 16 files changed, 66 insertions(+), 60 deletions(-) diff --git a/pom.xml b/pom.xml index 6abc183065..44b8ea6cb2 100644 --- a/pom.xml +++ b/pom.xml @@ -60,8 +60,6 @@ 3.1.10-SNAPSHOT 2.4.6 2.5.1 - 5.13.9 - 0.32.0 2.3.4.RELEASE 2.2.0.RELEASE diff --git a/spring-cloud-sleuth-autoconfigure/pom.xml b/spring-cloud-sleuth-autoconfigure/pom.xml index ca1108668d..43bf78995b 100644 --- a/spring-cloud-sleuth-autoconfigure/pom.xml +++ b/spring-cloud-sleuth-autoconfigure/pom.xml @@ -414,6 +414,7 @@ zipkin true + io.zipkin.reporter2 zipkin-reporter diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveBaggageConfiguration.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveBaggageConfiguration.java index 62cf393958..6cf8c00975 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveBaggageConfiguration.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveBaggageConfiguration.java @@ -334,12 +334,6 @@ public TraceContext decorate(TraceContext context) { return delegate.decorate(context); } - @Override - public Propagation create(Propagation.KeyFactory keyFactory) { - Propagation propagation = delegate.create(keyFactory); - return delegateWithoutB3Baggage(factoryFromSupplier, propagation); - } - private Propagation delegateWithoutB3Baggage(Propagation.Factory factoryFromSupplier, Propagation propagation) { return new Propagation() { diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/instrument/web/BraveHttpConfiguration.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/instrument/web/BraveHttpConfiguration.java index 5732b79b21..2309607bc0 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/instrument/web/BraveHttpConfiguration.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/instrument/web/BraveHttpConfiguration.java @@ -77,9 +77,8 @@ public class BraveHttpConfiguration { @Bean @ConditionalOnMissingBean // NOTE: stable bean name as might be used outside sleuth - HttpTracing httpTracing(Tracing tracing, @Nullable SkipPatternProvider provider, - @Nullable brave.http.HttpClientParser clientParser, @Nullable brave.http.HttpServerParser serverParser, - BeanFactory beanFactory, @Nullable List httpTracingCustomizers) { + HttpTracing httpTracing(Tracing tracing, @Nullable SkipPatternProvider provider, BeanFactory beanFactory, + @Nullable List httpTracingCustomizers) { HttpTracing.Builder builder = httpTracingBuilder(tracing, provider, beanFactory); brave.http.HttpRequestParser httpClientRequestParser = httpRequestParser(beanFactory, HttpClientRequestParser.NAME); @@ -98,9 +97,6 @@ HttpTracing httpTracing(Tracing tracing, @Nullable SkipPatternProvider provider, builder.clientResponseParser(httpClientResponseParser); } } - else if (clientParser != null) { // consider deprecated last - builder.clientParser(clientParser); - } if (httpServerRequestParser != null || httpServerResponseParser != null) { if (httpServerRequestParser != null) { @@ -110,9 +106,6 @@ else if (clientParser != null) { // consider deprecated last builder.serverResponseParser(httpServerResponseParser); } } - else if (serverParser != null) { // consider deprecated last - builder.serverParser(serverParser); - } if (httpTracingCustomizers != null) { for (HttpTracingCustomizer customizer : httpTracingCustomizers) { diff --git a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveAutoConfigurationTests.java b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveAutoConfigurationTests.java index abd440e653..e2619b7e6b 100644 --- a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveAutoConfigurationTests.java +++ b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveAutoConfigurationTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.sleuth.autoconfig.brave; -import java.util.List; +import java.util.Map; import brave.Tracing; import brave.baggage.BaggageField; @@ -95,8 +95,7 @@ void should_use_B3Propagation_factory_by_default() { void should_use_baggageBean() { this.contextRunner.withUserConfiguration(WithBaggageBeans.class, Baggage.class).run((context -> { final Baggage bean = context.getBean(Baggage.class); - BDDAssertions.then(bean.fields).containsOnly(BaggageField.create("country-code"), - BaggageField.create("x-vcap-request-id")); + BDDAssertions.then(bean.fields).containsEntry("country-code", "x-vcap-request-id"); })); } @@ -105,7 +104,7 @@ void should_use_local_keys_from_properties() { this.contextRunner.withPropertyValues("spring.sleuth.baggage.local-fields=bp") .withUserConfiguration(Baggage.class).run((context -> { final Baggage bean = context.getBean(Baggage.class); - BDDAssertions.then(bean.fields).containsExactly(BaggageField.create("bp")); + BDDAssertions.then(bean.fields).containsKey("bp"); })); } @@ -114,8 +113,7 @@ void should_combine_baggage_beans_and_properties() { this.contextRunner.withPropertyValues("spring.sleuth.baggage.local-fields=bp") .withUserConfiguration(WithBaggageBeans.class, Baggage.class).run((context -> { final Baggage bean = context.getBean(Baggage.class); - BDDAssertions.then(bean.fields).containsOnly(BaggageField.create("country-code"), - BaggageField.create("x-vcap-request-id"), BaggageField.create("bp")); + BDDAssertions.then(bean.fields).containsOnlyKeys("country-code", "x-vcap-request-id", "bp"); })); } @@ -131,7 +129,7 @@ void should_use_baggagePropagationFactoryBuilder_bean() { @Configuration(proxyBeanMethods = false) static class Baggage { - List fields; + Map fields; @Autowired Baggage(Tracing tracing) { @@ -139,7 +137,7 @@ static class Baggage { // TraceContextOrSamplingFlags.EMPTY TraceContextOrSamplingFlags emptyExtraction = tracing.propagation().extractor((c, k) -> null) .extract(Boolean.TRUE); - fields = BaggageField.getAll(emptyExtraction); + fields = BaggageField.getAllValues(emptyExtraction); } } diff --git a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BravePropagationTests.java b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BravePropagationTests.java index 96a2f0f949..e3e24df825 100644 --- a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BravePropagationTests.java +++ b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/BravePropagationTests.java @@ -22,7 +22,6 @@ import java.util.Map; import brave.internal.codec.HexCodec; -import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.Propagation; import brave.propagation.TraceContext; import brave.propagation.TraceContextOrSamplingFlags; @@ -159,8 +158,8 @@ public TraceContext.Extractor extractor(Getter getter) { } @Override - public Propagation create(KeyFactory keyFactory) { - return StringPropagationAdapter.create(this, keyFactory); + public Propagation get() { + return this; } } diff --git a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/baggage/CustomPropagationFactoryTests.java b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/baggage/CustomPropagationFactoryTests.java index 5ba137735b..ef5552d261 100644 --- a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/baggage/CustomPropagationFactoryTests.java +++ b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/brave/baggage/CustomPropagationFactoryTests.java @@ -19,7 +19,6 @@ import java.util.Collections; import java.util.List; -import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.Propagation; import brave.propagation.TraceContext; import brave.propagation.TraceContextOrSamplingFlags; @@ -94,8 +93,8 @@ public TraceContext.Extractor extractor(Getter getter) { } @Override - public Propagation create(KeyFactory keyFactory) { - return StringPropagationAdapter.create(this, keyFactory); + public Propagation get() { + return this; } } diff --git a/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/CompositePropagationFactorySupplier.java b/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/CompositePropagationFactorySupplier.java index 3afdd8d3b7..835cacf3ec 100644 --- a/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/CompositePropagationFactorySupplier.java +++ b/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/CompositePropagationFactorySupplier.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.stream.Collectors; -import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.B3Propagation; import brave.propagation.Propagation; import brave.propagation.TraceContext; @@ -129,8 +128,8 @@ public TraceContext.Extractor extractor(Getter getter) { } @Override - public Propagation create(KeyFactory keyFactory) { - return StringPropagationAdapter.create(this, keyFactory); + public Propagation get() { + return this; } @Override @@ -177,8 +176,8 @@ private Propagation.Factory propagationFactory() { } @Override - public Propagation create(KeyFactory keyFactory) { - return propagationFactory().create(keyFactory); + public Propagation get() { + return new LazyPropagation(this); } @Override @@ -191,11 +190,6 @@ public boolean requires128BitTraceId() { return propagationFactory().requires128BitTraceId(); } - @Override - public Propagation get() { - return new LazyPropagation(this); - } - @Override public TraceContext decorate(TraceContext context) { return propagationFactory().decorate(context); @@ -260,8 +254,8 @@ public TraceContext.Extractor extractor(Getter getter) { } @Override - public Propagation create(KeyFactory keyFactory) { - return StringPropagationAdapter.create(this, keyFactory); + public Propagation get() { + return this; } } diff --git a/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/W3CPropagation.java b/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/W3CPropagation.java index 4794f3ff9e..95e098acdd 100644 --- a/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/W3CPropagation.java +++ b/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/bridge/W3CPropagation.java @@ -31,7 +31,6 @@ import brave.baggage.BaggagePropagation; import brave.baggage.BaggagePropagationConfig; import brave.internal.baggage.BaggageFields; -import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.Propagation; import brave.propagation.TraceContext; import brave.propagation.TraceContextOrSamplingFlags; @@ -129,8 +128,8 @@ class W3CPropagation extends Propagation.Factory implements Propagation } @Override - public Propagation create(KeyFactory keyFactory) { - return StringPropagationAdapter.create(this, keyFactory); + public Propagation get() { + return this; } @Override @@ -321,7 +320,7 @@ class W3CBaggagePropagator { private BaggagePropagation.FactoryBuilder factory() { return BaggagePropagation.newFactoryBuilder(new Propagation.Factory() { @Override - public Propagation create(Propagation.KeyFactory keyFactory) { + public Propagation get() { return null; } }); diff --git a/spring-cloud-sleuth-dependencies/.flattened-pom.xml b/spring-cloud-sleuth-dependencies/.flattened-pom.xml index 23e93f39cc..63ec3f52e9 100644 --- a/spring-cloud-sleuth-dependencies/.flattened-pom.xml +++ b/spring-cloud-sleuth-dependencies/.flattened-pom.xml @@ -100,9 +100,10 @@ https://github.com/spring-cloud - 0.37.4 + 1.0.1 4.2.2 - 5.13.9 + 2.17.2 + 5.18.0 @@ -141,6 +142,13 @@ spring-cloud-sleuth-tests-common ${project.version} + + io.zipkin.reporter2 + zipkin-reporter-bom + ${zipkin-reporter.version} + pom + import + io.zipkin.brave brave-bom diff --git a/spring-cloud-sleuth-dependencies/pom.xml b/spring-cloud-sleuth-dependencies/pom.xml index 79dcafc3e8..1f69381635 100644 --- a/spring-cloud-sleuth-dependencies/pom.xml +++ b/spring-cloud-sleuth-dependencies/pom.xml @@ -42,8 +42,9 @@ - 5.13.11 - 0.37.5 + 5.18.1 + 2.17.2 + 1.0.1 4.2.3 @@ -85,6 +86,13 @@ ${project.version} + + io.zipkin.reporter2 + zipkin-reporter-bom + ${zipkin-reporter.version} + pom + import + io.zipkin.brave brave-bom @@ -92,6 +100,18 @@ pom import + + + io.zipkin.brave + brave + ${brave.version} + + + * + * + + + io.opentracing.brave brave-opentracing diff --git a/spring-cloud-sleuth-zipkin/pom.xml b/spring-cloud-sleuth-zipkin/pom.xml index 31ddef11ef..58f1f8b49c 100644 --- a/spring-cloud-sleuth-zipkin/pom.xml +++ b/spring-cloud-sleuth-zipkin/pom.xml @@ -96,6 +96,7 @@ io.zipkin.zipkin2 zipkin + io.zipkin.reporter2 zipkin-reporter diff --git a/tests/brave/spring-cloud-sleuth-instrumentation-async-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/async/TraceAsyncIntegrationTests.java b/tests/brave/spring-cloud-sleuth-instrumentation-async-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/async/TraceAsyncIntegrationTests.java index 0f5afefd63..5fcf8c3743 100644 --- a/tests/brave/spring-cloud-sleuth-instrumentation-async-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/async/TraceAsyncIntegrationTests.java +++ b/tests/brave/spring-cloud-sleuth-instrumentation-async-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/async/TraceAsyncIntegrationTests.java @@ -24,8 +24,8 @@ import brave.propagation.CurrentTraceContext; import brave.propagation.TraceContext; import brave.test.IntegrationTestSpanHandler; -import org.junit.ClassRule; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +48,7 @@ public class TraceAsyncIntegrationTests { private static final Logger log = LoggerFactory.getLogger(TraceAsyncIntegrationTests.class); - @ClassRule + @RegisterExtension public static IntegrationTestSpanHandler spans = new IntegrationTestSpanHandler(); TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true).build(); diff --git a/tests/brave/spring-cloud-sleuth-instrumentation-webflux-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/web/client/MergedFactory.java b/tests/brave/spring-cloud-sleuth-instrumentation-webflux-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/web/client/MergedFactory.java index 6168ebc725..6fb146d669 100644 --- a/tests/brave/spring-cloud-sleuth-instrumentation-webflux-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/web/client/MergedFactory.java +++ b/tests/brave/spring-cloud-sleuth-instrumentation-webflux-tests/src/test/java/org/springframework/cloud/sleuth/brave/instrument/web/client/MergedFactory.java @@ -20,7 +20,6 @@ import brave.Span; import brave.internal.collect.Lists; -import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.B3Propagation; import brave.propagation.Propagation; import brave.propagation.TraceContext; @@ -52,8 +51,8 @@ public TraceContext.Extractor extractor(Getter getter) { } @Override - public Propagation create(KeyFactory keyFactory) { - return StringPropagationAdapter.create(this, keyFactory); + public Propagation get() { + return this; } } diff --git a/tests/brave/spring-cloud-sleuth-zipkin-tests/pom.xml b/tests/brave/spring-cloud-sleuth-zipkin-tests/pom.xml index 499f0cbe08..7119e05750 100644 --- a/tests/brave/spring-cloud-sleuth-zipkin-tests/pom.xml +++ b/tests/brave/spring-cloud-sleuth-zipkin-tests/pom.xml @@ -82,11 +82,13 @@ io.zipkin.reporter2 - zipkin-reporter + zipkin-reporter-brave + io.zipkin.reporter2 - zipkin-reporter-brave + zipkin-reporter + true io.zipkin.reporter2 diff --git a/tests/common/pom.xml b/tests/common/pom.xml index 73295be6a8..965b34b65d 100644 --- a/tests/common/pom.xml +++ b/tests/common/pom.xml @@ -241,12 +241,13 @@ io.zipkin.reporter2 - zipkin-reporter + zipkin-reporter-brave true + io.zipkin.reporter2 - zipkin-reporter-brave + zipkin-reporter true