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);
}
}
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;
}
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()))));
}
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)));
});
}
}
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;
}
Aggregations