Search in sources :

Example 1 with TimeEvent

use of com.google.devtools.cloudtrace.v2.Span.TimeEvent in project instrumentation-java by census-instrumentation.

the class StackdriverV2ExporterHandler method toTimeAnnotationProto.

private static TimeEvent toTimeAnnotationProto(TimedEvent<Annotation> timedEvent) {
    TimeEvent.Builder timeEventBuilder = TimeEvent.newBuilder().setTime(toTimestampProto(timedEvent.getTimestamp()));
    Annotation annotation = timedEvent.getEvent();
    timeEventBuilder.setAnnotation(TimeEvent.Annotation.newBuilder().setDescription(toTruncatableStringProto(annotation.getDescription())).setAttributes(toAttributesBuilderProto(annotation.getAttributes(), 0)).build());
    return timeEventBuilder.build();
}
Also used : TimeEvent(com.google.devtools.cloudtrace.v2.Span.TimeEvent) Annotation(io.opencensus.trace.Annotation)

Example 2 with TimeEvent

use of com.google.devtools.cloudtrace.v2.Span.TimeEvent in project instrumentation-java by census-instrumentation.

the class StackdriverV2ExporterHandlerProtoTest method generateSpan.

@Test
public void generateSpan() {
    SpanData spanData = SpanData.create(spanContext, parentSpanId, /* hasRemoteParent= */
    true, SPAN_NAME, null, startTimestamp, attributes, annotations, messageEvents, links, CHILD_SPAN_COUNT, status, endTimestamp);
    TimeEvent annotationTimeEvent1 = TimeEvent.newBuilder().setAnnotation(TimeEvent.Annotation.newBuilder().setDescription(TruncatableString.newBuilder().setValue(ANNOTATION_TEXT).build()).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(TruncatableString.newBuilder().setValue(ANNOTATION_TEXT).build()).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(TRACE_ID).setSpanId(SPAN_ID).setAttributes(Span.Attributes.newBuilder().build()).build()).build();
    com.google.rpc.Status spanStatus = com.google.rpc.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 = handler.generateSpan(spanData, EMPTY_RESOURCE_LABELS, Collections.<String, AttributeValue>emptyMap());
    assertThat(span.getName()).isEqualTo(SD_SPAN_NAME);
    assertThat(span.getSpanId()).isEqualTo(SPAN_ID);
    assertThat(span.getParentSpanId()).isEqualTo(PARENT_SPAN_ID);
    assertThat(span.getDisplayName()).isEqualTo(TruncatableString.newBuilder().setValue(SPAN_NAME).build());
    assertThat(span.getStartTime()).isEqualTo(startTime);
    assertThat(span.getEndTime()).isEqualTo(endTime);
    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());
    // TODO(@Hailong): add stack trace test in the future.
    assertThat(span.getStackTrace()).isEqualTo(StackTrace.newBuilder().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(com.google.protobuf.BoolValue.of(false));
    assertThat(span.getChildSpanCount()).isEqualTo(Int32Value.newBuilder().setValue(CHILD_SPAN_COUNT).build());
}
Also used : SpanData(io.opencensus.trace.export.SpanData) TimeEvent(com.google.devtools.cloudtrace.v2.Span.TimeEvent) Span(com.google.devtools.cloudtrace.v2.Span) Test(org.junit.Test)

Example 3 with TimeEvent

use of com.google.devtools.cloudtrace.v2.Span.TimeEvent 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());
}
Also used : SpanData(io.opencensus.trace.export.SpanData) TimeEvent(io.opencensus.proto.trace.v1.Span.TimeEvent) Span(io.opencensus.proto.trace.v1.Span) Test(org.junit.Test)

Example 4 with TimeEvent

use of com.google.devtools.cloudtrace.v2.Span.TimeEvent in project instrumentation-java by census-instrumentation.

the class TraceProtoUtils method toTimeAnnotationProto.

private static TimeEvent toTimeAnnotationProto(TimedEvent<Annotation> timedEvent) {
    TimeEvent.Builder timeEventBuilder = TimeEvent.newBuilder().setTime(toTimestampProto(timedEvent.getTimestamp()));
    Annotation annotation = timedEvent.getEvent();
    timeEventBuilder.setAnnotation(TimeEvent.Annotation.newBuilder().setDescription(toTruncatableStringProto(annotation.getDescription())).setAttributes(toAttributesBuilderProto(annotation.getAttributes(), 0)).build());
    return timeEventBuilder.build();
}
Also used : TimeEvent(io.opencensus.proto.trace.v1.Span.TimeEvent) Annotation(io.opencensus.trace.Annotation)

Aggregations

TimeEvent (com.google.devtools.cloudtrace.v2.Span.TimeEvent)2 TimeEvent (io.opencensus.proto.trace.v1.Span.TimeEvent)2 Annotation (io.opencensus.trace.Annotation)2 SpanData (io.opencensus.trace.export.SpanData)2 Test (org.junit.Test)2 Span (com.google.devtools.cloudtrace.v2.Span)1 Span (io.opencensus.proto.trace.v1.Span)1