Search in sources :

Example 36 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class SpanExporterImplTest method exportSpansToMultipleServices.

@Test
public void exportSpansToMultipleServices() {
    SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    spanExporter.registerHandler("test.service", serviceHandler);
    TestHandler serviceHandler2 = new TestHandler();
    spanExporter.registerHandler("test.service2", serviceHandler2);
    RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2);
    List<SpanData> exported1 = serviceHandler.waitForExport(2);
    List<SpanData> exported2 = serviceHandler2.waitForExport(2);
    assertThat(exported1).containsExactly(span1.toSpanData(), span2.toSpanData());
    assertThat(exported2).containsExactly(span1.toSpanData(), span2.toSpanData());
}
Also used : StartEndHandler(io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler) SpanData(io.opencensus.trace.export.SpanData) TestHandler(io.opencensus.testing.export.TestHandler) StartEndHandlerImpl(io.opencensus.implcore.trace.StartEndHandlerImpl) SimpleEventQueue(io.opencensus.implcore.internal.SimpleEventQueue) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 37 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class SpanExporterImplTest method exportNotSampledSpans.

@Test
public void exportNotSampledSpans() {
    SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    spanExporter.registerHandler("test.service", serviceHandler);
    RecordEventsSpanImpl span1 = createNotSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2);
    // Spans are recorded and exported in the same order as they are ended, we test that a non
    // sampled span is not exported by creating and ending a sampled span after a non sampled span
    // and checking that the first exported span is the sampled span (the non sampled did not get
    // exported).
    List<SpanData> exported = serviceHandler.waitForExport(1);
    // Need to check this because otherwise the variable span1 is unused, other option is to not
    // have a span1 variable.
    assertThat(exported).doesNotContain(span1.toSpanData());
    assertThat(exported).containsExactly(span2.toSpanData());
}
Also used : StartEndHandler(io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler) SpanData(io.opencensus.trace.export.SpanData) StartEndHandlerImpl(io.opencensus.implcore.trace.StartEndHandlerImpl) SimpleEventQueue(io.opencensus.implcore.internal.SimpleEventQueue) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 38 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class SpanExporterImplTest method exportNotSampledSpansFlushed.

@Test(timeout = 10000L)
public void exportNotSampledSpansFlushed() {
    // Set the export delay to zero, for no timeout, in order to confirm the #flush() below works
    SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(0, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    spanExporter.registerHandler("test.service", serviceHandler);
    RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2);
    // Force a flush, without this, the #waitForExport() call below would block indefinitely.
    spanExporter.flush();
    List<SpanData> exported = serviceHandler.waitForExport(1);
    assertThat(exported).containsExactly(span2.toSpanData());
}
Also used : StartEndHandler(io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler) SpanData(io.opencensus.trace.export.SpanData) StartEndHandlerImpl(io.opencensus.implcore.trace.StartEndHandlerImpl) SimpleEventQueue(io.opencensus.implcore.internal.SimpleEventQueue) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 39 with SpanData

use of io.opencensus.trace.export.SpanData in project ignite by apache.

the class OpenCensusTracingSpiTest method testPartitionsMapExchangeTracing.

/**
 * Test checks that PME process in case of node left discovery event is traced correctly in positive case.
 */
