use of zipkin2.internal.WriteBuffer in project zipkin by openzipkin.
the class ThriftEndpointCodec method write.
static void write(Endpoint value, WriteBuffer buffer) {
IPV4.write(buffer);
buffer.write(value.ipv4Bytes() != null ? value.ipv4Bytes() : INT_ZERO);
PORT.write(buffer);
int port = value.portAsInt();
// write short!
buffer.writeByte((port >>> 8L) & 0xff);
buffer.writeByte(port & 0xff);
SERVICE_NAME.write(buffer);
ThriftCodec.writeLengthPrefixed(buffer, value.serviceName() != null ? value.serviceName() : "");
byte[] ipv6 = value.ipv6Bytes();
if (ipv6 != null) {
IPV6.write(buffer);
ThriftCodec.writeInt(buffer, 16);
buffer.write(ipv6);
}
buffer.writeByte(TYPE_STOP);
}
use of zipkin2.internal.WriteBuffer 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.internal.WriteBuffer in project zipkin by openzipkin.
the class V1ThriftSpanWriter method writeBinaryAnnotations.
static void writeBinaryAnnotations(WriteBuffer buffer, V1Span v1Span, byte[] endpointBytes) {
int binaryAnnotationCount = v1Span.binaryAnnotations().size();
ThriftCodec.writeListBegin(buffer, binaryAnnotationCount);
for (int i = 0; i < binaryAnnotationCount; i++) {
V1BinaryAnnotation a = v1Span.binaryAnnotations().get(i);
byte[] ep = a.stringValue() != null ? endpointBytes : legacyEndpointBytes(a.endpoint());
ThriftBinaryAnnotationWriter.write(a.key(), a.stringValue(), ep, buffer);
}
}
use of zipkin2.internal.WriteBuffer in project zipkin by openzipkin.
the class V2SpanWriter method writeEndpoint.
static void writeEndpoint(Endpoint value, WriteBuffer b, boolean writeEmptyServiceName) {
b.writeByte('{');
boolean wroteField = false;
String serviceName = value.serviceName();
if (serviceName == null && writeEmptyServiceName)
serviceName = "";
if (serviceName != null) {
b.writeAscii("\"serviceName\":\"");
b.writeUtf8(jsonEscape(serviceName));
b.writeByte('"');
wroteField = true;
}
if (value.ipv4() != null) {
if (wroteField)
b.writeByte(',');
b.writeAscii("\"ipv4\":\"");
b.writeAscii(value.ipv4());
b.writeByte('"');
wroteField = true;
}
if (value.ipv6() != null) {
if (wroteField)
b.writeByte(',');
b.writeAscii("\"ipv6\":\"");
b.writeAscii(value.ipv6());
b.writeByte('"');
wroteField = true;
}
int port = value.portAsInt();
if (port != 0) {
if (wroteField)
b.writeByte(',');
b.writeAscii("\"port\":");
b.writeAscii(port);
}
b.writeByte('}');
}
use of zipkin2.internal.WriteBuffer in project zipkin by openzipkin.
the class V1JsonSpanWriter method write.
@Override
public void write(Span value, WriteBuffer b) {
V1Span v1Span = converter.convert(value);
v1SpanWriter.write(v1Span, b);
}
Aggregations