Search in sources :

Example 51 with SpanData

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

the class OpenCensusTracingSpiTest method testNodeJoinTracing.

/**
 * Test checks that node join process is traced correctly in positive case.
 */
@Test
public void testNodeJoinTracing() throws Exception {
    IgniteEx joinedNode = startGrid(GRID_CNT);
    awaitPartitionMapExchange();
    // Consistent id is the same with node name.
    List<String> clusterNodeNames = grid(0).cluster().nodes().stream().map(node -> (String) node.consistentId()).collect(Collectors.toList());
    handler().flush();
    String joinedNodeId = joinedNode.localNode().id().toString();
    // Check existence of Traces.Discovery.NODE_JOIN_REQUEST spans with OK status on all nodes:
    Map<AttributeValue, SpanData> nodeJoinReqSpans = handler().allSpans().filter(span -> DISCOVERY_NODE_JOIN_REQUEST.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> stringAttributeValue(joinedNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toMap(span -> span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.NODE, SpanTags.NAME)), span -> span));
    // NODE_JOIN_REQUEST must be processed at least on coordinator node.
    // For other nodes there is no such guarantee.
    int CRD_IDX = 0;
    clusterNodeNames.stream().filter(node -> node.endsWith(String.valueOf(CRD_IDX))).forEach(nodeName -> Assert.assertTrue(String.format("%s not found on node with name=%s, nodeJoinReqSpans=%s", DISCOVERY_NODE_JOIN_REQUEST, nodeName, nodeJoinReqSpans), nodeJoinReqSpans.containsKey(stringAttributeValue(nodeName))));
    // Check existence of Traces.Discovery.NODE_JOIN_ADD spans with OK status on all nodes:
    for (int i = 0; i <= GRID_CNT; i++) {
        List<SpanData> nodeJoinAddSpans = handler().spansReportedByNode(getTestIgniteInstanceName(i)).filter(span -> DISCOVERY_NODE_JOIN_ADD.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> stringAttributeValue(joinedNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toList());
        Assert.assertTrue(String.format("%s span not found, nodeId=%d", DISCOVERY_NODE_JOIN_ADD, i), !nodeJoinReqSpans.isEmpty());
        nodeJoinAddSpans.forEach(spanData -> {
            SpanData parentSpan = handler().spanById(spanData.getParentSpanId());
            Assert.assertNotNull("Parent span doesn't exist for " + spanData, parentSpan);
            Assert.assertEquals("Parent span name is invalid, parentSpan=" + parentSpan, DISCOVERY_NODE_JOIN_REQUEST.spanName(), parentSpan.getName());
            Assert.assertEquals("Parent span is not related to joined node, parentSpan=" + parentSpan, stringAttributeValue(joinedNodeId), parentSpan.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)));
        });
    }
    // Check existence of Traces.Discovery.NODE_JOIN_FINISH spans with OK status on all nodes:
    for (int i = 0; i <= GRID_CNT; i++) {
        List<SpanData> nodeJoinAddSpans = handler().spansReportedByNode(getTestIgniteInstanceName(i)).filter(span -> DISCOVERY_NODE_JOIN_FINISH.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> stringAttributeValue(joinedNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toList());
        Assert.assertTrue(String.format("%s span not found, nodeId=%d", DISCOVERY_NODE_JOIN_FINISH, i), !nodeJoinReqSpans.isEmpty());
        nodeJoinAddSpans.forEach(spanData -> {
            SpanData parentSpan = handler().spanById(spanData.getParentSpanId());
            Assert.assertNotNull("Parent span doesn't exist for " + spanData, parentSpan);
            Assert.assertEquals("Parent span name is invalid " + parentSpan, DISCOVERY_NODE_JOIN_ADD.spanName(), parentSpan.getName());
            Assert.assertEquals("Parent span is not related to joined node " + parentSpan, stringAttributeValue(joinedNodeId), parentSpan.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)));
        });
    }
}
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) Test(org.junit.Test)

Example 52 with SpanData

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

the class UrlInstrumentationIT method getContent.

@Test(timeout = 60000)
public void getContent() throws Exception {
    URL url = getClass().getResource("some_resource.txt").toURI().toURL();
    Object content = url.getContent();
    assertThat(content).isInstanceOf(InputStream.class);
    assertThat(CharStreams.toString(new InputStreamReader((InputStream) content, Charsets.UTF_8))).isEqualTo("Some resource.");
    SpanData span = testHandler.waitForExport(1).get(0);
    assertThat(span.getName()).isEqualTo("java.net.URL#getContent");
    assertThat(span.getStatus().isOk()).isTrue();
}
Also used : InputStreamReader(java.io.InputStreamReader) SpanData(io.opencensus.trace.export.SpanData) InputStream(java.io.InputStream) URL(java.net.URL) Test(org.junit.Test)

