@Override void flush(Span span) { // In the RPC span model, the client owns the timestamp and duration of the span. If we // were propagated an id, we can assume that we shouldn't report timestamp or duration, // rather let the client do that. Worst case we were propagated an unreported ID and // Zipkin backfills timestamp and duration. synchronized (span) { if (span.isShared()) { for (int i = 0, length = span.getAnnotations().size(); i < length; i++) { if (span.getAnnotations().get(i).value.equals("sr")) { span.setTimestamp(null); break; } } } } List<zipkin2.Span> toReport = V1SpanConverter.create().convert(toZipkin(span)); for (int i = 0, length = toReport.size(); i < length; i++) { reporter().report(toReport.get(i)); } } }
public Object getFieldValue(_Fields field) { switch (field) { case TRACE_ID: return Long.valueOf(getTrace_id()); case NAME: return getName(); case ID: return Long.valueOf(getId()); case PARENT_ID: return Long.valueOf(getParent_id()); case ANNOTATIONS: return getAnnotations(); case BINARY_ANNOTATIONS: return getBinary_annotations(); case DEBUG: return Boolean.valueOf(isDebug()); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case TRACE_ID: return Long.valueOf(getTrace_id()); case NAME: return getName(); case ID: return Long.valueOf(getId()); case PARENT_ID: return Long.valueOf(getParent_id()); case ANNOTATIONS: return getAnnotations(); case BINARY_ANNOTATIONS: return getBinary_annotations(); case DEBUG: return Boolean.valueOf(isDebug()); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case TRACE_ID: return Long.valueOf(getTrace_id()); case NAME: return getName(); case ID: return Long.valueOf(getId()); case PARENT_ID: return Long.valueOf(getParent_id()); case ANNOTATIONS: return getAnnotations(); case BINARY_ANNOTATIONS: return getBinary_annotations(); case DEBUG: return Boolean.valueOf(isDebug()); } throw new IllegalStateException(); }
private void assertSpansAreEquivalent(Span s, com.twitter.zipkin.gen.Span zs) { assertTrue("zipkin doesn't support multiple parents to a single span.", s.getParents().length <= 1); if (s.getParents().length == 1) { assertEquals(s.getParents()[0].getLow(), zs.getParent_id()); } assertEquals(s.getSpanId().getLow(), zs.getId()); Assert.assertNotNull(zs.getAnnotations()); if (ROOT_SPAN_DESC.equals(zs.getName())) { assertEquals(5, zs.getAnnotations().size());// two start, two stop + one timeline annotation assertEquals(1, zs.getBinary_annotations().size()); } else { assertEquals(4, zs.getAnnotations().size()); } } }
for (com.twitter.zipkin.gen.Annotation annotation : zs.getAnnotations()) {
public static zipkin2.v1.V1Span toZipkin(Span span) { zipkin2.v1.V1Span.Builder result = zipkin2.v1.V1Span.newBuilder(); result.traceId(span.getTrace_id()); result.traceIdHigh(span.getTrace_id_high()); result.id(span.getId()); result.parentId(span.getParent_id() != null ? span.getParent_id() : 0L); result.name(span.getName()); result.timestamp(span.getTimestamp() != null ? span.getTimestamp() : 0L); result.duration(span.getDuration() != null ? span.getDuration() : 0L); result.debug(span.isDebug()); for (Annotation a : span.getAnnotations()) { result.addAnnotation(a.timestamp, a.value, a.host != null ? a.host.toV2() : null); } for (BinaryAnnotation a : span.getBinary_annotations()) { zipkin2.Endpoint endpoint = a.host != null ? a.host.toV2() : null; if (a.type == AnnotationType.STRING) { result.addBinaryAnnotation(a.key, new String(a.value, UTF_8), endpoint); } else if (a.type == AnnotationType.BOOL && endpoint != null) { result.addBinaryAnnotation(a.key, endpoint); } } return result.build(); }
@Test public void testHTraceDefaultPort() throws IOException { MilliSpan ms = new MilliSpan.Builder().description("test"). parents(new SpanId[] { new SpanId(2L, 2L) }). spanId(new SpanId(2L, 3L)). tracerId("hmaster"). begin(System.currentTimeMillis()). build(); com.twitter.zipkin.gen.Span zs = new HTraceToZipkinConverter(12345, (short) -1).convert(ms); for (com.twitter.zipkin.gen.Annotation annotation:zs.getAnnotations()) { assertEquals((short)60000, annotation.getHost().getPort()); } // make sure it's all lower cased ms = new MilliSpan.Builder().description("test"). parents(new SpanId[] {new SpanId(2, 2)}). spanId(new SpanId(2, 3)). tracerId("HregIonServer"). begin(System.currentTimeMillis()). build(); zs = new HTraceToZipkinConverter(12345, (short) -1).convert(ms); for (com.twitter.zipkin.gen.Annotation annotation:zs.getAnnotations()) { assertEquals((short)60020, annotation.getHost().getPort()); } }
private static zipkin.Span from(Span in) { zipkin.Span.Builder result = new zipkin.Span.Builder(); result.traceId(in.getTrace_id()); result.id(in.getId()); result.parentId(in.getParent_id()); result.name(in.getName()); result.timestamp(in.getTimestamp()); result.duration(in.getDuration()); result.debug(in.isDebug()); for (Annotation a : in.getAnnotations()) { result.addAnnotation(zipkin.Annotation.create(a.timestamp, a.value, from(a.host))); } for (BinaryAnnotation a : in.getBinary_annotations()) { result.addBinaryAnnotation(new zipkin.BinaryAnnotation.Builder() .key(a.key) .value(a.value) .type(Type.fromValue(a.type.getValue())) .endpoint(from(a.host)) .build()); } return result.build(); }