Skip to content

Commit

Permalink
Migrates to Brave 6 and Zipkin Reporter 3 (#49)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt authored Jan 15, 2024
1 parent bafb7f0 commit 16390d6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions cassandra-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<artifactId>brave-tests</artifactId>
<version>${brave.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>3.0.2</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +24,7 @@

public class CassandraContainer extends GenericContainer<CassandraContainer> {
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));
Expand Down
7 changes: 7 additions & 0 deletions cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@

<dependencyManagement>
<dependencies>
<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: 19 additions & 5 deletions cassandra/src/main/java/brave/cassandra/Tracing.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
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;
import org.apache.cassandra.tracing.TraceState;
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;

Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
<maven.compiler.testRelease>11</maven.compiler.testRelease>

<cassandra-driver-core.version>3.11.2</cassandra-driver-core.version>
<brave.version>5.18.0</brave.version>
<brave.version>6.0.0</brave.version>
<zipkin-reporter.version>3.2.1</zipkin-reporter.version>

<!-- override to set exclusions per-project -->
<errorprone.args />
Expand Down

0 comments on commit 16390d6

Please sign in to comment.