use of com.megaease.easeagent.report.trace.ReportSpanBuilder in project easeagent by megaease.
the class ConvertSpanReporter method convert.
static ReportSpan convert(MutableSpan span) {
ReportSpanBuilder result = ReportSpanBuilder.newBuilder().traceId(span.traceId()).parentId(span.parentId()).id(span.id()).name(span.name());
long start = span.startTimestamp();
long finish = span.finishTimestamp();
result.timestamp(start);
if (start != 0 && finish != 0L) {
result.duration(Math.max(finish - start, 1));
}
// use ordinal comparison to defend against version skew
Kind kind = span.kind();
if (kind != null) {
result.kind(BRAVE_TO_ZIPKIN_KIND.get(kind));
}
String localServiceName = span.localServiceName();
String localIp = span.localIp();
if (localServiceName != null || localIp != null) {
zipkin2.Endpoint e = Endpoint.newBuilder().serviceName(localServiceName).ip(localIp).port(span.localPort()).build();
result.localEndpoint(ReportSpanBuilder.endpoint(e));
}
String remoteServiceName = span.remoteServiceName();
String remoteIp = span.remoteIp();
if (remoteServiceName != null || remoteIp != null) {
zipkin2.Endpoint e = Endpoint.newBuilder().serviceName(remoteServiceName).ip(remoteIp).port(span.remotePort()).build();
result.remoteEndpoint(ReportSpanBuilder.endpoint(e));
}
span.forEachTag(Consumer.INSTANCE, result);
span.forEachAnnotation(Consumer.INSTANCE, result);
if (span.shared())
result.shared(true);
if (span.debug())
result.debug(true);
return result.build();
}
Aggregations