JaegerThriftSpanConverter { public static io.jaegertracing.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) { JaegerSpanContext context = jaegerSpan.context(); boolean oneChildOfParent = jaegerSpan.getReferences().size() == 1 && References.CHILD_OF.equals(jaegerSpan.getReferences().get(0).getType()); List<SpanRef> references = oneChildOfParent ? Collections.<SpanRef>emptyList() : buildReferences(jaegerSpan.getReferences()); return new io.jaegertracing.thriftjava.Span( context.getTraceIdLow(), context.getTraceIdHigh(), context.getSpanId(), oneChildOfParent ? context.getParentId() : 0, jaegerSpan.getOperationName(), context.getFlags(), jaegerSpan.getStart(), jaegerSpan.getDuration() ) .setReferences(references) .setTags(buildTags(jaegerSpan.getTags())) .setLogs(buildLogs(jaegerSpan.getLogs())); } private  JaegerThriftSpanConverter(); static io.jaegertracing.thriftjava.Span convertSpan(JaegerSpan jaegerSpan); static List<Tag> buildTags(Map<String, ?> tags);  }
@Test public void testConvertSpan() { Map<String, Object> fields = new HashMap<String, Object>(); fields.put("k", "v"); JaegerSpan span = tracer.buildSpan("operation-name").start(); span = span.log(1, fields); span = span.setBaggageItem("foo", "bar"); io.jaegertracing.thriftjava.Span thriftSpan = JaegerThriftSpanConverter.convertSpan(span); assertEquals("operation-name", thriftSpan.getOperationName()); assertEquals(2, thriftSpan.getLogs().size()); Log thriftLog = thriftSpan.getLogs().get(0); assertEquals(1, thriftLog.getTimestamp()); assertEquals(1, thriftLog.getFields().size()); Tag thriftTag = thriftLog.getFields().get(0); assertEquals("k", thriftTag.getKey()); assertEquals("v", thriftTag.getVStr()); thriftLog = thriftSpan.getLogs().get(1); assertEquals(3, thriftLog.getFields().size()); thriftTag = thriftLog.getFields().get(0); assertEquals("event", thriftTag.getKey()); assertEquals("baggage", thriftTag.getVStr()); thriftTag = thriftLog.getFields().get(1); assertEquals("value", thriftTag.getKey()); assertEquals("bar", thriftTag.getVStr()); thriftTag = thriftLog.getFields().get(2); assertEquals("key", thriftTag.getKey()); assertEquals("foo", thriftTag.getVStr()); }
@Test public void testConvertSpanWith128BitTraceId() { JaegerSpan span = tracer128.buildSpan("operation-name").start(); io.jaegertracing.thriftjava.Span thriftSpan = JaegerThriftSpanConverter.convertSpan(span); assertEquals(span.context().getTraceIdLow(), thriftSpan.getTraceIdLow()); assertEquals(span.context().getTraceIdHigh(), thriftSpan.getTraceIdHigh()); }
@Test public void testConvertSpanOneReferenceChildOf() { JaegerSpan parent = tracer.buildSpan("foo").start(); JaegerSpan child = tracer.buildSpan("foo") .asChildOf(parent) .start(); io.jaegertracing.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(child); assertEquals(child.context().getParentId(), span.getParentSpanId()); assertEquals(0, span.getReferences().size()); }
@Test public void testConvertSpanTwoReferencesChildOf() { JaegerSpan parent = tracer.buildSpan("foo").start(); JaegerSpan parent2 = tracer.buildSpan("foo").start(); JaegerSpan child = tracer.buildSpan("foo") .asChildOf(parent) .asChildOf(parent2) .start(); io.jaegertracing.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(child); assertEquals(0, span.getParentSpanId()); assertEquals(2, span.getReferences().size()); assertEquals(buildReference(parent.context(), References.CHILD_OF),span.getReferences().get(0)); assertEquals(buildReference(parent2.context(), References.CHILD_OF),span.getReferences().get(1)); }
@Test public void testConvertSpanMixedReferences() { JaegerSpan parent = tracer.buildSpan("foo").start(); JaegerSpan parent2 = tracer.buildSpan("foo").start(); JaegerSpan child = tracer.buildSpan("foo") .addReference(References.FOLLOWS_FROM, parent.context()) .asChildOf(parent2) .start(); io.jaegertracing.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(child); assertEquals(0, span.getParentSpanId()); assertEquals(2, span.getReferences().size()); assertEquals(buildReference(parent.context(), References.FOLLOWS_FROM),span.getReferences().get(0)); assertEquals(buildReference(parent2.context(), References.CHILD_OF),span.getReferences().get(1)); }