Search in sources :

Example 6 with WriteBuffer

use of zipkin2.internal.WriteBuffer 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);
    }
}
Also used : Endpoint(zipkin2.Endpoint) V1Annotation(zipkin2.v1.V1Annotation)

Example 7 with WriteBuffer

use of zipkin2.internal.WriteBuffer 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);
}
Also used : V1Span(zipkin2.v1.V1Span)

Example 8 with WriteBuffer

use of zipkin2.internal.WriteBuffer in project zipkin by openzipkin.

the class V1ThriftSpanWriter method writeList.

public int writeList(List<Span> spans, byte[] out, int pos) {
    int lengthOfSpans = spans.size();
    if (lengthOfSpans == 0)
        return 0;
    WriteBuffer result = WriteBuffer.wrap(out, pos);
    ThriftCodec.writeList(this, spans, result);
    return result.pos() - pos;
}
Also used : Endpoint(zipkin2.Endpoint)

Example 9 with WriteBuffer

use of zipkin2.internal.WriteBuffer in project zipkin by openzipkin.

the class V2SpanWriter method write.

@Override
public void write(Span value, WriteBuffer b) {
    b.writeAscii("{\"traceId\":\"");
    b.writeAscii(value.traceId());
    b.writeByte('"');
    if (value.parentId() != null) {
        b.writeAscii(",\"parentId\":\"");
        b.writeAscii(value.parentId());
        b.writeByte('"');
    }
    b.writeAscii(",\"id\":\"");
    b.writeAscii(value.id());
    b.writeByte('"');
    if (value.kind() != null) {
        b.writeAscii(",\"kind\":\"");
        b.writeAscii(value.kind().toString());
        b.writeByte('"');
    }
    if (value.name() != null) {
        b.writeAscii(",\"name\":\"");
        b.writeUtf8(jsonEscape(value.name()));
        b.writeByte('"');
    }
    if (value.timestampAsLong() != 0L) {
        b.writeAscii(",\"timestamp\":");
        b.writeAscii(value.timestampAsLong());
    }
    if (value.durationAsLong() != 0L) {
        b.writeAscii(",\"duration\":");
        b.writeAscii(value.durationAsLong());
    }
    if (value.localEndpoint() != null) {
        b.writeAscii(",\"localEndpoint\":");
        writeEndpoint(value.localEndpoint(), b, false);
    }
    if (value.remoteEndpoint() != null) {
        b.writeAscii(",\"remoteEndpoint\":");
        writeEndpoint(value.remoteEndpoint(), b, false);
    }
    if (!value.annotations().isEmpty()) {
        b.writeAscii(",\"annotations\":");
        b.writeByte('[');
        for (int i = 0, length = value.annotations().size(); i < length; ) {
            Annotation a = value.annotations().get(i++);
            writeAnnotation(a.timestamp(), a.value(), null, b);
            if (i < length)
                b.writeByte(',');
        }
        b.writeByte(']');
    }
    if (!value.tags().isEmpty()) {
        b.writeAscii(",\"tags\":{");
        Iterator<Map.Entry<String, String>> i = value.tags().entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<String, String> entry = i.next();
            b.writeByte('"');
            b.writeUtf8(jsonEscape(entry.getKey()));
            b.writeAscii("\":\"");
            b.writeUtf8(jsonEscape(entry.getValue()));
            b.writeByte('"');
            if (i.hasNext())
                b.writeByte(',');
        }
        b.writeByte('}');
    }
    if (Boolean.TRUE.equals(value.debug())) {
        b.writeAscii(",\"debug\":true");
    }
    if (Boolean.TRUE.equals(value.shared())) {
        b.writeAscii(",\"shared\":true");
    }
    b.writeByte('}');
}
Also used : Map(java.util.Map) Endpoint(zipkin2.Endpoint) Annotation(zipkin2.Annotation)

Example 10 with WriteBuffer

use of zipkin2.internal.WriteBuffer in project zipkin by openzipkin.

the class TestObjects method newTraceId.

public static String newTraceId() {
    byte[] traceId = new byte[32];
    WriteBuffer buffer = WriteBuffer.wrap(traceId);
    buffer.writeLongHex(ThreadLocalRandom.current().nextLong());
    buffer.writeLongHex(ThreadLocalRandom.current().nextLong());
    return new String(traceId, UTF_8);
}
Also used : WriteBuffer(zipkin2.internal.WriteBuffer)

Aggregations

Endpoint (zipkin2.Endpoint)7 V1Annotation (zipkin2.v1.V1Annotation)2 V1BinaryAnnotation (zipkin2.v1.V1BinaryAnnotation)2 V1Span (zipkin2.v1.V1Span)2 Map (java.util.Map)1 Annotation (zipkin2.Annotation)1 WriteBuffer (zipkin2.internal.WriteBuffer)1