Skip to content

Commit

Permalink
Tracing: added OpenTelemetry integration test
Browse files Browse the repository at this point in the history
The test verifies that span tree structure and status code are valid.
Speculative executions are run parallel to the main thread, so some
of them can finish only after query result has been returned.
Thus, in order to collect span data from entire request, we decided
to wait until all speculative executions end. The main thread uses
conditional variable `allEnded` to wait for them and lock is used
for concurrent mutation of activeSpans.
  • Loading branch information
wprzytula committed Sep 26, 2022
1 parent e30928a commit 53cdcaa
Show file tree
Hide file tree
Showing 3 changed files with 902 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.RetryPolicy;
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
import com.datastax.driver.core.tracing.PrecisionLevel;
import com.datastax.driver.core.tracing.TracingInfo;
import com.datastax.driver.core.tracing.VerbosityLevel;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
Expand All @@ -32,9 +32,9 @@ public class OpenTelemetryTracingInfo implements TracingInfo {
private final Tracer tracer;
private final Context context;
private boolean tracingStarted;
private final PrecisionLevel precision;
private final VerbosityLevel precision;

protected OpenTelemetryTracingInfo(Tracer tracer, Context context, PrecisionLevel precision) {
protected OpenTelemetryTracingInfo(Tracer tracer, Context context, VerbosityLevel precision) {
this.tracer = tracer;
this.context = context;
this.precision = precision;
Expand All @@ -53,7 +53,7 @@ private void assertStarted() {
assert tracingStarted : "TracingInfo.setStartTime must be called before any other method";
}

public PrecisionLevel getPrecision() {
public VerbosityLevel getVerbosity() {
return precision;
}

Expand All @@ -72,14 +72,14 @@ public void setConsistencyLevel(ConsistencyLevel consistency) {

public void setStatement(String statement) {
assertStarted();
if (currentPrecisionLevelIsAtLeast(PrecisionLevel.FULL)) {
if (currentVerbosityLevelIsAtLeast(VerbosityLevel.FULL)) {
span.setAttribute("db.scylladb.statement", statement);
}
}

public void setHostname(String hostname) {
assertStarted();
if (currentPrecisionLevelIsAtLeast(PrecisionLevel.FULL)) {
if (currentVerbosityLevelIsAtLeast(VerbosityLevel.FULL)) {
span.setAttribute("net.peer.name", hostname);
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public void setRowsCount(int rowsCount) {
@Override
public void setStatement(String statement, int limit) {
assertStarted();
if (currentPrecisionLevelIsAtLeast(PrecisionLevel.FULL)) {
if (currentVerbosityLevelIsAtLeast(VerbosityLevel.FULL)) {
if (statement.length() > limit) statement = statement.substring(0, limit);
span.setAttribute("db.scylladb.statement", statement);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ public void tracingFinished() {
span.end();
}

private boolean currentPrecisionLevelIsAtLeast(PrecisionLevel requiredLevel) {
private boolean currentVerbosityLevelIsAtLeast(VerbosityLevel requiredLevel) {
return requiredLevel.compareTo(precision) <= 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
package com.datastax.driver.opentelemetry;

import com.datastax.driver.core.tracing.NoopTracingInfoFactory;
import com.datastax.driver.core.tracing.PrecisionLevel;
import com.datastax.driver.core.tracing.TracingInfo;
import com.datastax.driver.core.tracing.TracingInfoFactory;
import com.datastax.driver.core.tracing.VerbosityLevel;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;

public class OpenTelemetryTracingInfoFactory implements TracingInfoFactory {
private final Tracer tracer;
private final PrecisionLevel precision;
private final VerbosityLevel precision;

public OpenTelemetryTracingInfoFactory(final Tracer tracer) {
this(tracer, PrecisionLevel.NORMAL);
this(tracer, VerbosityLevel.NORMAL);
}

public OpenTelemetryTracingInfoFactory(final Tracer tracer, final PrecisionLevel precision) {
public OpenTelemetryTracingInfoFactory(final Tracer tracer, final VerbosityLevel precision) {
this.tracer = tracer;
this.precision = precision;
}
Expand All @@ -48,7 +48,7 @@ public TracingInfo buildTracingInfo(TracingInfo parent) {
if (parent instanceof OpenTelemetryTracingInfo) {
final OpenTelemetryTracingInfo castedParent = (OpenTelemetryTracingInfo) parent;
return new OpenTelemetryTracingInfo(
castedParent.getTracer(), castedParent.getContext(), castedParent.getPrecision());
castedParent.getTracer(), castedParent.getContext(), castedParent.getVerbosity());
}

return new NoopTracingInfoFactory().buildTracingInfo();
Expand Down
Loading

0 comments on commit 53cdcaa

Please sign in to comment.