use of com.uber.jaeger.reporters.InMemoryReporter in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testTracerTags.
@Test
@UseDataProvider("dataProviderTracerTags")
public void testTracerTags(SpanType spanType, Map<String, String> expectedTags) throws Exception {
InMemoryReporter spanReporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("x", spanReporter, new ConstSampler(true)).withZipkinSharedRpcSpan().withTag("tag.str", "y").withTag("tag.bool", true).withTag("tag.num", 1).build();
Span span = (Span) tracer.buildSpan("root").startManual();
if (spanType == SpanType.CHILD) {
span = (Span) tracer.buildSpan("child").asChildOf(span).startManual();
} else if (spanType == SpanType.RPC_SERVER) {
span = (Span) tracer.buildSpan("rpc-server").asChildOf(span).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).startManual();
}
com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
List<BinaryAnnotation> annotations = zipkinSpan.getBinary_annotations();
for (Map.Entry<String, String> entry : expectedTags.entrySet()) {
String key = entry.getKey();
Object expectedValue = entry.getValue();
BinaryAnnotation anno = findBinaryAnnotation(annotations, key);
if (expectedValue.equals(UNDEF)) {
assertNull("Not expecting " + key + " for " + spanType, anno);
} else if (expectedValue.equals(ANY)) {
assertEquals(key, anno.getKey());
} else {
String actualValue = new String(anno.getValue(), StandardCharsets.UTF_8);
assertEquals("Expecting " + key + " for " + spanType, expectedValue, actualValue);
}
}
}
use of com.uber.jaeger.reporters.InMemoryReporter in project jaeger-client-java by jaegertracing.
the class PropagationTest method testIgnoreActiveSpan.
@Test
public void testIgnoreActiveSpan() {
InMemoryReporter reporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("test", reporter, new ConstSampler(true)).build();
try (Scope parent = tracer.buildSpan("parent").startActive(true)) {
tracer.buildSpan("child").ignoreActiveSpan().startActive(true).close();
}
assertEquals(2, reporter.getSpans().size());
Span childSpan = reporter.getSpans().get(0);
Span parentSpan = reporter.getSpans().get(1);
assertTrue(reporter.getSpans().get(0).getReferences().isEmpty());
assertTrue(reporter.getSpans().get(1).getReferences().isEmpty());
assertNotEquals(parentSpan.context().getTraceId(), childSpan.context().getTraceId());
assertEquals(0, childSpan.context().getParentId());
}
use of com.uber.jaeger.reporters.InMemoryReporter in project jaeger-client-java by jaegertracing.
the class PropagationTest method testNoAutoRefWithExistingRefs.
@Test
public void testNoAutoRefWithExistingRefs() {
InMemoryReporter reporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("test", reporter, new ConstSampler(true)).build();
io.opentracing.Span initialSpan = tracer.buildSpan("initial").start();
try (Scope parent = tracer.buildSpan("parent").startActive(true)) {
tracer.buildSpan("child").asChildOf(initialSpan.context()).startActive(true).close();
}
initialSpan.finish();
assertEquals(3, reporter.getSpans().size());
Span childSpan = reporter.getSpans().get(0);
Span parentSpan = reporter.getSpans().get(1);
Span initSpan = reporter.getSpans().get(2);
assertTrue(initSpan.getReferences().isEmpty());
assertTrue(parentSpan.getReferences().isEmpty());
assertEquals(initSpan.context().getTraceId(), childSpan.context().getTraceId());
assertEquals(initSpan.context().getSpanId(), childSpan.context().getParentId());
assertEquals(0, initSpan.context().getParentId());
assertEquals(0, parentSpan.context().getParentId());
}
use of com.uber.jaeger.reporters.InMemoryReporter in project jaeger-client-java by jaegertracing.
the class PropagationTest method testActiveSpanAutoFinishOnClose.
@Test
public void testActiveSpanAutoFinishOnClose() {
InMemoryReporter reporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("test", reporter, new ConstSampler(true)).build();
tracer.buildSpan("parent").startActive(true).close();
assertEquals(1, reporter.getSpans().size());
}
use of com.uber.jaeger.reporters.InMemoryReporter in project jaeger-client-java by jaegertracing.
the class PropagationTest method testCustomScopeManager.
@Test
public void testCustomScopeManager() {
Scope scope = mock(Scope.class);
Tracer tracer = new Tracer.Builder("test", new InMemoryReporter(), new ConstSampler(true)).withScopeManager(new ScopeManager() {
@Override
public Scope activate(io.opentracing.Span span, boolean finishSpanOnClose) {
return scope;
}
@Override
public Scope active() {
return scope;
}
}).build();
assertEquals(scope, tracer.scopeManager().active());
}
Aggregations