@Test
public void testPartitionsMapExchangeTracing() throws Exception {
    long curTopVer = grid(0).cluster().topologyVersion();
    String leftNodeId = grid(GRID_CNT - 1).localNode().id().toString();
    stopGrid(GRID_CNT - 1);
    awaitPartitionMapExchange();
    handler().flush();
    // Check PME for NODE_LEFT event on remaining nodes:
    for (int i = 0; i < GRID_CNT - 1; i++) {
        List<SpanData> exchFutSpans = handler().spansReportedByNode(getTestIgniteInstanceName(i)).filter(span -> EXCHANGE_FUTURE.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> AttributeValue.stringAttributeValue(String.valueOf(EventType.EVT_NODE_LEFT)).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT, SpanTags.TYPE)))).filter(span -> stringAttributeValue(leftNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toList());
        Assert.assertTrue(String.format("%s span not found (or more than 1), nodeId=%d, exchFutSpans=%s", EXCHANGE_FUTURE, i, exchFutSpans), exchFutSpans.size() == 1);
        exchFutSpans.forEach(span -> {
            SpanData parentSpan = handler().spanById(span.getParentSpanId());
            Assert.assertNotNull("Parent span doesn't exist for " + span, parentSpan);
            Assert.assertEquals("Parent span name is invalid " + parentSpan, DISCOVERY_NODE_LEFT.spanName(), parentSpan.getName());
            Assert.assertEquals("Parent span is not related to joined node " + parentSpan, stringAttributeValue(leftNodeId), parentSpan.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)));
            Assert.assertEquals("Exchange future major topology version is invalid " + span, AttributeValue.stringAttributeValue(String.valueOf(curTopVer + 1)), span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.RESULT, SpanTags.TOPOLOGY_VERSION, SpanTags.MAJOR)));
            Assert.assertEquals("Exchange future minor version is invalid " + span, AttributeValue.stringAttributeValue("0"), span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.RESULT, SpanTags.TOPOLOGY_VERSION, SpanTags.MINOR)));
        });
    }
}
Also used : DISCOVERY_NODE_LEFT(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_LEFT) AttributeValue(io.opencensus.trace.AttributeValue) COMMUNICATION_REGULAR_PROCESS(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_REGULAR_PROCESS) SOCKET_WRITE_BYTES(org.apache.ignite.internal.processors.tracing.SpanTags.SOCKET_WRITE_BYTES) COMMUNICATION_JOB_EXECUTE_REQUEST(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_JOB_EXECUTE_REQUEST) CUSTOM_JOB_CALL(org.apache.ignite.internal.processors.tracing.SpanType.CUSTOM_JOB_CALL) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) COMMUNICATION_SOCKET_READ(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_SOCKET_READ) Map(java.util.Map) DISCOVERY_NODE_JOIN_ADD(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_JOIN_ADD) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) DISCOVERY_NODE_JOIN_REQUEST(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_JOIN_REQUEST) EXCHANGE_FUTURE(org.apache.ignite.internal.processors.tracing.SpanType.EXCHANGE_FUTURE) Status(io.opencensus.trace.Status) EventType(org.apache.ignite.events.EventType) SpanTags(org.apache.ignite.internal.processors.tracing.SpanTags) DISCOVERY_NODE_JOIN_FINISH(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_JOIN_FINISH) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Integer.parseInt(java.lang.Integer.parseInt) COMMUNICATION_SOCKET_WRITE(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_SOCKET_WRITE) DISCOVERY_CUSTOM_EVENT(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_CUSTOM_EVENT) List(java.util.List) COMMUNICATION_JOB_EXECUTE_RESPONSE(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_JOB_EXECUTE_RESPONSE) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) MTC(org.apache.ignite.internal.processors.tracing.MTC) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) Assert(org.junit.Assert) AttributeValue.stringAttributeValue(io.opencensus.trace.AttributeValue.stringAttributeValue) SpanData(io.opencensus.trace.export.SpanData) Test(org.junit.Test)

Example 40 with SpanData

use of io.opencensus.trace.export.SpanData in project ignite by apache.

the class OpenCensusTracingSpiTest method testCommunicationMessages.

/**
 * @throws Exception if failed.
 */
