use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.
the class V1JsonSpanReader method readList.
public boolean readList(ReadBuffer buffer, Collection<Span> out) {
if (buffer.available() == 0)
return false;
V1SpanConverter converter = V1SpanConverter.create();
JsonReader reader = new JsonReader(buffer);
try {
reader.beginArray();
if (!reader.hasNext())
return false;
while (reader.hasNext()) {
V1Span result = fromJson(reader);
converter.convert(result, out);
}
reader.endArray();
return true;
} catch (Exception e) {
throw exceptionReading("List<Span>", e);
}
}
use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.
the class ITDependencies method duplicateAddress.
/**
* This test confirms that the span store can process trace with intermediate spans like the below
* properly.
* <p>
* span1: SR SS span2: intermediate call span3: CS SR SS CR: Dependency 1
*/
@Test
protected void duplicateAddress(TestInfo testInfo) throws Exception {
String testSuffix = testSuffix(testInfo);
String traceId = newTraceId();
Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);
Endpoint backend = suffixServiceName(TestObjects.BACKEND, testSuffix);
V1SpanConverter converter = V1SpanConverter.create();
List<Span> trace = new ArrayList<>();
converter.convert(V1Span.newBuilder().traceId(traceId).id("20").name("get").timestamp(TODAY * 1000L).duration(350L * 1000L).addAnnotation(TODAY * 1000, "sr", frontend).addAnnotation((TODAY + 350) * 1000, "ss", frontend).addBinaryAnnotation("ca", frontend).addBinaryAnnotation("sa", frontend).build(), trace);
converter.convert(V1Span.newBuilder().traceId(traceId).parentId("21").id("22").name("get").timestamp((TODAY + 50) * 1000L).duration(250L * 1000L).addAnnotation((TODAY + 50) * 1000, "cs", frontend).addAnnotation((TODAY + 300) * 1000, "cr", frontend).addBinaryAnnotation("ca", backend).addBinaryAnnotation("sa", backend).build(), trace);
processDependencies(trace);
assertThat(store().getDependencies(TODAY + 1000, 1000L).execute()).containsOnly(DependencyLink.newBuilder().parent(frontend.serviceName()).child(backend.serviceName()).callCount(1).build());
}
use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.
the class SelectSpansAndAnnotations method apply.
@Override
public List<Span> apply(DSLContext context) {
final Map<Pair, List<V1Span.Builder>> spansWithoutAnnotations;
final Map<Row3<Long, Long, Long>, List<Record>> dbAnnotations;
spansWithoutAnnotations = context.select(schema.spanFields).from(ZIPKIN_SPANS).where(traceIdCondition(context)).stream().map(r -> V1Span.newBuilder().traceIdHigh(maybeGet(r, ZIPKIN_SPANS.TRACE_ID_HIGH, 0L)).traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)).name(r.getValue(ZIPKIN_SPANS.NAME)).id(r.getValue(ZIPKIN_SPANS.ID)).parentId(maybeGet(r, ZIPKIN_SPANS.PARENT_ID, 0L)).timestamp(maybeGet(r, ZIPKIN_SPANS.START_TS, 0L)).duration(maybeGet(r, ZIPKIN_SPANS.DURATION, 0L)).debug(r.getValue(ZIPKIN_SPANS.DEBUG))).collect(groupingBy(s -> new Pair(s.traceIdHigh(), s.traceId()), LinkedHashMap::new, Collectors.toList()));
dbAnnotations = context.select(schema.annotationFields).from(ZIPKIN_ANNOTATIONS).where(schema.annotationsTraceIdCondition(spansWithoutAnnotations.keySet())).orderBy(ZIPKIN_ANNOTATIONS.A_TIMESTAMP.asc(), ZIPKIN_ANNOTATIONS.A_KEY.asc()).stream().collect(groupingBy((Record a) -> row(maybeGet(a, ZIPKIN_ANNOTATIONS.TRACE_ID_HIGH, 0L), a.getValue(ZIPKIN_ANNOTATIONS.TRACE_ID), a.getValue(ZIPKIN_ANNOTATIONS.SPAN_ID)), LinkedHashMap::new, // LinkedHashMap preserves order while grouping
Collectors.toList()));
V1SpanConverter converter = V1SpanConverter.create();
List<Span> allSpans = new ArrayList<>(spansWithoutAnnotations.size());
for (List<V1Span.Builder> spans : spansWithoutAnnotations.values()) {
for (V1Span.Builder span : spans) {
Row3<Long, Long, Long> key = row(span.traceIdHigh(), span.traceId(), span.id());
if (dbAnnotations.containsKey(key)) {
for (Record a : dbAnnotations.get(key)) {
Endpoint endpoint = endpoint(a);
processAnnotationRecord(a, span, endpoint);
}
}
converter.convert(span.build(), allSpans);
}
}
return allSpans;
}
use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.
the class ThriftCodec method readList.
public static boolean readList(ReadBuffer buffer, Collection<Span> out) {
int length = buffer.available();
if (length == 0)
return false;
try {
int listLength = readListLength(buffer);
if (listLength == 0)
return false;
V1ThriftSpanReader reader = new V1ThriftSpanReader();
V1SpanConverter converter = V1SpanConverter.create();
for (int i = 0; i < listLength; i++) {
V1Span v1Span = reader.read(buffer);
converter.convert(v1Span, out);
}
} catch (Exception e) {
throw exceptionReading("List<Span>", e);
}
return true;
}
Aggregations