From 16390d67ca6cce5bd6482bcf31f3f49dfd04c083 Mon Sep 17 00:00:00 2001 From: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:35:28 +0800 Subject: [PATCH] Migrates to Brave 6 and Zipkin Reporter 3 (#49) Signed-off-by: Adrian Cole --- cassandra-tests/pom.xml | 5 ++++ .../java/cassandra/CassandraContainer.java | 3 +-- cassandra/pom.xml | 7 ++++++ .../main/java/brave/cassandra/Tracing.java | 24 +++++++++++++++---- pom.xml | 3 ++- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/cassandra-tests/pom.xml b/cassandra-tests/pom.xml index 3c45502..330109b 100644 --- a/cassandra-tests/pom.xml +++ b/cassandra-tests/pom.xml @@ -37,6 +37,11 @@ brave-tests ${brave.version} + + io.zipkin.zipkin2 + zipkin + 3.0.2 + org.junit.jupiter diff --git a/cassandra-tests/src/main/java/cassandra/CassandraContainer.java b/cassandra-tests/src/main/java/cassandra/CassandraContainer.java index 03b48a0..b2cc68d 100644 --- a/cassandra-tests/src/main/java/cassandra/CassandraContainer.java +++ b/cassandra-tests/src/main/java/cassandra/CassandraContainer.java @@ -15,7 +15,6 @@ import java.net.InetSocketAddress; import java.time.Duration; -import org.junit.AssumptionViolatedException; import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; @@ -25,7 +24,7 @@ public class CassandraContainer extends GenericContainer { public CassandraContainer() { - super(parse("ghcr.io/openzipkin/zipkin-cassandra:2.27.0")); + super(parse("ghcr.io/openzipkin/zipkin-cassandra:3.0.2")); waitStrategy = Wait.forHealthcheck(); addExposedPort(9042); withStartupTimeout(Duration.ofMinutes(2)); diff --git a/cassandra/pom.xml b/cassandra/pom.xml index 9b5b62c..f612b78 100644 --- a/cassandra/pom.xml +++ b/cassandra/pom.xml @@ -31,6 +31,13 @@ + + io.zipkin.reporter2 + zipkin-reporter-bom + ${zipkin-reporter.version} + pom + import + io.zipkin.brave brave-bom diff --git a/cassandra/src/main/java/brave/cassandra/Tracing.java b/cassandra/src/main/java/brave/cassandra/Tracing.java index 7fefc30..67c8109 100644 --- a/cassandra/src/main/java/brave/cassandra/Tracing.java +++ b/cassandra/src/main/java/brave/cassandra/Tracing.java @@ -21,6 +21,7 @@ import brave.propagation.TraceContextOrSamplingFlags; import java.net.InetAddress; import java.nio.ByteBuffer; +import java.util.Collections; import java.util.Map; import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.net.Message; @@ -28,8 +29,6 @@ import org.apache.cassandra.tracing.TraceStateImpl; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.TimeUUID; -import zipkin2.reporter.Call; -import zipkin2.reporter.CheckResult; import zipkin2.reporter.brave.AsyncZipkinSpanHandler; import zipkin2.reporter.urlconnection.URLConnectionSender; @@ -69,9 +68,13 @@ public Tracing() { logger.info("using TracingComponent.Explicit(" + endpoint + ")"); URLConnectionSender sender = URLConnectionSender.create(endpoint); try { - CheckResult check = sender.check(); - if (!check.ok()) maybeFailFast(check.error()); + sender.send(Collections.emptyList()); + } catch (Throwable t) { + propagateIfFatal(t); + maybeFailFast(t); + } + try { AsyncZipkinSpanHandler zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender); // Make sure spans are reported on shutdown Runtime.getRuntime().addShutdownHook(new Thread(zipkinSpanHandler::close)); @@ -84,12 +87,23 @@ public Tracing() { .build(); component = new TracingComponent.Explicit(tracing); } catch (RuntimeException | Error t) { - Call.propagateIfFatal(t); + propagateIfFatal(t); maybeFailFast(t); throw t; } } + // Taken from RxJava throwIfFatal, which was taken from scala + static void propagateIfFatal(Throwable t) { + if (t instanceof VirtualMachineError) { + throw (VirtualMachineError) t; + } else if (t instanceof ThreadDeath) { + throw (ThreadDeath) t; + } else if (t instanceof LinkageError) { + throw (LinkageError) t; + } + } + static void maybeFailFast(Throwable error) { if (Boolean.parseBoolean(System.getProperty("zipkin.fail_fast", "false"))) { logger.error("Error initializing tracer: ", error); diff --git a/pom.xml b/pom.xml index e249d34..a23183a 100644 --- a/pom.xml +++ b/pom.xml @@ -98,7 +98,8 @@ 11 3.11.2 - 5.18.0 + 6.0.0 + 3.2.1