use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class V1SpanWriter method write.
@Override
public void write(V1Span value, WriteBuffer b) {
b.writeAscii("{\"traceId\":\"");
if (value.traceIdHigh() != 0L)
b.writeLongHex(value.traceIdHigh());
b.writeLongHex(value.traceId());
b.writeByte('"');
if (value.parentId() != 0L) {
b.writeAscii(",\"parentId\":\"");
b.writeLongHex(value.parentId());
b.writeByte('"');
}
b.writeAscii(",\"id\":\"");
b.writeLongHex(value.id());
b.writeByte('"');
b.writeAscii(",\"name\":\"");
if (value.name() != null)
b.writeUtf8(jsonEscape(value.name()));
b.writeByte('"');
if (value.timestamp() != 0L) {
b.writeAscii(",\"timestamp\":");
b.writeAscii(value.timestamp());
}
if (value.duration() != 0L) {
b.writeAscii(",\"duration\":");
b.writeAscii(value.duration());
}
int annotationCount = value.annotations().size();
Endpoint lastEndpoint = null;
byte[] lastEndpointBytes = null;
if (annotationCount > 0) {
b.writeAscii(",\"annotations\":[");
for (int i = 0; i < annotationCount; ) {
V1Annotation a = value.annotations().get(i++);
Endpoint endpoint = a.endpoint();
byte[] endpointBytes;
if (endpoint == null) {
endpointBytes = null;
} else if (endpoint.equals(lastEndpoint)) {
endpointBytes = lastEndpointBytes;
} else {
lastEndpoint = endpoint;
endpointBytes = lastEndpointBytes = legacyEndpointBytes(endpoint);
}
writeAnnotation(a.timestamp(), a.value(), endpointBytes, b);
if (i < annotationCount)
b.writeByte(',');
}
b.writeByte(']');
}
int binaryAnnotationCount = value.binaryAnnotations().size();
if (binaryAnnotationCount > 0) {
b.writeAscii(",\"binaryAnnotations\":[");
for (int i = 0; i < binaryAnnotationCount; ) {
V1BinaryAnnotation a = value.binaryAnnotations().get(i++);
Endpoint endpoint = a.endpoint();
byte[] endpointBytes;
if (endpoint == null) {
endpointBytes = null;
} else if (endpoint.equals(lastEndpoint)) {
endpointBytes = lastEndpointBytes;
} else {
lastEndpoint = endpoint;
endpointBytes = lastEndpointBytes = legacyEndpointBytes(endpoint);
}
if (a.stringValue() != null) {
writeBinaryAnnotation(a.key(), a.stringValue(), endpointBytes, b);
} else {
b.writeAscii("{\"key\":\"");
b.writeAscii(a.key());
b.writeAscii("\",\"value\":true,\"endpoint\":");
b.write(endpointBytes);
b.writeByte('}');
}
if (i < binaryAnnotationCount)
b.writeByte(',');
}
b.writeByte(']');
}
if (Boolean.TRUE.equals(value.debug())) {
b.writeAscii(",\"debug\":true");
}
b.writeByte('}');
}
use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class SpanConverterTest method server_shared_v1_no_timestamp_duration.
@Test
public void server_shared_v1_no_timestamp_duration() {
Span v2 = Span.newBuilder().traceId("1").parentId('2').id("3").name("get").kind(Kind.SERVER).shared(true).localEndpoint(BACKEND).timestamp(1472470996199000L).duration(207000L).build();
V1Span v1 = V1Span.newBuilder().traceId("1").parentId('2').id("3").name("get").addAnnotation(1472470996199000L, "sr", BACKEND).addAnnotation(1472470996406000L, "ss", BACKEND).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 SpanConverterTest method parsesSharedFlagFromRPCSpan.
/**
* This emulates a situation in mysql where the row representing a span has the client's timestamp
*/
@Test
public void parsesSharedFlagFromRPCSpan() {
V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("get").timestamp(10).addAnnotation(20, "sr", BACKEND).addAnnotation(30, "ss", BACKEND).build();
Span v2 = Span.newBuilder().traceId("1").parentId("2").id("3").name("get").kind(Kind.SERVER).shared(true).localEndpoint(BACKEND).timestamp(20).duration(10L).build();
assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
use of zipkin2.v1.V1Span in project zipkin by openzipkin.
the class SpanConverterTest method client_unfinished.
@Test
public void client_unfinished() {
Span v2 = Span.newBuilder().traceId("1").parentId("2").id("3").name("get").kind(Kind.CLIENT).localEndpoint(FRONTEND).timestamp(1472470996199000L).addAnnotation(1472470996238000L, "ws").build();
V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("get").timestamp(1472470996199000L).addAnnotation(1472470996199000L, "cs", FRONTEND).addAnnotation(1472470996238000L, "ws", FRONTEND).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 SpanConverterTest method client.
@Test
public void client() {
Span v2 = Span.newBuilder().traceId("1").parentId("2").id("3").name("get").kind(Kind.CLIENT).localEndpoint(FRONTEND).remoteEndpoint(BACKEND).timestamp(1472470996199000L).duration(207000L).addAnnotation(1472470996238000L, "ws").addAnnotation(1472470996403000L, "wr").putTag("http.path", "/api").putTag("clnt/finagle.version", "6.45.0").build();
V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("get").timestamp(1472470996199000L).duration(207000L).addAnnotation(1472470996199000L, "cs", FRONTEND).addAnnotation(1472470996238000L, "ws", // ts order retained
FRONTEND).addAnnotation(1472470996403000L, "wr", FRONTEND).addAnnotation(1472470996406000L, "cr", FRONTEND).addBinaryAnnotation("http.path", "/api", FRONTEND).addBinaryAnnotation("clnt/finagle.version", "6.45.0", FRONTEND).addBinaryAnnotation("sa", BACKEND).build();
assertThat(v2SpanConverter.convert(v2)).usingRecursiveComparison().isEqualTo(v1);
assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
Aggregations