Search in sources :

Example 6 with AttributeValue

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

the class OcAgentTraceExporterIntegrationTest method doWork.

private void doWork(String spanName, int i) {
    try (Scope scope = tracer.spanBuilder(spanName).startScopedSpan()) {
        // Simulate some work.
        Span span = tracer.getCurrentSpan();
        try {
            Thread.sleep(10L);
        } catch (InterruptedException e) {
            span.setStatus(Status.INTERNAL.withDescription(e.toString()));
        }
        Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
        attributes.put("inner work iteration number", AttributeValue.longAttributeValue(i));
        span.addAnnotation("Invoking doWork", attributes);
    }
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) Scope(io.opencensus.common.Scope) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Span(io.opencensus.trace.Span)

Example 7 with AttributeValue

use of io.opencensus.trace.AttributeValue in project ignite by apache.

the class AbstractTracingTest method checkSpanExistences.

/**
 * Checks that there's at least one span with given spanType and attributes.
 *
 * @param spanType Span type to be found.
 * @param expAttrs Expected attributes.
 * @return {@code true} if Span with given type and attributes was found, false otherwise.
 */
boolean checkSpanExistences(SpanType spanType, /* tagName: tagValue*/
Map<String, String> expAttrs) {
    java.util.List<SpanData> gotSpans = hnd.allSpans().filter(span -> spanType.spanName().equals(span.getName())).collect(Collectors.toList());
    for (SpanData specificTypeSpans : gotSpans) {
        Map<String, AttributeValue> attrs = specificTypeSpans.getAttributes().getAttributeMap();
        boolean matchFound = true;
        for (Map.Entry<String, String> entry : expAttrs.entrySet()) {
            if (!entry.getValue().equals(attributeValueToString(attrs.get(entry.getKey())))) {
                matchFound = false;
                break;
            }
        }
        if (matchFound && expAttrs.size() == attrs.size())
            return true;
    }
    return false;
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) EXCHANGE(org.apache.ignite.spi.tracing.Scope.EXCHANGE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) BeforeClass(org.junit.BeforeClass) AttributeValue(io.opencensus.trace.AttributeValue) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) SpanData(io.opencensus.trace.export.SpanData) Samplers(io.opencensus.trace.samplers.Samplers) ArrayList(java.util.ArrayList) Map(java.util.Map) After(org.junit.After) SpanId(io.opencensus.trace.SpanId) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) LinkedList(java.util.LinkedList) Tracing(io.opencensus.trace.Tracing) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) COMMUNICATION(org.apache.ignite.spi.tracing.Scope.COMMUNICATION) Before(org.junit.Before) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Scope(org.apache.ignite.spi.tracing.Scope) OpenCensusTraceExporter(org.apache.ignite.spi.tracing.opencensus.OpenCensusTraceExporter) Collectors(java.util.stream.Collectors) Span(io.opencensus.trace.Span) SpanExporter(io.opencensus.trace.export.SpanExporter) TX(org.apache.ignite.spi.tracing.Scope.TX) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) Functions(io.opencensus.common.Functions) Collections(java.util.Collections) AttributeValue.stringAttributeValue(io.opencensus.trace.AttributeValue.stringAttributeValue) TracingConfigurationManager(org.apache.ignite.spi.tracing.TracingConfigurationManager) AttributeValue(io.opencensus.trace.AttributeValue) AttributeValue.stringAttributeValue(io.opencensus.trace.AttributeValue.stringAttributeValue) SpanData(io.opencensus.trace.export.SpanData) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with AttributeValue

use of io.opencensus.trace.AttributeValue 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)

Example 9 with AttributeValue

use of io.opencensus.trace.AttributeValue 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 10 with AttributeValue

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

the class JaegerExporterHandler method attributesToTags.

private static List<Tag> attributesToTags(final Map<String, AttributeValue> attributes, @Nullable final Tag extraTag) {
    final List<Tag> tags = Lists.newArrayListWithExpectedSize(attributes.size() + 1);
    for (final Map.Entry<String, AttributeValue> entry : attributes.entrySet()) {
        final Tag tag = entry.getValue().match(stringAttributeConverter, booleanAttributeConverter, longAttributeConverter, doubleAttributeConverter, defaultAttributeConverter);
        tag.setKey(entry.getKey());
        tags.add(tag);
    }
    if (extraTag != null) {
        tags.add(extraTag);
    }
    return tags;
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) Tag(io.jaegertracing.thriftjava.Tag) Map(java.util.Map)

Aggregations

AttributeValue (io.opencensus.trace.AttributeValue)15 SpanData (io.opencensus.trace.export.SpanData)11 Test (org.junit.Test)8 Status (io.opencensus.trace.Status)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Link (io.opencensus.trace.Link)4 SpanContext (io.opencensus.trace.SpanContext)4 List (java.util.List)4 Timestamp (io.opencensus.common.Timestamp)3 AttributeValue.stringAttributeValue (io.opencensus.trace.AttributeValue.stringAttributeValue)3 SpanId (io.opencensus.trace.SpanId)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Scope (org.apache.ignite.spi.tracing.Scope)3 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)3 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)3 Tag (io.jaegertracing.thriftjava.Tag)2 Span (io.opencensus.trace.Span)2 TraceParams (io.opencensus.trace.config.TraceParams)2