Search in sources :

Example 11 with Kind

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

the class SpanTranslatorTest method translate_clientSpan.

/**
 * This test is intentionally sensitive, so changing other parts makes obvious impact here
 */
@Test
public void translate_clientSpan() {
    Span zipkinSpan = Span.newBuilder().traceId("7180c278b62e8f6a216a2aea45d08fc9").parentId("6b221d5bc9e6496c").id("5b4185666d50f68b").name("get").kind(Span.Kind.CLIENT).localEndpoint(Endpoint.newBuilder().serviceName("frontend").build()).remoteEndpoint(Endpoint.newBuilder().serviceName("backend").ip("192.168.99.101").port(9000).build()).timestamp(// 1 second after epoch
    1_000_000L).duration(123_456L).addAnnotation(1_123_000L, "foo").putTag("http.path", "/api").putTag("clnt/finagle.version", "6.45.0").build();
    TraceSpan translated = SpanTranslator.translate(TraceSpan.newBuilder(), zipkinSpan).build();
    assertThat(translated).isEqualTo(TraceSpan.newBuilder().setSpanId(Long.parseUnsignedLong(zipkinSpan.id(), 16) ^ 0x3f6a2ec3c810c2abL).setParentSpanId(Long.parseUnsignedLong(zipkinSpan.parentId(), 16)).setKind(TraceSpan.SpanKind.RPC_CLIENT).setName("get").setStartTime(Timestamp.newBuilder().setSeconds(1).build()).setEndTime(Timestamp.newBuilder().setSeconds(1).setNanos(123_456_000).build()).putLabels("zipkin.io/clnt/finagle.version", "6.45.0").putLabels("zipkin.io/http.path", "/api").putLabels("/component", "frontend").putLabels("zipkin.io/foo", "1970-01-01 (00:00:01.123)").build());
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) Test(org.junit.Test)

Example 12 with Kind

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

the class TraceTranslatorTest method testMultihostServerRootSpan.

@Test
public void testMultihostServerRootSpan() {
    Span span1 = Span.newBuilder().traceId("1").id("1").name("/a").timestamp(// This is set because the server owns the span
    1474488796000000L).duration(5000000L).build();
    Span span2 = Span.newBuilder().kind(Kind.CLIENT).traceId("1").parentId("1").id("2").name("/b?client").timestamp(// This is set because the client owns the span.
    1474488797000000L).duration(1500000L).build();
    Span span3 = Span.newBuilder().kind(Kind.SERVER).shared(true).traceId("1").parentId("1").id("2").name("/b?server").build();
    Span span4 = Span.newBuilder().traceId("1").parentId("2").id("3").name("custom-span").timestamp(1474488797600000L).duration(200000L).build();
    Collection<Trace> traces = TraceTranslator.translateSpans("test-project", Arrays.asList(span1, span2, span3, span4));
    assertEquals(1, traces.size());
    Trace trace = traces.iterator().next();
    Map<String, TraceSpan> spansByName = getSpansByName(trace);
    assertThat(spansByName).containsOnlyKeys("/a", "/b?client", "/b?server", "custom-span");
    assertDistinctSpanIds(trace);
    assertThat(spansByName.get("custom-span").getParentSpanId()).isEqualTo(spansByName.get("/b?server").getSpanId());
    assertThat(spansByName.get("/b?server").getParentSpanId()).isEqualTo(spansByName.get("/b?client").getSpanId());
    assertThat(spansByName.get("/b?client").getParentSpanId()).isEqualTo(spansByName.get("/a").getSpanId());
    assertThat(spansByName.get("/a").getParentSpanId()).isEqualTo(0);
}
Also used : Trace(com.google.devtools.cloudtrace.v1.Trace) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test)

Example 13 with Kind

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

the class TraceTranslatorTest method testMultihostServerRootSpan_noTimestamp.

@Test
public void testMultihostServerRootSpan_noTimestamp() {
    Span span1 = Span.newBuilder().kind(Kind.SERVER).traceId("1").id("1").name("/a").build();
    Span span2 = Span.newBuilder().kind(Kind.CLIENT).traceId("1").parentId("1").id("2").name("/b?client").build();
    Span span3 = Span.newBuilder().kind(Kind.SERVER).shared(true).traceId("1").parentId("1").id("2").name("/b?server").build();
    Span span4 = Span.newBuilder().traceId("1").parentId("2").id("3").name("custom-span").build();
    Collection<Trace> traces = TraceTranslator.translateSpans("test-project", Arrays.asList(span1, span2, span3, span4));
    assertEquals(1, traces.size());
    Trace trace = traces.iterator().next();
    Map<String, TraceSpan> spansByName = getSpansByName(trace);
    assertThat(spansByName).containsOnlyKeys("/a", "/b?client", "/b?server", "custom-span");
    assertDistinctSpanIds(trace);
    assertThat(spansByName.get("custom-span").getParentSpanId()).isEqualTo(spansByName.get("/b?server").getSpanId());
    assertThat(spansByName.get("/b?server").getParentSpanId()).isEqualTo(spansByName.get("/b?client").getSpanId());
    assertThat(spansByName.get("/b?client").getParentSpanId()).isEqualTo(spansByName.get("/a").getSpanId());
// Without the timestamp field, it's not possible to correctly set the root span's parentSpanId
// to 0 because we didn't have enough information to conclude that it had no parent.
}
Also used : Trace(com.google.devtools.cloudtrace.v1.Trace) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test)

Example 14 with Kind

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

the class ElasticsearchSpanConsumerTest method traceIsSearchableByServerServiceName.

@Test
void traceIsSearchableByServerServiceName() throws Exception {
    server.enqueue(SUCCESS_RESPONSE);
    Span clientSpan = Span.newBuilder().traceId("20").id("22").name("").parentId("21").timestamp(1000L).kind(Kind.CLIENT).localEndpoint(WEB_ENDPOINT).build();
    Span serverSpan = Span.newBuilder().traceId("20").id("22").name("get").parentId("21").timestamp(2000L).kind(Kind.SERVER).localEndpoint(APP_ENDPOINT).build();
    accept(serverSpan, clientSpan);
    // make sure that both timestamps are in the index
    assertThat(server.takeRequest().request().contentUtf8()).contains("{\"timestamp_millis\":2").contains("{\"timestamp_millis\":1");
}
Also used : Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Example 15 with Kind

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

the class BulkIndexWriterTest method spanSearchFields_addsTimestampFieldWhenNoTags.

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

Aggregations

Span (zipkin2.Span)82 Test (org.junit.Test)54 Endpoint (zipkin2.Endpoint)25 Test (org.junit.jupiter.api.Test)17 V1Span (zipkin2.v1.V1Span)10 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)8 IOException (java.io.IOException)6 Map (java.util.Map)5 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)5 Tracer (brave.Tracer)4 Tracing (brave.Tracing)4 Trace (com.google.devtools.cloudtrace.v1.Trace)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Before (org.junit.Before)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Span (brave.Span)3 Sampler (brave.sampler.Sampler)3 Annotation (zipkin2.Annotation)3