Search in sources :

Example 1 with V1BinaryAnnotation

use of zipkin2.v1.V1BinaryAnnotation in project zipkin by openzipkin.

the class V1ThriftSpanWriter method sizeInBytes.

@Override
public int sizeInBytes(Span value) {
    V1Span v1Span = converter.convert(value);
    int endpointSize = value.localEndpoint() != null ? ThriftEndpointCodec.sizeInBytes(value.localEndpoint()) : 0;
    // TRACE_ID
    int sizeInBytes = 3 + 8;
    // TRACE_ID_HIGH
    if (v1Span.traceIdHigh() != 0)
        sizeInBytes += 3 + 8;
    // PARENT_ID
    if (v1Span.parentId() != 0)
        sizeInBytes += 3 + 8;
    // ID
    sizeInBytes += 3 + 8;
    // NAME
    sizeInBytes += 3 + 4;
    if (value.name() != null)
        sizeInBytes += utf8SizeInBytes(value.name());
    // we write list thriftFields even when empty to match finagle serialization
    // ANNOTATION field + list overhead
    sizeInBytes += 3 + 5;
    for (int i = 0, length = v1Span.annotations().size(); i < length; i++) {
        int valueSize = utf8SizeInBytes(v1Span.annotations().get(i).value());
        sizeInBytes += ThriftAnnotationWriter.sizeInBytes(valueSize, endpointSize);
    }
    // BINARY_ANNOTATION field + list overhead
    sizeInBytes += 3 + 5;
    for (int i = 0, length = v1Span.binaryAnnotations().size(); i < length; i++) {
        V1BinaryAnnotation b = v1Span.binaryAnnotations().get(i);
        int keySize = utf8SizeInBytes(b.key());
        if (b.stringValue() != null) {
            int valueSize = utf8SizeInBytes(b.stringValue());
            sizeInBytes += ThriftBinaryAnnotationWriter.sizeInBytes(keySize, valueSize, endpointSize);
        } else {
            int remoteEndpointSize = ThriftEndpointCodec.sizeInBytes(b.endpoint());
            sizeInBytes += ThriftBinaryAnnotationWriter.sizeInBytes(keySize, 1, remoteEndpointSize);
        }
    }
    // DEBUG
    if (v1Span.debug() != null)
        sizeInBytes += 3 + 1;
    // TIMESTAMP
    if (v1Span.timestamp() != 0L)
        sizeInBytes += 3 + 8;
    // DURATION
    if (v1Span.duration() != 0L)
        sizeInBytes += 3 + 8;
    // TYPE_STOP
    sizeInBytes++;
    return sizeInBytes;
}
Also used : V1BinaryAnnotation(zipkin2.v1.V1BinaryAnnotation) Endpoint(zipkin2.Endpoint) V1Span(zipkin2.v1.V1Span)

Example 2 with V1BinaryAnnotation

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

Example 3 with V1BinaryAnnotation

use of zipkin2.v1.V1BinaryAnnotation in project zipkin by openzipkin.

the class V1SpanConverter method processBinaryAnnotations.

void processBinaryAnnotations(V1Span source) {
    zipkin2.Endpoint ca = null, sa = null, ma = null;
    for (int i = 0, length = source.binaryAnnotations.size(); i < length; i++) {
        V1BinaryAnnotation b = source.binaryAnnotations.get(i);
        // endpoint. Hence, we leniently parse.
        if ("ca".equals(b.key)) {
            ca = b.endpoint;
            continue;
        } else if ("sa".equals(b.key)) {
            sa = b.endpoint;
            continue;
        } else if ("ma".equals(b.key)) {
            ma = b.endpoint;
            continue;
        }
        Span.Builder currentSpan = forEndpoint(source, b.endpoint);
        // don't add marker "lc" tags
        if ("lc".equals(b.key) && b.stringValue.isEmpty())
            continue;
        currentSpan.putTag(b.key, b.stringValue);
    }
    boolean noCoreAnnotations = cs == null && cr == null && ss == null && sr == null;
    // special-case when we are missing core annotations, but we have both address annotations
    if (noCoreAnnotations && (ca != null || sa != null)) {
        if (ca != null && sa != null) {
            forEndpoint(source, ca).remoteEndpoint(sa);
        } else if (sa != null) {
            // "sa" is a default for a remote address, don't make it a client span
            forEndpoint(source, null).remoteEndpoint(sa);
        } else {
            // ca != null: treat it like a server
            forEndpoint(source, null).kind(Kind.SERVER).remoteEndpoint(ca);
        }
        return;
    }
    V1Annotation server = sr != null ? sr : ss;
    if (ca != null && server != null && !ca.equals(server.endpoint)) {
        // the same service name as "sa". Removing the service name prevents creating loopback links.
        if (hasSameServiceName(ca, server.endpoint)) {
            ca = ca.toBuilder().serviceName(null).build();
        }
        forEndpoint(source, server.endpoint).remoteEndpoint(ca);
    }
    if (sa != null) {
        // client span
        if (cs != null) {
            forEndpoint(source, cs.endpoint).remoteEndpoint(sa);
        } else if (cr != null) {
            forEndpoint(source, cr.endpoint).remoteEndpoint(sa);
        }
    }
    if (ma != null) {
        // a messaging span. This will ensure both sides have the address of the broker.
        if (ms != null)
            forEndpoint(source, ms.endpoint).remoteEndpoint(ma);
        if (mr != null)
            forEndpoint(source, mr.endpoint).remoteEndpoint(ma);
    }
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint)

Example 4 with V1BinaryAnnotation

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

Example 5 with V1BinaryAnnotation

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

Aggregations

Endpoint (zipkin2.Endpoint)5 V1BinaryAnnotation (zipkin2.v1.V1BinaryAnnotation)4 V1Annotation (zipkin2.v1.V1Annotation)2 Span (zipkin2.Span)1 V1Span (zipkin2.v1.V1Span)1