Search in sources :

Example 11 with V1Span

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

Example 12 with V1Span

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);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 13 with V1Span

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);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 14 with V1Span

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);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 15 with V1Span

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);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Aggregations

Span (zipkin2.Span)44 Test (org.junit.Test)41 Endpoint (zipkin2.Endpoint)8 V1Span (zipkin2.v1.V1Span)7 V1BinaryAnnotation (zipkin2.v1.V1BinaryAnnotation)4 EOFException (java.io.EOFException)3 BufferUnderflowException (java.nio.BufferUnderflowException)3 V1Annotation (zipkin2.v1.V1Annotation)3 V1SpanConverter (zipkin2.v1.V1SpanConverter)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Annotation (zipkin2.Annotation)1 JsonReader (zipkin2.internal.JsonCodec.JsonReader)1