Search in sources :

Example 61 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class SpanConverterTest method consumer_duration.

@Test
public void consumer_duration() {
    Span v2 = Span.newBuilder().traceId("1").parentId("2").id("3").name("next-message").kind(Kind.CONSUMER).localEndpoint(BACKEND).timestamp(1472470996199000L).duration(51000L).build();
    V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("next-message").timestamp(1472470996199000L).duration(51000L).addAnnotation(1472470996199000L, "wr", BACKEND).addAnnotation(1472470996250000L, "mr", 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 62 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class SpanConverterTest method server_missingSr.

@Test
public void server_missingSr() {
    Span v2 = Span.newBuilder().traceId("1").id("2").name("get").kind(Kind.SERVER).localEndpoint(BACKEND).timestamp(1472470996199000L).duration(207000L).build();
    V1Span v1 = V1Span.newBuilder().traceId("1").id("2").name("get").timestamp(1472470996199000L).duration(207000L).addAnnotation(1472470996406000L, "ss", BACKEND).build();
    assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 63 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class SpanConverterTest method server_clientAddress.

/**
 * This shows a historical finagle span, which has client-side socket info.
 */
@Test
public void server_clientAddress() {
    Span v2 = Span.newBuilder().traceId("1").id("2").name("get").kind(Kind.SERVER).localEndpoint(BACKEND).remoteEndpoint(FRONTEND.toBuilder().port(63840).build()).timestamp(TODAY).duration(207000L).addAnnotation(TODAY + 500L, "Gc(9,0.PSScavenge,2015-09-17 12:37:02 +0000,304.milliseconds+762.microseconds)").putTag("srv/finagle.version", "6.28.0").shared(true).build();
    V1Span v1 = V1Span.newBuilder().traceId("1").id("2").name("get").addAnnotation(v2.timestampAsLong(), "sr", v2.localEndpoint()).addAnnotation(v2.timestampAsLong() + 500L, "Gc(9,0.PSScavenge,2015-09-17 12:37:02 +0000,304.milliseconds+762.microseconds)", v2.localEndpoint()).addAnnotation(v2.timestampAsLong() + v2.durationAsLong(), "ss", v2.localEndpoint()).addBinaryAnnotation("srv/finagle.version", "6.28.0", v2.localEndpoint().toBuilder().port(0).build()).addBinaryAnnotation("sa", v2.localEndpoint()).addBinaryAnnotation("ca", v2.remoteEndpoint()).build();
    assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 64 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class SpanConverterTest method consumer_remote.

@Test
public void consumer_remote() {
    Span v2 = Span.newBuilder().traceId("1").parentId("2").id("3").name("next-message").kind(Kind.CONSUMER).localEndpoint(BACKEND).remoteEndpoint(kafka).timestamp(1472470996199000L).build();
    V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("next-message").timestamp(1472470996199000L).addAnnotation(1472470996199000L, "mr", BACKEND).addBinaryAnnotation("ma", kafka).build();
    assertThat(v2SpanConverter.convert(v2)).usingRecursiveComparison().isEqualTo(v1);
    assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 65 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class JacksonSpanDecoder method parseSpan.

static Span parseSpan(JsonParser jsonParser) throws IOException {
    if (!jsonParser.isExpectedStartObjectToken()) {
        throw new IOException("Not a valid JSON object, start token: " + jsonParser.currentToken());
    }
    Span.Builder result = Span.newBuilder();
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jsonParser.currentName();
        JsonToken value = jsonParser.nextToken();
        if (value == JsonToken.VALUE_NULL) {
            continue;
        }
        switch(fieldName) {
            case "traceId":
                result.traceId(jsonParser.getValueAsString());
                break;
            case "parentId":
                result.parentId(jsonParser.getValueAsString());
                break;
            case "id":
                result.id(jsonParser.getValueAsString());
                break;
            case "kind":
                result.kind(Span.Kind.valueOf(jsonParser.getValueAsString()));
                break;
            case "name":
                result.name(jsonParser.getValueAsString());
                break;
            case "timestamp":
                result.timestamp(jsonParser.getValueAsLong());
                break;
            case "duration":
                result.duration(jsonParser.getValueAsLong());
                break;
            case "localEndpoint":
                result.localEndpoint(parseEndpoint(jsonParser));
                break;
            case "remoteEndpoint":
                result.remoteEndpoint(parseEndpoint(jsonParser));
                break;
            case "annotations":
                if (!jsonParser.isExpectedStartArrayToken()) {
                    throw new IOException("Invalid span, expecting annotations array start, got: " + value);
                }
                while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                    Annotation a = parseAnnotation(jsonParser);
                    result.addAnnotation(a.timestamp(), a.value());
                }
                break;
            case "tags":
                if (value != JsonToken.START_OBJECT) {
                    throw new IOException("Invalid span, expecting tags object, got: " + value);
                }
                while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                    result.putTag(jsonParser.currentName(), jsonParser.nextTextValue());
                }
                break;
            case "debug":
                result.debug(jsonParser.getBooleanValue());
                break;
            case "shared":
                result.shared(jsonParser.getBooleanValue());
                break;
            default:
                jsonParser.skipChildren();
        }
    }
    return result.build();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Span(zipkin2.Span) Annotation(zipkin2.Annotation)

Aggregations

Span (zipkin2.Span)77 Test (org.junit.Test)54 Endpoint (zipkin2.Endpoint)28 Test (org.junit.jupiter.api.Test)17 V1Span (zipkin2.v1.V1Span)10 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)8 SpanSampler (com.wavefront.agent.sampler.SpanSampler)6 ByteBuf (io.netty.buffer.ByteBuf)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)6 IOException (java.io.IOException)6 Map (java.util.Map)6 Span (wavefront.report.Span)6 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)5 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)5 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)5 Trace (com.google.devtools.cloudtrace.v1.Trace)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Annotation (wavefront.report.Annotation)4 Annotation (zipkin2.Annotation)3