// 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();
  }
  public static Message<?> addSpanHeaders(TraceKeys traceKeys, Message<?> message, Span span) {
    if (span == null) {
      if (!message.getHeaders().containsKey(Span.NOT_SAMPLED_NAME)) {
        return MessageBuilder.fromMessage(message).setHeader(Span.NOT_SAMPLED_NAME, "").build();
      }
      return message;
    }

    Map<String, String> headers = new HashMap<>();
    addHeader(headers, Span.TRACE_ID_NAME, Span.toHex(span.getTraceId()));
    addHeader(headers, Span.SPAN_ID_NAME, Span.toHex(span.getSpanId()));

    if (span.isExportable()) {
      addAnnotations(traceKeys, message, span);
      Long parentId = getFirst(span.getParents());
      if (parentId != null) {
        addHeader(headers, Span.PARENT_ID_NAME, Span.toHex(parentId));
      }
      addHeader(headers, Span.SPAN_NAME_NAME, span.getName());
      addHeader(headers, Span.PROCESS_ID_NAME, span.getProcessId());
    } else {
      addHeader(headers, Span.NOT_SAMPLED_NAME, "");
    }
    return MessageBuilder.fromMessage(message).copyHeaders(headers).build();
  }
 private String getParentId(Span span) {
   return span.getParents() != null && !span.getParents().isEmpty()
       ? span.getParents().get(0)
       : null;
 }