use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandlerTest method generateSpan_ErrorStatus.
@Test
public void generateSpan_ErrorStatus() {
SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
"SpanName", /* name */
Kind.CLIENT, /* kind */
Timestamp.create(1505855794, 194009601), /* startTimestamp */
Attributes.create(attributes, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
Status.OUT_OF_RANGE, /* status, any but OK */
Timestamp.create(1505855799, 465726528));
assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data))).isEqualTo("[" + "{" + "\"spanId\":\"9cc1e3049173be09\"," + "\"traceId\":\"d239036e7d5cec11\"," + "\"parentId\":\"8b03ab423da481c5\"," + "\"timestamp\":1505855794194," + "\"duration\":5271," + "\"name\":\"SpanName\"," + "\"type\":\"EXIT\"," + "\"error\":true," + "\"data\":" + "{\"http.url\":\"http://localhost/foo\"}" + "}" + "]");
}
use of io.opencensus.trace.export.SpanData 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 io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class OcAgentTraceExporterHandler method timeLimitedExport.
@Override
public void timeLimitedExport(Collection<SpanData> spanDataList) {
if (exportRpcHandler == null || exportRpcHandler.isCompleted()) {
// If not connected, try to initiate a new connection when a new batch of spans arrive.
// Export RPC doesn't respect the retry interval.
TraceServiceGrpc.TraceServiceStub stub = getTraceServiceStub(endPoint, useInsecure, sslContext);
exportRpcHandler = createExportRpcHandlerAndConnect(stub, node);
}
if (exportRpcHandler == null || exportRpcHandler.isCompleted()) {
// Failed to connect to Agent.
logger.info("Export RPC disconnected, dropping " + spanDataList.size() + " spans.");
exportRpcHandler = null;
} else {
// Connection succeeded, send export request.
ExportTraceServiceRequest.Builder requestBuilder = ExportTraceServiceRequest.newBuilder();
for (SpanData spanData : spanDataList) {
requestBuilder.addSpans(TraceProtoUtils.toSpanProto(spanData));
}
exportRpcHandler.onExport(requestBuilder.build());
}
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandlerTest method generateSpan_ClientKind.
@Test
public void generateSpan_ClientKind() {
SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
"SpanName", /* name */
Kind.CLIENT, /* kind */
Timestamp.create(1505855794, 194009601), /* startTimestamp */
Attributes.create(attributes, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
Status.OK, Timestamp.create(1505855799, 465726528));
assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data))).isEqualTo("[" + "{" + "\"spanId\":\"9cc1e3049173be09\"," + "\"traceId\":\"d239036e7d5cec11\"," + "\"parentId\":\"8b03ab423da481c5\"," + "\"timestamp\":1505855794194," + "\"duration\":5271," + "\"name\":\"SpanName\"," + "\"type\":\"EXIT\"," + "\"data\":" + "{\"http.url\":\"http://localhost/foo\"}" + "}" + "]");
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandlerTest method generateSpan_NoKindAndRemoteParent.
@Test
public void generateSpan_NoKindAndRemoteParent() {
SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
"SpanName", /* name */
null, /* kind */
Timestamp.create(1505855794, 194009601), /* startTimestamp */
Attributes.create(attributes, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
Status.OK, Timestamp.create(1505855799, 465726528));
assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data))).isEqualTo("[" + "{" + "\"spanId\":\"9cc1e3049173be09\"," + "\"traceId\":\"d239036e7d5cec11\"," + "\"parentId\":\"8b03ab423da481c5\"," + "\"timestamp\":1505855794194," + "\"duration\":5271," + "\"name\":\"SpanName\"," + "\"type\":\"ENTRY\"," + "\"data\":" + "{\"http.url\":\"http://localhost/foo\"}" + "}" + "]");
}
Aggregations