@Test @UseDataProvider("dataProviderTracerTags") public void testTracerTags(SpanType spanType, Map<String, String> expectedTags) { InMemoryReporter spanReporter = new InMemoryReporter(); JaegerTracer tracer = new JaegerTracer.Builder("x") .withReporter(spanReporter) .withSampler(new ConstSampler(true)) .withZipkinSharedRpcSpan() .withTag("tag.str", "y") .withTag("tag.bool", true) .withTag("tag.num", 1) .build(); JaegerSpan span = tracer.buildSpan("root").start(); if (spanType == SpanType.CHILD) { span = tracer.buildSpan("child").asChildOf(span).start(); } else if (spanType == SpanType.RPC_SERVER) { span = tracer.buildSpan("rpc-server") .asChildOf(span) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .start(); } 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); } } }
public static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) { JaegerTracer tracer = jaegerSpan.getTracer(); Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName()); JaegerSpanContext context = jaegerSpan.context(); return new com.twitter.zipkin.thriftjava.Span( context.getTraceIdLow(), jaegerSpan.getOperationName(), context.getSpanId(), buildAnnotations(jaegerSpan, host), buildBinaryAnnotations(jaegerSpan, host)) .setParent_id(context.getParentId()) .setTrace_id_high(context.getTraceIdHigh()) .setDebug(context.isDebug()) .setTimestamp(jaegerSpan.getStart()) .setDuration(jaegerSpan.getDuration()); }
ThriftSpanConverter { public static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) { JaegerTracer tracer = jaegerSpan.getTracer(); Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName()); JaegerSpanContext context = jaegerSpan.context(); return new com.twitter.zipkin.thriftjava.Span( context.getTraceIdLow(), jaegerSpan.getOperationName(), context.getSpanId(), buildAnnotations(jaegerSpan, host), buildBinaryAnnotations(jaegerSpan, host)) .setParent_id(context.getParentId()) .setTrace_id_high(context.getTraceIdHigh()) .setDebug(context.isDebug()) .setTimestamp(jaegerSpan.getStart()) .setDuration(jaegerSpan.getDuration()); } }
ThriftSpanConverter { public static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) { JaegerTracer tracer = jaegerSpan.getTracer(); Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName()); JaegerSpanContext context = jaegerSpan.context(); return new com.twitter.zipkin.thriftjava.Span( context.getTraceIdLow(), jaegerSpan.getOperationName(), context.getSpanId(), buildAnnotations(jaegerSpan, host), buildBinaryAnnotations(jaegerSpan, host)) .setParent_id(context.getParentId()) .setTrace_id_high(context.getTraceIdHigh()) .setDebug(context.isDebug()) .setTimestamp(jaegerSpan.getStart()) .setDuration(jaegerSpan.getDuration()); }  }
ThriftSpanConverter { public static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) { JaegerTracer tracer = jaegerSpan.getTracer(); Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName()); JaegerSpanContext context = jaegerSpan.context(); return new com.twitter.zipkin.thriftjava.Span( context.getTraceIdLow(), jaegerSpan.getOperationName(), context.getSpanId(), buildAnnotations(jaegerSpan, host), buildBinaryAnnotations(jaegerSpan, host)) .setParent_id(context.getParentId()) .setTrace_id_high(context.getTraceIdHigh()) .setDebug(context.isDebug()) .setTimestamp(jaegerSpan.getStart()) .setDuration(jaegerSpan.getDuration()); }  static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan); static Endpoint extractPeerEndpoint(Map<String, Object> tags); }
ThriftSpanConverter { public static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) { JaegerTracer tracer = jaegerSpan.getTracer(); Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName()); JaegerSpanContext context = jaegerSpan.context(); return new com.twitter.zipkin.thriftjava.Span( context.getTraceIdLow(), jaegerSpan.getOperationName(), context.getSpanId(), buildAnnotations(jaegerSpan, host), buildBinaryAnnotations(jaegerSpan, host)) .setParent_id(context.getParentId()) .setTrace_id_high(context.getTraceIdHigh()) .setDebug(context.isDebug()) .setTimestamp(jaegerSpan.getStart()) .setDuration(jaegerSpan.getDuration()); }  static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan); static Endpoint extractPeerEndpoint(Map<String, Object> tags);  }