use of io.opentelemetry.proto.trace.v1.Span in project instrumentation-java by census-instrumentation.
the class TraceProtoUtils method toSpanProto.
/**
* Converts {@link SpanData} to {@link Span} proto.
*
* @param spanData the {@code SpanData}.
* @return proto representation of {@code Span}.
*/
static Span toSpanProto(SpanData spanData) {
SpanContext spanContext = spanData.getContext();
TraceId traceId = spanContext.getTraceId();
SpanId spanId = spanContext.getSpanId();
Span.Builder spanBuilder = Span.newBuilder().setTraceId(toByteString(traceId.getBytes())).setSpanId(toByteString(spanId.getBytes())).setTracestate(toTracestateProto(spanContext.getTracestate())).setName(toTruncatableStringProto(spanData.getName())).setStartTime(toTimestampProto(spanData.getStartTimestamp())).setAttributes(toAttributesProto(spanData.getAttributes())).setTimeEvents(toTimeEventsProto(spanData.getAnnotations(), spanData.getMessageEvents())).setLinks(toLinksProto(spanData.getLinks()));
Kind kind = spanData.getKind();
if (kind != null) {
spanBuilder.setKind(toSpanKindProto(kind));
}
io.opencensus.trace.Status status = spanData.getStatus();
if (status != null) {
spanBuilder.setStatus(toStatusProto(status));
}
Timestamp end = spanData.getEndTimestamp();
if (end != null) {
spanBuilder.setEndTime(toTimestampProto(end));
}
Integer childSpanCount = spanData.getChildSpanCount();
if (childSpanCount != null) {
spanBuilder.setChildSpanCount(UInt32Value.newBuilder().setValue(childSpanCount).build());
}
Boolean hasRemoteParent = spanData.getHasRemoteParent();
if (hasRemoteParent != null) {
spanBuilder.setSameProcessAsParentSpan(BoolValue.of(!hasRemoteParent));
}
SpanId parentSpanId = spanData.getParentSpanId();
if (parentSpanId != null && parentSpanId.isValid()) {
spanBuilder.setParentSpanId(toByteString(parentSpanId.getBytes()));
}
return spanBuilder.build();
}
use of io.opentelemetry.proto.trace.v1.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.newBuilder().traceId("1").id("1").name("foo").build();
// write the span to the zipkin using http
assertThat(postSpansV1(asList(span)).code()).isEqualTo(202);
// read the traces directly
assertThat(zipkin.getTraces()).containsOnly(asList(span));
}
use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class CassandraSpanConsumerTest method traceByServiceSpan_indexesLocalServiceNameAndEmptySpanName.
/**
* To allow lookups w/o a span name, we index "". "" is used instead of null to avoid creating
* tombstones.
*/
@Test
public void traceByServiceSpan_indexesLocalServiceNameAndEmptySpanName() {
Span span = spanWithoutAnnotationsOrTags;
AggregateCall<?, Void> call = (AggregateCall<?, Void>) consumer.accept(singletonList(span));
assertThat(call.delegate()).filteredOn(c -> c instanceof InsertTraceByServiceSpan).extracting("input.service", "input.span").containsExactly(tuple(FRONTEND.serviceName(), span.name()), tuple(FRONTEND.serviceName(), ""));
}
use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class CassandraSpanConsumerTest method strictTraceIdFalse_setsTraceIdHigh.
@Test
public void strictTraceIdFalse_setsTraceIdHigh() {
consumer = spanConsumer(CassandraStorage.newBuilder().strictTraceId(false));
Span span = spanWithoutAnnotationsOrTags.toBuilder().traceId("77fcac3d4c5be8d2a037812820c65f28").build();
AggregateCall<?, Void> call = (AggregateCall<?, Void>) consumer.accept(singletonList(span));
assertThat(call.delegate()).filteredOn(c -> c instanceof InsertSpan).extracting("input.trace_id_high", "input.trace_id").containsExactly(tuple("77fcac3d4c5be8d2", "a037812820c65f28"));
}
use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class CassandraSpanConsumerTest method serviceSpanKeys_emptyWhenNoEndpoints.
@Test
public void serviceSpanKeys_emptyWhenNoEndpoints() {
Span span = spanWithoutAnnotationsOrTags.toBuilder().localEndpoint(null).build();
assertThat(consumer.accept(singletonList(span))).isInstanceOf(ResultSetFutureCall.class);
}
Aggregations