Skip to content

Commit

Permalink
handle noop (#4968)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Berg <[email protected]>
  • Loading branch information
mattspataro and jack-berg authored Nov 29, 2022
1 parent ac2ba4a commit 568bdb4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ val DEPENDENCIES = listOf(
"io.jaegertracing:jaeger-client:1.8.1",
"io.opentelemetry.proto:opentelemetry-proto:0.19.0-alpha",
"io.opentracing:opentracing-api:0.33.0",
"io.opentracing:opentracing-noop:0.33.0",
"junit:junit:4.13.2",
"nl.jqno.equalsverifier:equalsverifier:3.11.1",
"org.assertj:assertj-core:3.23.1",
Expand Down
1 change: 1 addition & 0 deletions opentracing-shim/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {

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

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

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 @@ -12,6 +12,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanContext;
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.opentelemetry.sdk.trace.samplers.SamplingResult;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentracing.References;
import io.opentracing.noop.NoopSpan;
import io.opentracing.tag.Tags;
import java.math.BigInteger;
import java.util.List;
Expand Down Expand Up @@ -79,6 +81,19 @@ 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(SpanId.isValid(spanData.getParentSpanId())).isFalse();
} finally {
childSpan.finish();
}
}

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

0 comments on commit 568bdb4

Please sign in to comment.