Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Do not log null spancontext references (#487)
Browse files Browse the repository at this point in the history
* Fix issue where warning message is generated each time a null reference is passed

Signed-off-by: Gary Brown <gary@brownuk.com>

* Add test for unexpected span context

Signed-off-by: Gary Brown <gary@brownuk.com>

* Move test to span tests

Signed-off-by: Gary Brown <gary@brownuk.com>

* Moved testAsChildOfAcceptNull to span test

Signed-off-by: Gary Brown <gary@brownuk.com>
  • Loading branch information
objectiser authored and pavolloffay committed Jul 12, 2018
1 parent f3f6fdd commit b9e0282
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ public JaegerTracer.SpanBuilder asChildOf(Span parent) {

@Override
public JaegerTracer.SpanBuilder addReference(String referenceType, SpanContext reference) {
if (reference == null) {
return this;
}
if (!(reference instanceof JaegerSpanContext)) {
log.warn("Expected to have a JaegerSpanContext but got " + referenceType.getClass().getName());
log.warn("Expected to have a JaegerSpanContext but got " + reference.getClass().getName());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -30,7 +31,10 @@
import io.jaegertracing.internal.samplers.ConstSampler;
import io.jaegertracing.spi.BaggageRestrictionManager;
import io.opentracing.References;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.log.Fields;
import io.opentracing.noop.NoopSpan;
import io.opentracing.tag.Tags;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -451,4 +455,34 @@ public void testSpanNotSampled() {
.finish();
assertEquals(0, reporter.getSpans().size());
}

@Test
public void testAsChildOfIgnoreUnexpectedContextImpl() {
JaegerTracer tracer = new JaegerTracer.Builder("foo")
.withReporter(reporter)
.withSampler(new ConstSampler(true))
.build();
JaegerSpan jaegerSpan = tracer.buildSpan("foo")
.asChildOf(NoopSpan.INSTANCE.context()).start();
jaegerSpan.finish();
assertTrue(jaegerSpan.getReferences().isEmpty());
}

@Test
public void testAsChildOfAcceptNull() {
JaegerTracer tracer = new JaegerTracer.Builder("foo")
.withReporter(reporter)
.withSampler(new ConstSampler(true))
.build();

JaegerSpan jaegerSpan = tracer.buildSpan("foo")
.asChildOf((Span) null).start();
jaegerSpan.finish();
assertTrue(jaegerSpan.getReferences().isEmpty());

jaegerSpan = tracer.buildSpan("foo")
.asChildOf((SpanContext) null).start();
jaegerSpan.finish();
assertTrue(jaegerSpan.getReferences().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.jaegertracing.spi.Sampler;
import io.opentracing.ScopeManager;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.tag.Tags;
Expand Down Expand Up @@ -163,22 +162,6 @@ public void testClose() {
verify(sampler).close();
}

@Test
public void testAsChildOfAcceptNull() {
tracer = new JaegerTracer.Builder("foo")
.withReporter(new InMemoryReporter())
.withSampler(new ConstSampler(true))
.build();

JaegerSpan jaegerSpan = tracer.buildSpan("foo").asChildOf((Span) null).start();
jaegerSpan.finish();
assertTrue(jaegerSpan.getReferences().isEmpty());

jaegerSpan = tracer.buildSpan("foo").asChildOf((SpanContext) null).start();
jaegerSpan.finish();
assertTrue(jaegerSpan.getReferences().isEmpty());
}

@Test
public void testActiveSpan() {
JaegerSpan mockSpan = Mockito.mock(JaegerSpan.class);
Expand Down

0 comments on commit b9e0282

Please sign in to comment.