Skip to content

Commit

Permalink
Update to be compatible with Brave 5.18
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
Adrian Cole committed Jan 10, 2024
1 parent 04dc4ee commit 6ddb8dc
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 60 deletions.
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
<spring-cloud-openfeign.version>3.1.10-SNAPSHOT</spring-cloud-openfeign.version>
<spring-cloud-task.version>2.4.6</spring-cloud-task.version>
<spring-cloud-deployer.version>2.5.1</spring-cloud-deployer.version>
<brave.version>5.13.9</brave.version>
<opentracing.version>0.32.0</opentracing.version>
<!-- Deprecated - reached EOL -->
<spring-security-boot-autoconfigure.version>2.3.4.RELEASE</spring-security-boot-autoconfigure.version>
<spring-security-oauth2.version>2.2.0.RELEASE</spring-security-oauth2.version>
Expand Down
1 change: 1 addition & 0 deletions spring-cloud-sleuth-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@
<artifactId>zipkin</artifactId>
<optional>true</optional>
</dependency>
<!-- Needed for ZipkinRestTemplateSenderConfiguration: BytesMessageEncoder -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@ public TraceContext decorate(TraceContext context) {
return delegate.decorate(context);
}

@Override
public <K> Propagation<K> create(Propagation.KeyFactory<K> keyFactory) {
Propagation<K> propagation = delegate.create(keyFactory);
return delegateWithoutB3Baggage(factoryFromSupplier, propagation);
}

private <K> Propagation<K> delegateWithoutB3Baggage(Propagation.Factory factoryFromSupplier,
Propagation<K> propagation) {
return new Propagation<K>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpTracingCustomizer> httpTracingCustomizers) {
HttpTracing httpTracing(Tracing tracing, @Nullable SkipPatternProvider provider, BeanFactory beanFactory,
@Nullable List<HttpTracingCustomizer> httpTracingCustomizers) {
HttpTracing.Builder builder = httpTracingBuilder(tracing, provider, beanFactory);
brave.http.HttpRequestParser httpClientRequestParser = httpRequestParser(beanFactory,
HttpClientRequestParser.NAME);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}));
}

Expand All @@ -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");
}));
}

Expand All @@ -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");
}));
}

