use of zipkin.Span in project zipkin by openzipkin.
the class ZipkinRuleTest method getBy128BitTraceId.
@Test
public void getBy128BitTraceId() throws Exception {
Span span = TRACE.get(0).toBuilder().traceIdHigh(traceId).build();
zipkin.storeSpans(asList(span));
Response getResponse = client.newCall(new Request.Builder().url(format("%s/api/v1/trace/%016x%016x", zipkin.httpUrl(), traceId, traceId)).build()).execute();
assertThat(getResponse.code()).isEqualTo(200);
}
use of zipkin.Span in project zipkin by openzipkin.
the class ZipkinRuleTest method getTraces_whenMissingTimestamps.
/** The rule is here to help debugging. Even partial spans should be returned */
@Test
public void getTraces_whenMissingTimestamps() throws IOException {
Span span = Span.builder().traceId(traceId).id(traceId).name("foo").build();
// write the span to the zipkin using http
assertThat(postSpans(asList(span)).code()).isEqualTo(202);
// read the traces directly
assertThat(zipkin.getTraces()).containsOnly(asList(span));
}
use of zipkin.Span in project zipkin by openzipkin.
the class MySQLSpanConsumer method accept.
/** Blocking version of {@link AsyncSpanConsumer#accept} */
@Override
public void accept(List<Span> spans) {
if (spans.isEmpty())
return;
try (Connection conn = datasource.getConnection()) {
DSLContext create = context.get(conn);
List<Query> inserts = new ArrayList<>();
for (Span span : spans) {
Long overridingTimestamp = authoritativeTimestamp(span);
Long timestamp = overridingTimestamp != null ? overridingTimestamp : guessTimestamp(span);
Map<TableField<Record, ?>, Object> updateFields = new LinkedHashMap<>();
if (!span.name.equals("") && !span.name.equals("unknown")) {
updateFields.put(ZIPKIN_SPANS.NAME, span.name);
}
// replace any tentative timestamp with the authoritative one.
if (overridingTimestamp != null) {
updateFields.put(ZIPKIN_SPANS.START_TS, overridingTimestamp);
}
if (span.duration != null) {
updateFields.put(ZIPKIN_SPANS.DURATION, span.duration);
}
InsertSetMoreStep<Record> insertSpan = create.insertInto(ZIPKIN_SPANS).set(ZIPKIN_SPANS.TRACE_ID, span.traceId).set(ZIPKIN_SPANS.ID, span.id).set(ZIPKIN_SPANS.PARENT_ID, span.parentId).set(ZIPKIN_SPANS.NAME, span.name).set(ZIPKIN_SPANS.DEBUG, span.debug).set(ZIPKIN_SPANS.START_TS, timestamp).set(ZIPKIN_SPANS.DURATION, span.duration);
if (span.traceIdHigh != 0 && schema.hasTraceIdHigh) {
insertSpan.set(ZIPKIN_SPANS.TRACE_ID_HIGH, span.traceIdHigh);
}
inserts.add(updateFields.isEmpty() ? insertSpan.onDuplicateKeyIgnore() : insertSpan.onDuplicateKeyUpdate().set(updateFields));
for (Annotation annotation : span.annotations) {
InsertSetMoreStep<Record> insert = create.insertInto(ZIPKIN_ANNOTATIONS).set(ZIPKIN_ANNOTATIONS.TRACE_ID, span.traceId).set(ZIPKIN_ANNOTATIONS.SPAN_ID, span.id).set(ZIPKIN_ANNOTATIONS.A_KEY, annotation.value).set(ZIPKIN_ANNOTATIONS.A_TYPE, -1).set(ZIPKIN_ANNOTATIONS.A_TIMESTAMP, annotation.timestamp);
if (span.traceIdHigh != 0 && schema.hasTraceIdHigh) {
insert.set(ZIPKIN_ANNOTATIONS.TRACE_ID_HIGH, span.traceIdHigh);
}
if (annotation.endpoint != null) {
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME, annotation.endpoint.serviceName);
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4, annotation.endpoint.ipv4);
if (annotation.endpoint.ipv6 != null && schema.hasIpv6) {
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV6, annotation.endpoint.ipv6);
}
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT, annotation.endpoint.port);
}
inserts.add(insert.onDuplicateKeyIgnore());
}
for (BinaryAnnotation annotation : span.binaryAnnotations) {
InsertSetMoreStep<Record> insert = create.insertInto(ZIPKIN_ANNOTATIONS).set(ZIPKIN_ANNOTATIONS.TRACE_ID, span.traceId).set(ZIPKIN_ANNOTATIONS.SPAN_ID, span.id).set(ZIPKIN_ANNOTATIONS.A_KEY, annotation.key).set(ZIPKIN_ANNOTATIONS.A_VALUE, annotation.value).set(ZIPKIN_ANNOTATIONS.A_TYPE, annotation.type.value).set(ZIPKIN_ANNOTATIONS.A_TIMESTAMP, timestamp);
if (span.traceIdHigh != 0 && schema.hasTraceIdHigh) {
insert.set(ZIPKIN_ANNOTATIONS.TRACE_ID_HIGH, span.traceIdHigh);
}
if (annotation.endpoint != null) {
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME, annotation.endpoint.serviceName);
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4, annotation.endpoint.ipv4);
if (annotation.endpoint.ipv6 != null && schema.hasIpv6) {
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV6, annotation.endpoint.ipv6);
}
insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT, annotation.endpoint.port);
}
inserts.add(insert.onDuplicateKeyIgnore());
}
}
create.batch(inserts).execute();
} catch (SQLException e) {
// TODO
throw new RuntimeException(e);
}
}
use of zipkin.Span in project zipkin by openzipkin.
the class JsonAdaptersTest method binaryAnnotation_double.
@Test
public void binaryAnnotation_double() throws IOException {
Span span = TestObjects.LOTS_OF_SPANS[0].toBuilder().binaryAnnotations(asList(BinaryAnnotation.builder().key("Double.zero").type(BinaryAnnotation.Type.DOUBLE).value(ByteBuffer.allocate(8).putDouble(0, 0.0).array()).build(), BinaryAnnotation.builder().key("Double.negative").type(BinaryAnnotation.Type.DOUBLE).value(ByteBuffer.allocate(8).putDouble(0, -1.005656679588439279).array()).build(), BinaryAnnotation.builder().key("Double.MIN_VALUE").type(BinaryAnnotation.Type.DOUBLE).value(ByteBuffer.allocate(8).putDouble(0, Double.MIN_VALUE).array()).build(), BinaryAnnotation.builder().key("Double.MAX_VALUE").type(BinaryAnnotation.Type.I64).value(ByteBuffer.allocate(8).putDouble(0, Double.MAX_VALUE).array()).build())).build();
Buffer bytes = new Buffer();
bytes.write(Codec.JSON.writeSpan(span));
assertThat(SPAN_ADAPTER.fromJson(bytes)).isEqualTo(span);
}
use of zipkin.Span in project zipkin by openzipkin.
the class JsonAdaptersTest method binaryAnnotation_long.
@Test
public void binaryAnnotation_long() throws IOException {
Span span = TestObjects.LOTS_OF_SPANS[0].toBuilder().binaryAnnotations(asList(BinaryAnnotation.builder().key("Long.zero").type(BinaryAnnotation.Type.I64).value(ByteBuffer.allocate(8).putLong(0, 0L).array()).build(), BinaryAnnotation.builder().key("Long.negative").type(BinaryAnnotation.Type.I64).value(ByteBuffer.allocate(8).putLong(0, -1005656679588439279L).array()).build(), BinaryAnnotation.builder().key("Long.MIN_VALUE").type(BinaryAnnotation.Type.I64).value(ByteBuffer.allocate(8).putLong(0, Long.MIN_VALUE).array()).build(), BinaryAnnotation.builder().key("Long.MAX_VALUE").type(BinaryAnnotation.Type.I64).value(ByteBuffer.allocate(8).putLong(0, Long.MAX_VALUE).array()).build())).build();
Buffer bytes = new Buffer();
bytes.write(Codec.JSON.writeSpan(span));
assertThat(SPAN_ADAPTER.fromJson(bytes)).isEqualTo(span);
}
Aggregations