Skip to content

Commit

Permalink
handle noop
Browse files Browse the repository at this point in the history
  • Loading branch information
mattspataro committed Nov 18, 2022
1 parent 4c95521 commit 9529a74
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions opentracing-shim/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ dependencies {

api("io.opentracing:opentracing-api")
implementation(project(":semconv"))
implementation("io.opentracing:opentracing-noop:0.33.0")

annotationProcessor("com.google.auto.value:auto-value")

testImplementation(project(":sdk:testing"))
}
repositories {
mavenCentral()
}

tasks {
withType(Test::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer.SpanBuilder;
import io.opentracing.noop.NoopSpan;
import io.opentracing.tag.Tag;
import io.opentracing.tag.Tags;
import java.util.ArrayList;
Expand Down Expand Up @@ -63,11 +64,9 @@ public SpanBuilderShim(TelemetryInfo telemetryInfo, String spanName) {

@Override
public SpanBuilder asChildOf(Span parent) {
if (parent == null) {
if (parent == null || parent instanceof NoopSpan) {
return this;
}

// TODO - Verify we handle a no-op Span
SpanShim spanShim = ShimUtil.getSpanShim(parent);
return addReference(References.CHILD_OF, spanShim.context());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanId;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
Expand All @@ -24,6 +25,7 @@
import io.opentracing.References;
import java.math.BigInteger;
import java.util.List;
import io.opentracing.noop.NoopSpan;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -59,6 +61,21 @@ void parent_single() {
}
}

@Test
void noop_parent_span() {
SpanShim childSpan =
(SpanShim)
new SpanBuilderShim(telemetryInfo, SPAN_NAME)
.asChildOf(NoopSpan.INSTANCE)
.start();
try {
SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData();
assertThat(spanData.getParentSpanId()).isEqualTo(SpanId.getInvalid());
} finally {
childSpan.finish();
}
}

@Test
void parent_multipleFollowsFrom() {
SpanShim parentSpan1 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start();
Expand Down

0 comments on commit 9529a74

Please sign in to comment.