Search in sources :

Example 86 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class SpanStoreTest method whenSpanTimestampIsMissingClientSendIsPreferred.

/**
   * Spans report depth-first. Make sure the client timestamp is preferred when instrumentation
   * don't add a timestamp.
   */
@Test
public void whenSpanTimestampIsMissingClientSendIsPreferred() {
    Endpoint frontend = Endpoint.create("frontend", 192 << 24 | 168 << 16 | 2);
    Annotation cs = Annotation.create((today + 50) * 1000, CLIENT_SEND, frontend);
    Annotation cr = Annotation.create((today + 150) * 1000, CLIENT_RECV, frontend);
    Endpoint backend = Endpoint.create("backend", 192 << 24 | 168 << 16 | 2);
    Annotation sr = Annotation.create((today + 95) * 1000, SERVER_RECV, backend);
    Annotation ss = Annotation.create((today + 100) * 1000, SERVER_SEND, backend);
    Span span = Span.builder().traceId(1).name("method1").id(666).build();
    // Simulate the server-side of a shared span arriving first
    accept(span.toBuilder().addAnnotation(sr).addAnnotation(ss).build());
    accept(span.toBuilder().addAnnotation(cs).addAnnotation(cr).build());
    // Make sure that the client's timestamp won
    assertThat(store().getTrace(span1.traceIdHigh, span.traceId)).containsExactly(span.toBuilder().timestamp(cs.timestamp).duration(cr.timestamp - cs.timestamp).annotations(asList(cs, sr, ss, cr)).build());
}
Also used : Endpoint(zipkin.Endpoint) Span(zipkin.Span) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) Test(org.junit.Test)

Example 87 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class JsonCodecTest method binaryAnnotation_long.

@Test
public void binaryAnnotation_long() {
    String json = "{\n" + "  \"traceId\": \"6b221d5bc9e6496c\",\n" + "  \"name\": \"get-traces\",\n" + "  \"id\": \"6b221d5bc9e6496c\",\n" + "  \"binaryAnnotations\": [\n" + "    {\n" + "      \"key\": \"num\",\n" + "      \"value\": 123456789,\n" + "      \"type\": \"I64\"\n" + "    }\n" + "  ]\n" + "}";
    Span span = Codec.JSON.readSpan(json.getBytes(UTF_8));
    assertThat(span.binaryAnnotations).containsExactly(BinaryAnnotation.builder().key("num").type(BinaryAnnotation.Type.I64).value(toBytes(123456789)).build());
    assertThat(Codec.JSON.readSpan(Codec.JSON.writeSpan(span))).isEqualTo(span);
}
Also used : Span(zipkin.Span) CodecTest(zipkin.CodecTest) Test(org.junit.Test)

Example 88 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class JsonCodecTest method writesTraceIdHighIntoTraceIdField.

@Test
public void writesTraceIdHighIntoTraceIdField() {
    Span with128BitTraceId = Span.builder().traceIdHigh(Util.lowerHexToUnsignedLong("48485a3953bb6124")).traceId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")).id(1).name("").build();
    assertThat(new String(Codec.JSON.writeSpan(with128BitTraceId), Util.UTF_8)).startsWith("{\"traceId\":\"48485a3953bb61246b221d5bc9e6496c\"");
}
Also used : Span(zipkin.Span) CodecTest(zipkin.CodecTest) Test(org.junit.Test)

Example 89 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class ThriftCodecTest method sizeInBytes_span.

@Test
public void sizeInBytes_span() throws IOException {
    Span span = TestObjects.LOTS_OF_SPANS[0];
    assertThat(ThriftCodec.SPAN_ADAPTER.sizeInBytes(span)).isEqualTo(codec().writeSpan(span).length);
}
Also used : Span(zipkin.Span) CodecTest(zipkin.CodecTest) Test(org.junit.Test)

Example 90 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class ThriftCodecTest method readSpanFromByteBuffer.

@Test
public void readSpanFromByteBuffer() throws IOException {
    for (Span span : TestObjects.TRACE) {
        byte[] bytes = codec().writeSpan(span);
        assertThat(codec().readSpan(ByteBuffer.wrap(bytes))).isEqualTo(span);
    }
}
Also used : Span(zipkin.Span) CodecTest(zipkin.CodecTest) Test(org.junit.Test)

Aggregations

Span (zipkin.Span)104 Test (org.junit.Test)84 Endpoint (zipkin.Endpoint)21 BinaryAnnotation (zipkin.BinaryAnnotation)12 ArrayList (java.util.ArrayList)11 Annotation (zipkin.Annotation)10 CodecTest (zipkin.CodecTest)9 CorrectForClockSkew.isLocalSpan (zipkin.internal.CorrectForClockSkew.isLocalSpan)9 ByteBuffer (java.nio.ByteBuffer)8 List (java.util.List)8 Buffer (okio.Buffer)8 LinkedHashMap (java.util.LinkedHashMap)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ImmutableList (com.google.common.collect.ImmutableList)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 LinkedList (java.util.LinkedList)4 Constants (zipkin.Constants)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 IOException (java.io.IOException)3 Arrays.asList (java.util.Arrays.asList)3