@Test
public void testCommunicationMessages() throws Exception {
    IgniteEx ignite = grid(0);
    IgniteEx ignite1 = grid(1);
    try (MTC.TraceSurroundings ignore = MTC.support(ignite.context().tracing().create(CUSTOM_JOB_CALL))) {
        ignite.compute(ignite.cluster().forNode(ignite1.localNode())).withNoFailover().call(() -> "");
    }
    handler().flush();
    SpanData jobSpan = handler().spanByName(CUSTOM_JOB_CALL.spanName());
    List<SpanData> data = handler().unrollByParent(jobSpan);
    List<AttributeValue> nodejobMsgTags = data.stream().filter(it -> it.getAttributes().getAttributeMap().containsKey(SpanTags.MESSAGE)).map(it -> it.getAttributes().getAttributeMap().get(SpanTags.MESSAGE)).collect(Collectors.toList());
    List<String> nodejobTraces = data.stream().map(SpanData::getName).collect(Collectors.toList());
    assertEquals(nodejobTraces.toString(), 7, nodejobTraces.size());
    assertEquals(1, nodejobTraces.stream().filter(it -> it.contains(CUSTOM_JOB_CALL.spanName())).count());
    List<SpanData> sockWriteTraces = data.stream().filter(span -> span.getName().contains(COMMUNICATION_SOCKET_WRITE.spanName())).collect(Collectors.toList());
    // request + response
    assertEquals(2, sockWriteTraces.size());
    sockWriteTraces.forEach(span -> assertTrue(parseInt(attributeValueToString(span.getAttributes().getAttributeMap().get(SOCKET_WRITE_BYTES))) > 0));
    // request + response
    assertEquals(2, nodejobTraces.stream().filter(it -> it.contains(COMMUNICATION_SOCKET_READ.spanName())).count());
    // request + response
    assertEquals(2, nodejobTraces.stream().filter(it -> it.contains(COMMUNICATION_REGULAR_PROCESS.spanName())).count());
    assertTrue(nodejobMsgTags.stream().anyMatch(it -> it.equals(stringAttributeValue(COMMUNICATION_JOB_EXECUTE_REQUEST.spanName()))));
    assertTrue(nodejobMsgTags.stream().anyMatch(it -> it.equals(stringAttributeValue(COMMUNICATION_JOB_EXECUTE_RESPONSE.spanName()))));
}
Also used : DISCOVERY_NODE_LEFT(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_LEFT) AttributeValue(io.opencensus.trace.AttributeValue) COMMUNICATION_REGULAR_PROCESS(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_REGULAR_PROCESS) SOCKET_WRITE_BYTES(org.apache.ignite.internal.processors.tracing.SpanTags.SOCKET_WRITE_BYTES) COMMUNICATION_JOB_EXECUTE_REQUEST(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_JOB_EXECUTE_REQUEST) CUSTOM_JOB_CALL(org.apache.ignite.internal.processors.tracing.SpanType.CUSTOM_JOB_CALL) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) COMMUNICATION_SOCKET_READ(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_SOCKET_READ) Map(java.util.Map) DISCOVERY_NODE_JOIN_ADD(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_JOIN_ADD) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) DISCOVERY_NODE_JOIN_REQUEST(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_JOIN_REQUEST) EXCHANGE_FUTURE(org.apache.ignite.internal.processors.tracing.SpanType.EXCHANGE_FUTURE) Status(io.opencensus.trace.Status) EventType(org.apache.ignite.events.EventType) SpanTags(org.apache.ignite.internal.processors.tracing.SpanTags) DISCOVERY_NODE_JOIN_FINISH(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_JOIN_FINISH) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Integer.parseInt(java.lang.Integer.parseInt) COMMUNICATION_SOCKET_WRITE(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_SOCKET_WRITE) DISCOVERY_CUSTOM_EVENT(org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_CUSTOM_EVENT) List(java.util.List) COMMUNICATION_JOB_EXECUTE_RESPONSE(org.apache.ignite.internal.processors.tracing.SpanType.COMMUNICATION_JOB_EXECUTE_RESPONSE) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) MTC(org.apache.ignite.internal.processors.tracing.MTC) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) Assert(org.junit.Assert) AttributeValue.stringAttributeValue(io.opencensus.trace.AttributeValue.stringAttributeValue) AttributeValue(io.opencensus.trace.AttributeValue) AttributeValue.stringAttributeValue(io.opencensus.trace.AttributeValue.stringAttributeValue) SpanData(io.opencensus.trace.export.SpanData) IgniteEx(org.apache.ignite.internal.IgniteEx) MTC(org.apache.ignite.internal.processors.tracing.MTC) 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