Search in sources :

Example 66 with SpanData

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();
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Scope(io.opencensus.common.Scope) SpanData(io.opencensus.trace.export.SpanData) Span(io.opencensus.trace.Span) Order(org.springframework.core.annotation.Order) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 67 with SpanData

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("[]");
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 68 with SpanData

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\"}" + "}" + "]");
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 69 with SpanData

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\"" + "}" + "}" + "]");
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 70 with SpanData

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());
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Aggregations

SpanData (io.opencensus.trace.export.SpanData)86 Test (org.junit.Test)74 RecordEventsSpanImpl (io.opencensus.implcore.trace.RecordEventsSpanImpl)18 Link (io.opencensus.trace.Link)17 AttributeValue (io.opencensus.trace.AttributeValue)13 Collectors (java.util.stream.Collectors)13 Scope (org.apache.ignite.spi.tracing.Scope)13 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)13 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)13 TracingSpi (org.apache.ignite.spi.tracing.TracingSpi)13 IgniteEx (org.apache.ignite.internal.IgniteEx)12 SAMPLING_RATE_ALWAYS (org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS)12 OpenCensusTracingSpi (org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi)12 SpanId (io.opencensus.trace.SpanId)11 Collections (java.util.Collections)9 SpanType (org.apache.ignite.internal.processors.tracing.SpanType)9 TX (org.apache.ignite.spi.tracing.Scope.TX)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8 Set (java.util.Set)8