Search in sources :

Example 21 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class JsonAdaptersTest method binaryAnnotation_long_max.

@Test
public void binaryAnnotation_long_max() throws IOException {
    String json = ("{" + "  \"traceId\": \"6b221d5bc9e6496c\"," + "  \"id\": \"6b221d5bc9e6496c\"," + "  \"name\": \"get-traces\"," + "  \"binaryAnnotations\": [" + "    {" + "      \"key\": \"num\"," + "      \"value\": \"9223372036854775807\"," + "      \"type\": \"I64\"" + "    }" + "  ]" + "}").replaceAll("\\s", "");
    Span span = JsonAdapters.SPAN_ADAPTER.fromJson(json);
    assertThat(span.binaryAnnotations).extracting(b -> ByteBuffer.wrap(b.value).getLong()).containsExactly(9223372036854775807L);
}
Also used : Buffer(okio.Buffer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Annotation(zipkin.Annotation) IOException(java.io.IOException) Test(org.junit.Test) BinaryAnnotation(zipkin.BinaryAnnotation) Codec(zipkin.Codec) DependencyLink(zipkin.DependencyLink) ByteBuffer(java.nio.ByteBuffer) Endpoint(zipkin.Endpoint) Span(zipkin.Span) Arrays.asList(java.util.Arrays.asList) TestObjects(zipkin.TestObjects) Util(zipkin.internal.Util) SPAN_ADAPTER(zipkin.storage.elasticsearch.http.JsonAdapters.SPAN_ADAPTER) Span(zipkin.Span) Test(org.junit.Test)

Example 22 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class ElasticsearchHttpSpanConsumerTest method spanGoesIntoADailyIndex_fallsBackToTodayWhenNoTimestamps.

@Test
public void spanGoesIntoADailyIndex_fallsBackToTodayWhenNoTimestamps() throws Exception {
    Span span = Span.builder().traceId(20L).id(20L).name("get").build();
    accept(span);
    // make sure the span went into an index corresponding to collection time
    assertThat(findSpans(TODAY, span.traceId)).contains("\"hits\":{\"total\":1");
}
Also used : Span(zipkin.Span) Test(org.junit.Test)

Example 23 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class InternalElasticsearchClientTest method toSpanBytes_timestampMillis.

@Test
public void toSpanBytes_timestampMillis() {
    Span span = Span.builder().traceId(20L).id(20L).name("get").timestamp(TODAY * 1000).build();
    byte[] result = InternalElasticsearchClient.toSpanBytes(span, TODAY);
    String json = new String(result);
    assertThat(json).startsWith("{\"timestamp_millis\":" + Long.toString(TODAY) + ",\"traceId\":\"0000000000000014\"");
    assertThat(Codec.JSON.readSpan(json.getBytes())).isEqualTo(// ignores timestamp_millis field
    span);
}
Also used : Span(zipkin.Span) Test(org.junit.Test)

Example 24 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class Collector method sample.

List<Span> sample(List<Span> input) {
    List<Span> sampled = new ArrayList<>(input.size());
    for (Span s : input) {
        if (sampler.isSampled(s))
            sampled.add(s);
    }
    int dropped = input.size() - sampled.size();
    if (dropped > 0)
        metrics.incrementSpansDropped(dropped);
    return sampled;
}
Also used : ArrayList(java.util.ArrayList) Span(zipkin.Span)

Example 25 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class GroupByTraceId method apply.

public static List<List<Span>> apply(Collection<Span> input, boolean strictTraceId, boolean adjust) {
    if (input == null || input.isEmpty())
        return Collections.emptyList();
    Map<Pair<Long>, List<Span>> groupedByTraceId = new LinkedHashMap<>();
    for (Span span : input) {
        Pair<Long> traceId = Pair.create(strictTraceId ? span.traceIdHigh : 0L, span.traceId);
        if (!groupedByTraceId.containsKey(traceId)) {
            groupedByTraceId.put(traceId, new LinkedList<>());
        }
        groupedByTraceId.get(traceId).add(span);
    }
    List<List<Span>> result = new ArrayList<>(groupedByTraceId.size());
    for (List<Span> sameTraceId : groupedByTraceId.values()) {
        result.add(adjust ? CorrectForClockSkew.apply(MergeById.apply(sameTraceId)) : sameTraceId);
    }
    Collections.sort(result, TRACE_DESCENDING);
    return result;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) Span(zipkin.Span) LinkedHashMap(java.util.LinkedHashMap)

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