Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrates to Brave 6 and Zipkin Reporter 3 #49

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only used in tests, so not making a top-level version yet.

</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.0</zipkin-reporter.version>

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