Search in sources :

Example 76 with Kind

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

the class BulkIndexWriterTest method spanSearchFields_skipsWhenNoData.

@Test
public void spanSearchFields_skipsWhenNoData() {
    Span span = Span.newBuilder().traceId("20").id("22").parentId("21").timestamp(0L).localEndpoint(FRONTEND).kind(Kind.CLIENT).build();
    BulkIndexWriter.SPAN.writeDocument(span, buffer);
    assertThat(buffer.buffer().toString(StandardCharsets.UTF_8)).startsWith("{\"traceId\":\"");
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 77 with Kind

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

the class ITDependencies method instrumentedProducerAndConsumer.

@Test
protected void instrumentedProducerAndConsumer(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    String traceId = newTraceId();
    Endpoint kafka = suffixServiceName(TestObjects.KAFKA, testSuffix);
    Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);
    Endpoint backend = suffixServiceName(TestObjects.BACKEND, testSuffix);
    List<Span> trace = asList(Span.newBuilder().traceId(traceId).id("10").name("send").timestamp((TODAY + 50L) * 1000L).duration(1).kind(Kind.PRODUCER).localEndpoint(frontend).remoteEndpoint(kafka).build(), Span.newBuilder().traceId(traceId).parentId("10").id("11").name("receive").timestamp((TODAY + 100) * 1000L).duration(1).kind(Kind.CONSUMER).remoteEndpoint(kafka).localEndpoint(backend).build());
    processDependencies(trace);
    assertThat(store().getDependencies(endTs(trace), DAY).execute()).containsOnly(DependencyLink.newBuilder().parent(frontend.serviceName()).child(kafka.serviceName()).callCount(1).build(), DependencyLink.newBuilder().parent(kafka.serviceName()).child(backend.serviceName()).callCount(1).build());
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) Test(org.junit.jupiter.api.Test)

Example 78 with Kind

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

the class ITDependencies method annotationNamedErrorIsntError.

/**
 * A timeline annotation named error is not a failed span. A tag/binary annotation is.
 */
@Test
protected void annotationNamedErrorIsntError(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    String traceId = newTraceId();
    Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);
    Endpoint backend = suffixServiceName(TestObjects.BACKEND, testSuffix);
    List<Span> trace = asList(Span.newBuilder().traceId(traceId).id("10").timestamp((TODAY + 50) * 1000).kind(Kind.CLIENT).localEndpoint(frontend).build(), Span.newBuilder().traceId(traceId).id("10").shared(true).timestamp((TODAY + 100) * 1000).kind(Kind.SERVER).localEndpoint(backend).addAnnotation((TODAY + 72) * 1000, "error").build());
    processDependencies(trace);
    assertThat(store().getDependencies(endTs(trace), DAY).execute()).containsOnly(DependencyLink.newBuilder().parent(frontend.serviceName()).child(backend.serviceName()).callCount(1).build());
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) Test(org.junit.jupiter.api.Test)

Example 79 with Kind

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

the class ITDependencies method getDependencies_linksMixedTraceId.

/**
 * This tests that dependency linking ignores the high-bits of the trace ID when grouping spans
 * for dependency links. This allows environments with 64-bit instrumentation to participate in
 * the same trace as 128-bit instrumentation.
 */
@Test
protected void getDependencies_linksMixedTraceId(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    String traceId = newTraceId();
    Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);
    Endpoint backend = suffixServiceName(TestObjects.BACKEND, testSuffix);
    List<Span> mixedTrace = asList(Span.newBuilder().traceId(traceId).id("1").name("get").kind(Kind.SERVER).timestamp(TODAY * 1000L).duration(350 * 1000L).localEndpoint(frontend).build(), // the server dropped traceIdHigh
    Span.newBuilder().traceId(traceId.substring(16)).parentId("1").id("2").name("get").kind(Kind.SERVER).shared(true).timestamp((TODAY + 100) * 1000L).duration(250 * 1000L).localEndpoint(backend).build(), Span.newBuilder().traceId(traceId).parentId("1").id("2").kind(Kind.CLIENT).timestamp((TODAY + 50) * 1000L).duration(300 * 1000L).localEndpoint(frontend).build());
    processDependencies(mixedTrace);
    assertThat(store().getDependencies(endTs(mixedTrace), DAY).execute()).containsOnly(DependencyLink.newBuilder().parent(frontend.serviceName()).child(backend.serviceName()).callCount(1).build());
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) Test(org.junit.jupiter.api.Test)

Example 80 with Kind

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

the class JsonSerializers method parseSpan.

static Span parseSpan(JsonParser parser) throws IOException {
    if (!parser.isExpectedStartObjectToken()) {
        throw new IllegalArgumentException("Not a valid JSON object, start token: " + parser.currentToken());
    }
    Span.Builder result = Span.newBuilder();
    JsonToken value;
    while ((value = parser.nextValue()) != JsonToken.END_OBJECT) {
        if (value == null) {
            throw new IOException("End of input while parsing object.");
        }
        if (value == JsonToken.VALUE_NULL) {
            continue;
        }
        switch(parser.currentName()) {
            case "traceId":
                result.traceId(parser.getText());
                break;
            case "parentId":
                result.parentId(parser.getText());
                break;
            case "id":
                result.id(parser.getText());
                break;
            case "kind":
                result.kind(Span.Kind.valueOf(parser.getText()));
                break;
            case "name":
                result.name(parser.getText());
                break;
            case "timestamp":
                result.timestamp(parser.getLongValue());
                break;
            case "duration":
                result.duration(parser.getLongValue());
                break;
            case "localEndpoint":
                result.localEndpoint(parseEndpoint(parser));
                break;
            case "remoteEndpoint":
                result.remoteEndpoint(parseEndpoint(parser));
                break;
            case "annotations":
                if (value != JsonToken.START_ARRAY) {
                    throw new IOException("Invalid span, expecting annotations array start, got: " + value);
                }
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    Annotation a = parseAnnotation(parser);
                    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 (parser.nextValue() != JsonToken.END_OBJECT) {
                    result.putTag(parser.currentName(), parser.getValueAsString());
                }
                break;
            case "debug":
                result.debug(parser.getBooleanValue());
                break;
            case "shared":
                result.shared(parser.getBooleanValue());
                break;
            default:
        }
    }
    return result.build();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) 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