use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class SpanConverterTest method consumer_remote.
@Test
public void consumer_remote() {
Span v2 = Span.newBuilder().traceId("1").parentId("2").id("3").name("next-message").kind(Kind.CONSUMER).localEndpoint(BACKEND).remoteEndpoint(kafka).timestamp(1472470996199000L).build();
V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("next-message").timestamp(1472470996199000L).addAnnotation(1472470996199000L, "mr", BACKEND).addBinaryAnnotation("ma", kafka).build();
assertThat(v2SpanConverter.convert(v2)).usingRecursiveComparison().isEqualTo(v1);
assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class V1SpanWriter method sizeInBytes.
@Override
public int sizeInBytes(V1Span value) {
// {"traceId":"xxxxxxxxxxxxxxxx"
int sizeInBytes = 29;
if (value.traceIdHigh() != 0L)
sizeInBytes += 16;
if (value.parentId() != 0L) {
// ,"parentId":"0123456789abcdef"
sizeInBytes += 30;
}
// ,"id":"0123456789abcdef"
sizeInBytes += 24;
// ,"name":""
sizeInBytes += 10;
if (value.name() != null) {
sizeInBytes += jsonEscapedSizeInBytes(value.name());
}
if (value.timestamp() != 0L) {
// ,"timestamp":
sizeInBytes += 13;
sizeInBytes += asciiSizeInBytes(value.timestamp());
}
if (value.duration() != 0L) {
// ,"duration":
sizeInBytes += 12;
sizeInBytes += asciiSizeInBytes(value.duration());
}
int annotationCount = value.annotations().size();
Endpoint lastEndpoint = null;
int lastEndpointSize = 0;
if (annotationCount > 0) {
// ,"annotations":[]
sizeInBytes += 17;
// comma to join elements
if (annotationCount > 1)
sizeInBytes += annotationCount - 1;
for (int i = 0; i < annotationCount; i++) {
V1Annotation a = value.annotations().get(i);
Endpoint endpoint = a.endpoint();
int endpointSize;
if (endpoint == null) {
endpointSize = 0;
} else if (endpoint.equals(lastEndpoint)) {
endpointSize = lastEndpointSize;
} else {
lastEndpoint = endpoint;
endpointSize = lastEndpointSize = endpointSizeInBytes(endpoint, true);
}
sizeInBytes += V2SpanWriter.annotationSizeInBytes(a.timestamp(), a.value(), endpointSize);
}
}
int binaryAnnotationCount = value.binaryAnnotations().size();
if (binaryAnnotationCount > 0) {
// ,"binaryAnnotations":[]
sizeInBytes += 23;
// commas
if (binaryAnnotationCount > 1)
sizeInBytes += binaryAnnotationCount - 1;
for (int i = 0; i < binaryAnnotationCount; ) {
V1BinaryAnnotation a = value.binaryAnnotations().get(i++);
Endpoint endpoint = a.endpoint();
int endpointSize;
if (endpoint == null) {
endpointSize = 0;
} else if (endpoint.equals(lastEndpoint)) {
endpointSize = lastEndpointSize;
} else {
lastEndpoint = endpoint;
endpointSize = lastEndpointSize = endpointSizeInBytes(endpoint, true);
}
if (a.stringValue() != null) {
sizeInBytes += binaryAnnotationSizeInBytes(a.key(), a.stringValue(), endpointSize);
} else {
// {"key":"NN","value":true,"endpoint":}
sizeInBytes += 37;
sizeInBytes += endpointSize;
}
}
}
// ,"debug":true
if (Boolean.TRUE.equals(value.debug()))
sizeInBytes += 13;
// }
return ++sizeInBytes;
}
use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class V1ThriftSpanWriter method writeAnnotations.
static void writeAnnotations(WriteBuffer buffer, V1Span v1Span, byte[] endpointBytes) {
int annotationCount = v1Span.annotations().size();
ThriftCodec.writeListBegin(buffer, annotationCount);
for (int i = 0; i < annotationCount; i++) {
V1Annotation a = v1Span.annotations().get(i);
ThriftAnnotationWriter.write(a.timestamp(), a.value(), endpointBytes, buffer);
}
}
use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class V1ThriftSpanWriter method write.
@Override
public void write(Span value, WriteBuffer buffer) {
V1Span v1Span = converter.convert(value);
byte[] endpointBytes = legacyEndpointBytes(value.localEndpoint());
TRACE_ID.write(buffer);
ThriftCodec.writeLong(buffer, v1Span.traceId());
NAME.write(buffer);
ThriftCodec.writeLengthPrefixed(buffer, value.name() != null ? value.name() : "");
ID.write(buffer);
ThriftCodec.writeLong(buffer, v1Span.id());
if (v1Span.parentId() != 0L) {
PARENT_ID.write(buffer);
ThriftCodec.writeLong(buffer, v1Span.parentId());
}
// we write list thriftFields even when empty to match finagle serialization
ANNOTATIONS.write(buffer);
writeAnnotations(buffer, v1Span, endpointBytes);
BINARY_ANNOTATIONS.write(buffer);
writeBinaryAnnotations(buffer, v1Span, endpointBytes);
if (v1Span.debug() != null) {
DEBUG.write(buffer);
buffer.writeByte(v1Span.debug() ? 1 : 0);
}
if (v1Span.timestamp() != 0L) {
TIMESTAMP.write(buffer);
ThriftCodec.writeLong(buffer, v1Span.timestamp());
}
if (v1Span.duration() != 0L) {
DURATION.write(buffer);
ThriftCodec.writeLong(buffer, v1Span.duration());
}
if (v1Span.traceIdHigh() != 0L) {
TRACE_ID_HIGH.write(buffer);
ThriftCodec.writeLong(buffer, v1Span.traceIdHigh());
}
buffer.writeByte(TYPE_STOP);
}
use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class SpanConverterTest method dataMissingEndpointGoesOnFirstSpan.
@Test
public void dataMissingEndpointGoesOnFirstSpan() {
V1Span v1 = V1Span.newBuilder().traceId(1).id(2).name("missing").addAnnotation(1472470996199000L, "foo", FRONTEND).addAnnotation(1472470996238000L, "bar", FRONTEND).addAnnotation(1472470996250000L, "baz", BACKEND).addAnnotation(1472470996350000L, "qux", BACKEND).addAnnotation(1472470996403000L, "missing", null).addBinaryAnnotation("foo", "bar", FRONTEND).addBinaryAnnotation("baz", "qux", BACKEND).addBinaryAnnotation("missing", "", null).build();
Span.Builder newBuilder = Span.newBuilder().traceId("1").id("2").name("missing");
Span first = newBuilder.clone().localEndpoint(FRONTEND).addAnnotation(1472470996199000L, "foo").addAnnotation(1472470996238000L, "bar").addAnnotation(1472470996403000L, "missing").putTag("foo", "bar").putTag("missing", "").build();
Span second = newBuilder.clone().localEndpoint(BACKEND).addAnnotation(1472470996250000L, "baz").addAnnotation(1472470996350000L, "qux").putTag("baz", "qux").build();
assertThat(v1SpanConverter.convert(v1)).containsExactly(first, second);
}
Aggregations