/** Returns a json representation of this endpoint */ @Override public String toString() { // expensive, but only used when people are debugging and cheaper than maintaining json codec Span fake = Span.newBuilder().traceId(0, 1).id(1).localEndpoint(toV2()).build(); String jsonSpan = new String(SpanBytesEncoder.JSON_V2.encode(fake), UTF_8); return jsonSpan.substring(70, jsonSpan.length() - 1); }
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(); }