// VisibleForTesting static zipkin.Span convert(Span span, Host host) { Builder zipkinSpan = zipkin.Span.builder(); Endpoint ep = Endpoint.create(host.getServiceName(), host.getIpv4(), host.getPort().shortValue()); // A zipkin span without any annotations cannot be queried, add special "lc" to // avoid that. if (notClientOrServer(span)) { ensureLocalComponent(span, zipkinSpan, ep); } ZipkinMessageListener.addZipkinAnnotations(zipkinSpan, span, ep); ZipkinMessageListener.addZipkinBinaryAnnotations(zipkinSpan, span, ep); if (hasClientSend(span)) { ensureServerAddr(span, zipkinSpan, ep); } zipkinSpan.timestamp(span.getBegin() * 1000); zipkinSpan.duration(span.getAccumulatedMillis() * 1000); zipkinSpan.traceId(span.getTraceId()); if (span.getParents().size() > 0) { if (span.getParents().size() > 1) { log.debug( "zipkin doesn't support spans with multiple parents. Omitting " + "other parents for " + span); } zipkinSpan.parentId(span.getParents().get(0)); } zipkinSpan.id(span.getSpanId()); if (StringUtils.hasText(span.getName())) { zipkinSpan.name(span.getName()); } return zipkinSpan.build(); }
private static void ensureLocalComponent(Span span, Builder zipkinSpan, Endpoint ep) { if (span.tags().containsKey(Constants.LOCAL_COMPONENT)) { return; } String processId = span.getProcessId() != null ? span.getProcessId().toLowerCase() : ZipkinMessageListener.UNKNOWN_PROCESS_ID; zipkinSpan.addBinaryAnnotation( BinaryAnnotation.create(Constants.LOCAL_COMPONENT, processId, ep)); }