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);
}
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");
}
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);
}
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;
}
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;
}
Aggregations