Skip to content

Commit

Permalink
deps: bumps to Brave 6.0.0 and moves off internal type
Browse files Browse the repository at this point in the history
This updates to Brave 6.0.0 and dodges an internal type that is not
in Brave 6.0.

Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
Adrian Cole committed Jan 10, 2024
1 parent b890027 commit d11d803
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 37 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def MICROMETER_PLATFORM_VERSIONS = [
]

def PLATFORM_VERSIONS = [
libs.zipkinReporterBom,
libs.braveBom,
// opentelemetry-instrumentation-api dependency above with this
libs.otelBom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import brave.baggage.BaggagePropagation;
import brave.baggage.BaggagePropagationConfig;
import brave.context.slf4j.MDCScopeDecorator;
import brave.handler.SpanHandler;
import brave.propagation.B3Propagation;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.sampler.Sampler;
Expand All @@ -42,7 +41,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
import zipkin2.reporter.brave.ZipkinSpanHandler;
import zipkin2.reporter.urlconnection.URLConnectionSender;

Expand All @@ -67,8 +66,8 @@ class BraveTests {
// in a Zipkin format to the provided location via the UrlConnectionSender
// (through the <io.zipkin.reporter2:zipkin-sender-urlconnection> dependency)
// Another option could be to use a TestSpanHandler for testing purposes.
SpanHandler spanHandler = ZipkinSpanHandler
.create(AsyncReporter.create(URLConnectionSender.create("http://localhost:9411/api/v2/spans")));
AsyncZipkinSpanHandler spanHandler = AsyncZipkinSpanHandler
.create(URLConnectionSender.create("http://localhost:9411/api/v2/spans"));

// [Brave component] CurrentTraceContext is a Brave component that allows you to
// retrieve the current TraceContext.
Expand Down
11 changes: 9 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ jmh="1.37"
jakartaWeb="9.1.0"
otelInstrumentation="1.32.0-alpha"
aopalliance="1.0"
zipkinAws="0.23.5"
# TODO: Update to 1.0.0 after https://github.com/open-telemetry/opentelemetry-java/pull/6129
zipkinAws="0.24.0"
otelBom="1.33.0"
logback = "1.4.14"
wavefrontSdk="3.4.3"
Expand All @@ -20,7 +21,12 @@ awaitility = "4.2.0"
mockito = "5.8.0"
wiremock = "3.0.1"
testcontainers = "1.19.3"
braveBom = "5.17.0"
braveBom = "6.0.0"
# TODO: Update to 3.1.1 after https://github.com/open-telemetry/opentelemetry-java/pull/6129
# Then, add an optional bean zipkin2.reporter.BytesEncoder<brave.handler.MutableSpan>
# When present, use the overload of AsyncZipkinSpanHandler.build, allowing custom formats like
# OTLP, Wavefront or Stackdriver.
zipkinReporterBom = "2.17.2"
reactorBom = "2022.0.14"
asmForPlugins = "7.3.1"
javaFormatForPlugins = "0.0.40"
Expand Down Expand Up @@ -61,6 +67,7 @@ wavefrontSdk = { module = "com.wavefront:wavefront-sdk-java", version.ref = "wav
wavefrontReporter = { module = "com.wavefront:wavefront-internal-reporter-java", version.ref = "wavefrontReporter" }
wiremock = { module = "com.github.tomakehurst:wiremock-jre8-standalone", version.ref = "wiremock" }
zipkinAws = { module = "io.zipkin.aws:brave-propagation-aws", version.ref = "zipkinAws" }
zipkinReporterBom = { module = "io.zipkin.reporter2:zipkin-reporter-bom", version.ref = "zipkinReporterBom" }

# plugin dependencies
plugin-license = { module = "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin", version = "0.16.1" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.micrometer.tracing.brave.bridge;

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 @@ -175,8 +174,8 @@ private static TraceContext extractContextFromTraceParent(String traceparent) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.propagation.Propagator;
import io.micrometer.tracing.test.reporter.BuildingBlocks;
import zipkin2.Span;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.Reporter;
import zipkin2.reporter.Sender;
import zipkin2.reporter.brave.ZipkinSpanHandler;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
import zipkin2.reporter.urlconnection.URLConnectionSender;

import java.util.Deque;
Expand Down Expand Up @@ -97,9 +94,9 @@ public static class Builder {

private Supplier<Sender> sender;

private Function<Sender, AsyncReporter<Span>> reporter;
private Function<Sender, AsyncZipkinSpanHandler> spanHandler;

private Function<Reporter, Tracing> tracing;
private Function<AsyncZipkinSpanHandler, Tracing> tracing;

private Function<Tracing, Tracer> tracer;

Expand All @@ -124,7 +121,7 @@ public static class BraveBuildingBlocks implements BuildingBlocks {

private final Sender sender;

private final AsyncReporter<Span> reporter;
private final AsyncZipkinSpanHandler spanHandler;

private final Tracing tracing;

Expand All @@ -147,7 +144,7 @@ public static class BraveBuildingBlocks implements BuildingBlocks {
/**
* Creates a new instance of {@link BraveBuildingBlocks}.
* @param sender sender
* @param reporter reporter
* @param spanHandler spanHandler
* @param tracing tracing
* @param tracer tracer
* @param propagator propagator
Expand All @@ -157,13 +154,13 @@ public static class BraveBuildingBlocks implements BuildingBlocks {
* @param customizers observation handler customizers
* @param testSpanHandler test span handler
*/
public BraveBuildingBlocks(Sender sender, AsyncReporter<Span> reporter, Tracing tracing, Tracer tracer,
BravePropagator propagator, HttpTracing httpTracing, HttpServerHandler httpServerHandler,
HttpClientHandler httpClientHandler,
public BraveBuildingBlocks(Sender sender, AsyncZipkinSpanHandler spanHandler, Tracing tracing,
Tracer tracer, BravePropagator propagator, HttpTracing httpTracing,
HttpServerHandler httpServerHandler, HttpClientHandler httpClientHandler,
BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers,
TestSpanHandler testSpanHandler) {
this.sender = sender;
this.reporter = reporter;
this.spanHandler = spanHandler;
this.tracing = tracing;
this.tracer = tracer;
this.propagator = propagator;
Expand Down Expand Up @@ -260,12 +257,12 @@ public Builder sender(Supplier<Sender> sender) {
}

/**
* Overrides reporter.
* @param reporter reporter provider
* Overrides spanHandler.
* @param spanHandler spanHandler provider
* @return this for chaining
*/
public Builder reporter(Function<Sender, AsyncReporter<Span>> reporter) {
this.reporter = reporter;
public Builder spanHandler(Function<Sender, AsyncZipkinSpanHandler> spanHandler) {
this.spanHandler = spanHandler;
return this;
}

Expand All @@ -274,7 +271,7 @@ public Builder reporter(Function<Sender, AsyncReporter<Span>> reporter) {
* @param tracing tracing provider
* @return this for chaining
*/
public Builder tracing(Function<Reporter, Tracing> tracing) {
public Builder tracing(Function<AsyncZipkinSpanHandler, Tracing> tracing) {
this.tracing = tracing;
return this;
}
Expand Down Expand Up @@ -363,10 +360,11 @@ public Builder closingFunction(Consumer<Builder.BraveBuildingBlocks> closingFunc
*/
public ZipkinBraveSetup register(ObservationRegistry registry) {
Sender sender = this.sender != null ? this.sender.get() : sender(this.zipkinUrl);
AsyncReporter<Span> reporter = this.reporter != null ? this.reporter.apply(sender) : reporter(sender);
AsyncZipkinSpanHandler spanHandler = this.spanHandler != null ? this.spanHandler.apply(sender)
: spanHandler(sender);
TestSpanHandler testSpanHandler = new TestSpanHandler();
Tracing tracing = this.tracing != null ? this.tracing.apply(reporter)
: tracing(reporter, testSpanHandler, this.applicationName);
Tracing tracing = this.tracing != null ? this.tracing.apply(spanHandler)
: tracing(spanHandler, testSpanHandler, this.applicationName);
Tracer tracer = this.tracer != null ? this.tracer.apply(tracing) : tracer(tracing);
HttpTracing httpTracing = this.httpTracing != null ? this.httpTracing.apply(tracing) : httpTracing(tracing);
@Deprecated
Expand All @@ -378,7 +376,7 @@ public ZipkinBraveSetup register(ObservationRegistry registry) {
BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers = this.customizers != null
? this.customizers : (t, h) -> {
};
BraveBuildingBlocks braveBuildingBlocks = new BraveBuildingBlocks(sender, reporter, tracing, tracer,
BraveBuildingBlocks braveBuildingBlocks = new BraveBuildingBlocks(sender, spanHandler, tracing, tracer,
new BravePropagator(tracing), httpTracing, httpServerHandler, httpClientHandler, customizers,
testSpanHandler);
ObservationHandler<? extends Observation.Context> tracingHandlers = this.handlers != null
Expand All @@ -399,20 +397,20 @@ private static Sender sender(String zipkinUrl) {
.build();
}

private static AsyncReporter<Span> reporter(Sender sender) {
return AsyncReporter.builder(sender).build();
private static AsyncZipkinSpanHandler spanHandler(Sender sender) {
return AsyncZipkinSpanHandler.create(sender);
}

private static Tracer tracer(Tracing tracing) {
return new BraveTracer(tracing.tracer(), new BraveCurrentTraceContext(tracing.currentTraceContext()),
new BraveBaggageManager());
}

private static Tracing tracing(AsyncReporter<Span> reporter, TestSpanHandler testSpanHandler,
private static Tracing tracing(AsyncZipkinSpanHandler spanHandler, TestSpanHandler testSpanHandler,
String applicationName) {
return Tracing.newBuilder()
.localServiceName(applicationName)
.addSpanHandler(ZipkinSpanHandler.newBuilder(reporter).build())
.addSpanHandler(spanHandler)
.addSpanHandler(testSpanHandler)
.currentTraceContext(ThreadLocalCurrentTraceContext.create())
.sampler(Sampler.ALWAYS_SAMPLE)
Expand All @@ -427,9 +425,9 @@ private static Consumer<BraveBuildingBlocks> closingFunction() {
return deps -> {
deps.httpTracing.close();
deps.tracing.close();
AsyncReporter reporter = deps.reporter;
reporter.flush();
reporter.close();
AsyncZipkinSpanHandler spanHandler = deps.spanHandler;
spanHandler.flush();
spanHandler.close();
};
}

Expand Down

0 comments on commit d11d803

Please sign in to comment.