Search in sources :

Example 6 with BinaryAnnotation

use of com.twitter.zipkin.thriftjava.BinaryAnnotation 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);
        }
    }
}
Also used : InMemoryReporter(com.uber.jaeger.reporters.InMemoryReporter) Tracer(com.uber.jaeger.Tracer) Span(com.uber.jaeger.Span) BinaryAnnotation(com.twitter.zipkin.thriftjava.BinaryAnnotation) ConstSampler(com.uber.jaeger.samplers.ConstSampler) HashMap(java.util.HashMap) Map(java.util.Map) TextMap(io.opentracing.propagation.TextMap) TreeMap(java.util.TreeMap) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

BinaryAnnotation (com.twitter.zipkin.thriftjava.BinaryAnnotation)6 Map (java.util.Map)4 HashMap (java.util.HashMap)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)2 TextMap (io.opentracing.propagation.TextMap)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 Span (com.uber.jaeger.Span)1 Tracer (com.uber.jaeger.Tracer)1 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)1 ConstSampler (com.uber.jaeger.samplers.ConstSampler)1 JaegerSpan (io.jaegertracing.internal.JaegerSpan)1 JaegerTracer (io.jaegertracing.internal.JaegerTracer)1 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)1 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)1