Example 53 with SpanData

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

the class InProcessSampledSpanStoreImpl method getErrorSampledSpans.

@Override
public Collection<SpanData> getErrorSampledSpans(ErrorFilter filter) {
    int numSpansToReturn = filter.getMaxSpansToReturn() == 0 ? MAX_PER_SPAN_NAME_SAMPLES : filter.getMaxSpansToReturn();
    List<RecordEventsSpanImpl> spans = Collections.emptyList();
    // the lock.
    synchronized (samples) {
        PerSpanNameSamples perSpanNameSamples = samples.get(filter.getSpanName());
        if (perSpanNameSamples != null) {
            spans = perSpanNameSamples.getErrorSamples(filter.getCanonicalCode(), numSpansToReturn);
        }
    }
    List<SpanData> ret = new ArrayList<SpanData>(spans.size());
    for (RecordEventsSpanImpl span : spans) {
        ret.add(span.toSpanData());
    }
    return Collections.unmodifiableList(ret);
}
Also used : SpanData(io.opencensus.trace.export.SpanData) ArrayList(java.util.ArrayList) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl)

Example 54 with SpanData

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

the class InProcessSampledSpanStoreImpl method getLatencySampledSpans.

@Override
public Collection<SpanData> getLatencySampledSpans(LatencyFilter filter) {
    int numSpansToReturn = filter.getMaxSpansToReturn() == 0 ? MAX_PER_SPAN_NAME_SAMPLES : filter.getMaxSpansToReturn();
    List<RecordEventsSpanImpl> spans = Collections.emptyList();
    // the lock.
    synchronized (samples) {
        PerSpanNameSamples perSpanNameSamples = samples.get(filter.getSpanName());
        if (perSpanNameSamples != null) {
            spans = perSpanNameSamples.getLatencySamples(filter.getLatencyLowerNs(), filter.getLatencyUpperNs(), numSpansToReturn);
        }
    }
    List<SpanData> ret = new ArrayList<SpanData>(spans.size());
    for (RecordEventsSpanImpl span : spans) {
        ret.add(span.toSpanData());
    }
    return Collections.unmodifiableList(ret);
}
Also used : SpanData(io.opencensus.trace.export.SpanData) ArrayList(java.util.ArrayList) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl)

Example 55 with SpanData

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

the class JaegerExporterHandlerTest method convertErrorSpanDataToJaegerThriftSpan.

@Test
public void convertErrorSpanDataToJaegerThriftSpan() throws SenderException {
    long startTime = 1519629870001L;
    long endTime = 1519630148002L;
    String statusMessage = "timeout";
    SpanData spanData = SpanData.create(sampleSpanContext(), SpanId.fromBytes(new byte[] { (byte) 0x7F, FF, FF, FF, FF, FF, FF, FF }), true, "test", Kind.SERVER, Timestamp.fromMillis(startTime), SpanData.Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0), SpanData.TimedEvents.create(Collections.<TimedEvent<Annotation>>emptyList(), 0), SpanData.TimedEvents.create(Collections.<TimedEvent<MessageEvent>>emptyList(), 0), SpanData.Links.create(Collections.<Link>emptyList(), 0), 0, Status.DEADLINE_EXCEEDED.withDescription(statusMessage), Timestamp.fromMillis(endTime));
    handler.export(singletonList(spanData));
    verify(mockSender).send(eq(process), captor.capture());
    List<Span> spans = captor.getValue();
    assertThat(spans.size()).isEqualTo(1);
    Span span = spans.get(0);
    assertThat(span.tags.size()).isEqualTo(3);
    assertThat(span.tags).containsExactly(new Tag(JaegerExporterHandler.SPAN_KIND, TagType.STRING).setVStr("server"), new Tag(JaegerExporterHandler.STATUS_CODE, TagType.LONG).setVLong(4), new Tag(JaegerExporterHandler.STATUS_MESSAGE, TagType.STRING).setVStr(statusMessage));
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) TimedEvent(io.opencensus.trace.export.SpanData.TimedEvent) Tag(io.jaegertracing.thriftjava.Tag) Span(io.jaegertracing.thriftjava.Span) 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