use of com.google.devtools.cloudtrace.v2.Span in project instrumentation-java by census-instrumentation.
the class TraceProtoUtilsTest method toSpanProto.
@Test
public void toSpanProto() {
SpanData spanData = SpanData.create(spanContext, parentSpanId, /* hasRemoteParent= */
false, SPAN_NAME, Kind.CLIENT, startTimestamp, attributes, annotations, messageEvents, links, CHILD_SPAN_COUNT, status, endTimestamp);
TimeEvent annotationTimeEvent1 = TimeEvent.newBuilder().setAnnotation(TimeEvent.Annotation.newBuilder().setDescription(toTruncatableStringProto(ANNOTATION_TEXT)).setAttributes(Span.Attributes.newBuilder().build()).build()).setTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(eventTimestamp1.getSeconds()).setNanos(eventTimestamp1.getNanos()).build()).build();
TimeEvent annotationTimeEvent2 = TimeEvent.newBuilder().setAnnotation(TimeEvent.Annotation.newBuilder().setDescription(toTruncatableStringProto(ANNOTATION_TEXT)).setAttributes(Span.Attributes.newBuilder().build()).build()).setTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(eventTimestamp3.getSeconds()).setNanos(eventTimestamp3.getNanos()).build()).build();
TimeEvent sentTimeEvent = TimeEvent.newBuilder().setMessageEvent(TimeEvent.MessageEvent.newBuilder().setType(MessageEvent.Type.SENT).setId(sentMessageEvent.getMessageId())).setTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(eventTimestamp2.getSeconds()).setNanos(eventTimestamp2.getNanos()).build()).build();
TimeEvent recvTimeEvent = TimeEvent.newBuilder().setMessageEvent(TimeEvent.MessageEvent.newBuilder().setType(MessageEvent.Type.RECEIVED).setId(recvMessageEvent.getMessageId())).setTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(eventTimestamp1.getSeconds()).setNanos(eventTimestamp1.getNanos()).build()).build();
Span.Links spanLinks = Span.Links.newBuilder().setDroppedLinksCount(DROPPED_LINKS_COUNT).addLink(Span.Link.newBuilder().setType(Span.Link.Type.CHILD_LINKED_SPAN).setTraceId(toByteString(traceId.getBytes())).setSpanId(toByteString(spanId.getBytes())).setAttributes(Span.Attributes.newBuilder().build()).build()).build();
io.opencensus.proto.trace.v1.Status spanStatus = io.opencensus.proto.trace.v1.Status.newBuilder().setCode(com.google.rpc.Code.DEADLINE_EXCEEDED.getNumber()).setMessage("TooSlow").build();
com.google.protobuf.Timestamp startTime = com.google.protobuf.Timestamp.newBuilder().setSeconds(startTimestamp.getSeconds()).setNanos(startTimestamp.getNanos()).build();
com.google.protobuf.Timestamp endTime = com.google.protobuf.Timestamp.newBuilder().setSeconds(endTimestamp.getSeconds()).setNanos(endTimestamp.getNanos()).build();
Span span = TraceProtoUtils.toSpanProto(spanData);
assertThat(span.getName()).isEqualTo(toTruncatableStringProto(SPAN_NAME));
assertThat(span.getTraceId()).isEqualTo(toByteString(traceId.getBytes()));
assertThat(span.getSpanId()).isEqualTo(toByteString(spanId.getBytes()));
assertThat(span.getParentSpanId()).isEqualTo(toByteString(parentSpanId.getBytes()));
assertThat(span.getStartTime()).isEqualTo(startTime);
assertThat(span.getEndTime()).isEqualTo(endTime);
assertThat(span.getKind()).isEqualTo(SpanKind.CLIENT);
assertThat(span.getAttributes().getDroppedAttributesCount()).isEqualTo(DROPPED_ATTRIBUTES_COUNT);
// The generated attributes map contains more values (e.g. agent). We only test what we added.
assertThat(span.getAttributes().getAttributeMapMap()).containsEntry(ATTRIBUTE_KEY_1, AttributeValue.newBuilder().setIntValue(10L).build());
assertThat(span.getAttributes().getAttributeMapMap()).containsEntry(ATTRIBUTE_KEY_2, AttributeValue.newBuilder().setBoolValue(true).build());
assertThat(span.getTimeEvents().getDroppedMessageEventsCount()).isEqualTo(DROPPED_NETWORKEVENTS_COUNT);
assertThat(span.getTimeEvents().getDroppedAnnotationsCount()).isEqualTo(DROPPED_ANNOTATIONS_COUNT);
assertThat(span.getTimeEvents().getTimeEventList()).containsExactly(annotationTimeEvent1, annotationTimeEvent2, sentTimeEvent, recvTimeEvent);
assertThat(span.getLinks()).isEqualTo(spanLinks);
assertThat(span.getStatus()).isEqualTo(spanStatus);
assertThat(span.getSameProcessAsParentSpan()).isEqualTo(BoolValue.of(true));
assertThat(span.getChildSpanCount()).isEqualTo(UInt32Value.newBuilder().setValue(CHILD_SPAN_COUNT).build());
}
use of com.google.devtools.cloudtrace.v2.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 com.google.devtools.cloudtrace.v2.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 com.google.devtools.cloudtrace.v2.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 com.google.devtools.cloudtrace.v2.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"));
}
Aggregations