use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class TraceWebAsyncClientAutoConfigurationTest method should_close_span_upon_success_callback.
@Test(timeout = 10000)
@Order(1)
public void should_close_span_upon_success_callback() throws ExecutionException, InterruptedException {
tracer = Tracing.getTracer();
Span initialSpan = tracer.spanBuilder("initial").startSpan();
try (Scope ws = tracer.withSpan(initialSpan)) {
ListenableFuture<ResponseEntity<String>> future = asyncRestTemplate.getForEntity("http://localhost:" + port() + "/async", String.class);
String result = future.get().getBody();
assertThat(result).isEqualTo("async");
} finally {
initialSpan.end();
}
// 3 spans are initial, client, server.
List<SpanData> spans = handler.waitForExport(3);
SpanData clientSpan = null;
for (SpanData span : spans) {
if (span.getKind() == CLIENT) {
clientSpan = span;
assertThat(clientSpan.getName()).isEqualTo("/async");
assertThat(clientSpan.getStatus().isOk()).isTrue();
assertThat(clientSpan.getAttributes().getAttributeMap().get(HttpTraceAttributeConstants.HTTP_METHOD)).isEqualTo(AttributeValue.stringAttributeValue("GET"));
assertThat(clientSpan.getAttributes().getAttributeMap().get(HttpTraceAttributeConstants.HTTP_HOST)).isEqualTo(AttributeValue.stringAttributeValue("localhost"));
assertThat(clientSpan.getAttributes().getAttributeMap().get(HttpTraceAttributeConstants.HTTP_PATH)).isEqualTo(AttributeValue.stringAttributeValue("/async"));
assertThat(clientSpan.getKind()).isEqualTo(CLIENT);
break;
}
}
assertThat(clientSpan).isNotNull();
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandlerTest method generateSpan_NullStatus.
@Test
public void generateSpan_NullStatus() {
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 */
null, /* status */
Timestamp.create(1505855799, 465726528));
assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data))).isEqualTo("[]");
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandlerTest method generateSpan_ServerKind.
@Test
public void generateSpan_ServerKind() {
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.SERVER, /* 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\"}" + "}" + "]");
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandlerTest method generateSpan_MultipleAttributes.
@Test
public void generateSpan_MultipleAttributes() {
Map<String, AttributeValue> multipleAttributes = ImmutableMap.of("http.url", AttributeValue.stringAttributeValue("http://localhost/foo"), "http.method", AttributeValue.stringAttributeValue("GET"));
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(multipleAttributes, 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\"," + "\"http.method\":\"GET\"" + "}" + "}" + "]");
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class ZipkinExporterHandlerTest 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()), // TODO SpanId.fromLowerBase16
SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
"Sent.helloworld.Greeter.SayHello", /* 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(ZipkinExporterHandler.generateSpan(data, localEndpoint)).isEqualTo(Span.newBuilder().traceId(TRACE_ID).parentId(PARENT_SPAN_ID).id(SPAN_ID).kind(Span.Kind.CLIENT).name(data.getName()).timestamp(1505855794000000L + 194009601L / 1000).duration((1505855799000000L + 465726528L / 1000) - (1505855794000000L + 194009601L / 1000)).localEndpoint(localEndpoint).addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED").addAnnotation(1505855799000000L + 459486280L / 1000, "SENT").putTag(ZipkinExporterHandler.STATUS_CODE, "OK").build());
}
Aggregations