Expand All @@ -131,15 +129,15 @@ void should_use_baggagePropagationFactoryBuilder_bean() {
@Configuration(proxyBeanMethods = false)
static class Baggage {

List<BaggageField> fields;
Map<String, String> fields;

@Autowired
Baggage(Tracing tracing) {
// When predefined baggage fields exist, the result !=
// TraceContextOrSamplingFlags.EMPTY
TraceContextOrSamplingFlags emptyExtraction = tracing.propagation().extractor((c, k) -> null)
.extract(Boolean.TRUE);
fields = BaggageField.getAll(emptyExtraction);
fields = BaggageField.getAllValues(emptyExtraction);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,8 +158,8 @@ public <R> TraceContext.Extractor<R> extractor(Getter<R, String> getter) {
}

@Override
public <K> Propagation<K> create(KeyFactory<K> keyFactory) {
return StringPropagationAdapter.create(this, keyFactory);
public Propagation<String> get() {
return this;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,8 +93,8 @@ public <R> TraceContext.Extractor<R> extractor(Getter<R, String> getter) {
}

@Override
public <K> Propagation<K> create(KeyFactory<K> keyFactory) {
return StringPropagationAdapter.create(this, keyFactory);
public Propagation<String> get() {
return this;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,8 +128,8 @@ public <R> TraceContext.Extractor<R> extractor(Getter<R, String> getter) {
}

@Override
public <K> Propagation<K> create(KeyFactory<K> keyFactory) {
return StringPropagationAdapter.create(this, keyFactory);
public Propagation<String> get() {
return this;
}

@Override
Expand Down Expand Up @@ -177,8 +176,8 @@ private Propagation.Factory propagationFactory() {
}

@Override
public <K> Propagation<K> create(KeyFactory<K> keyFactory) {
return propagationFactory().create(keyFactory);
public Propagation<String> get() {
return new LazyPropagation(this);
}

@Override
Expand All @@ -191,11 +190,6 @@ public boolean requires128BitTraceId() {
return propagationFactory().requires128BitTraceId();
}

@Override
public Propagation<String> get() {
return new LazyPropagation(this);
}

@Override
public TraceContext decorate(TraceContext context) {
return propagationFactory().decorate(context);
Expand Down Expand Up @@ -260,8 +254,8 @@ public <R> TraceContext.Extractor<R> extractor(Getter<R, String> getter) {
}

@Override
public <K> Propagation<K> create(KeyFactory<K> keyFactory) {
return StringPropagationAdapter.create(this, keyFactory);
public Propagation<String> get() {
return this;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,8 +128,8 @@ class W3CPropagation extends Propagation.Factory implements Propagation<String>
}

@Override
public <K> Propagation<K> create(KeyFactory<K> keyFactory) {
return StringPropagationAdapter.create(this, keyFactory);
public Propagation<String> get() {
return this;
}

@Override
Expand Down Expand Up @@ -321,7 +320,7 @@ class W3CBaggagePropagator {
private BaggagePropagation.FactoryBuilder factory() {
return BaggagePropagation.newFactoryBuilder(new Propagation.Factory() {
@Override
public <K> Propagation<K> create(Propagation.KeyFactory<K> keyFactory) {
public Propagation<String> get() {
return null;
}
});
Expand Down
12 changes: 10 additions & 2 deletions spring-cloud-sleuth-dependencies/.flattened-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@
<downloadUrl>https://github.com/spring-cloud</downloadUrl>
</distributionManagement>
<properties>
<brave.opentracing.version>0.37.4</brave.opentracing.version>
<brave.opentracing.version>1.0.1</brave.opentracing.version>
<grpc.spring.boot.version>4.2.2</grpc.spring.boot.version>
<brave.version>5.13.9</brave.version>
<zipkin-reporter.version>2.17.2</zipkin-reporter.version>
<brave.version>5.18.0</brave.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -141,6 +142,13 @@
<artifactId>spring-cloud-sleuth-tests-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-bom</artifactId>
<version>${zipkin-reporter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-bom</artifactId>
Expand Down
24 changes: 22 additions & 2 deletions spring-cloud-sleuth-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
</scm>

<properties>
<brave.version>5.13.11</brave.version>
<brave.opentracing.version>0.37.5</brave.opentracing.version>
<brave.version>5.18.1</brave.version>
<zipkin-reporter.version>2.17.2</zipkin-reporter.version>
<brave.opentracing.version>1.0.1</brave.opentracing.version>
<grpc.spring.boot.version>4.2.3</grpc.spring.boot.version>
</properties>
<dependencyManagement>
Expand Down Expand Up @@ -85,13 +86,32 @@
<version>${project.version}</version>
</dependency>
<!-- BRAVE -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-bom</artifactId>
<version>${zipkin-reporter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-bom</artifactId>
<version>${brave.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Brave prior to v6 had a reporter dependency. Remove that to avoid conflicts. -->
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave</artifactId>
<version>${brave.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.opentracing.brave</groupId>
<artifactId>brave-opentracing</artifactId>
Expand Down
1 change: 1 addition & 0 deletions spring-cloud-sleuth-zipkin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
</dependency>
<!-- Needed for ZipkinRestTemplateSenderConfiguration: BytesMessageEncoder -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,8 +51,8 @@ public <R> TraceContext.Extractor<R> extractor(Getter<R, String> getter) {
}

@Override
public <K> Propagation<K> create(KeyFactory<K> keyFactory) {
return StringPropagationAdapter.create(this, keyFactory);
public Propagation<String> get() {
return this;
}

}
6 changes: 4 additions & 2 deletions tests/brave/spring-cloud-sleuth-zipkin-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
<!-- Needed for ZipkinRestTemplateSenderConfiguration: BytesMessageEncoder -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
<artifactId>zipkin-reporter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
Expand Down
5 changes: 3 additions & 2 deletions tests/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,13 @@
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
<artifactId>zipkin-reporter-brave</artifactId>
<optional>true</optional>
</dependency>
<!-- Needed for ZipkinRestTemplateSenderConfiguration: BytesMessageEncoder -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
<artifactId>zipkin-reporter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand Down

0 comments on commit 6ddb8dc

Please sign in to comment.