.spanId(spanId) .sampled(debug ? Boolean.TRUE : sampled(flags)) .debug(debug) .build() );
public static Span fromZipkin(zipkin2.Span v2) { V1Span in = V2SpanConverter.create().convert(v2); Span result = newSpan(SpanId.builder() .traceIdHigh(in.traceIdHigh()) .traceId(in.traceId()) .spanId(in.id()) .parentId(in.parentId() != 0L ? in.parentId() : null) .debug(in.debug() != null ? in.debug() : false).build() ); result.setName(in.name()); result.setTimestamp(in.timestamp() != 0L ? in.timestamp() : null); result.setDuration(in.duration() != 0L ? in.duration() : null); for (zipkin2.v1.V1Annotation a : in.annotations()) { result.addToAnnotations(Annotation.create( a.timestamp(), a.value(), to(a.endpoint()))); } for (zipkin2.v1.V1BinaryAnnotation a : in.binaryAnnotations()) { if (a.type() != 0 && a.type() != 6) continue;; result.addToBinary_annotations(BinaryAnnotation.create( a.key(), a.type() == 0 ? new byte[]{1}: a.stringValue().getBytes(UTF_8), a.type() == 0 ? AnnotationType.BOOL : AnnotationType.STRING, to(a.endpoint()))); } return result; }
@Override public SpanId context(Span span) { if (span.context != null) return span.context; // If we got here, some implementation of state passed a deprecated span // If no ids were set, it is junk, so return null if (span.trace_id == 0 && span.parent_id == null && span.id == 0) return null; // Attempt to backfill the span context synchronized (span) { if (span.context != null) return span.context; span.context = SpanId.builder() .traceIdHigh(span.getTrace_id_high()) .traceId(span.getTrace_id()) .parentId(span.getParent_id()) .spanId(span.getId()) .debug(span.debug != null ? span.debug : false) .build(); } return span.context; } };
static SpanId toSpanId(TraceContext context) { return SpanId.builder() .traceIdHigh(context.traceIdHigh()) .traceId(context.traceId()) .parentId(context.parentId()) .spanId(context.spanId()) .debug(context.debug()) .sampled(context.sampled()).build(); } }