private static void ensureServerAddr(Span span, zipkin.Span.Builder zipkinSpan, Endpoint ep) { String serviceName = span.tags().containsKey(Span.SPAN_PEER_SERVICE_TAG_NAME) ? span.tags().get(Span.SPAN_PEER_SERVICE_TAG_NAME) : ep.serviceName; Endpoint endpoint = ep.port == null ? Endpoint.create(serviceName, ep.ipv4) : Endpoint.create(serviceName, ep.ipv4, ep.port); zipkinSpan.addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, endpoint)); }
// 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(); }