use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.
the class AbstractBraveModuleTest method testFindTargets.
@Test
public void testFindTargets() {
RelationshipRepositoryV2<Project, Serializable, Task, Serializable> relRepo = client.getRepositoryForType(Project.class, Task.class);
relRepo.findManyTargets(123L, "tasks", new QuerySpec(Task.class));
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("get", callSpan.name());
Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(2)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan0 = serverSpans.get(0);
Assert.assertEquals("crnk:get:/tasks/", repositorySpan0.name());
Assert.assertTrue(repositorySpan0.toString().contains("\"lc\""));
assertTag(repositorySpan0, "lc", "crnk");
assertTag(repositorySpan0, "crnk.results", "0");
assertTag(repositorySpan0, "crnk.status", "OK");
Span repositorySpan1 = serverSpans.get(1);
Assert.assertEquals("crnk:get:/projects/123/tasks/", repositorySpan1.name());
Assert.assertTrue(repositorySpan1.toString().contains("\"lc\""));
assertTag(repositorySpan1, "lc", "crnk");
assertTag(repositorySpan1, "crnk.query", "?");
assertTag(repositorySpan1, "crnk.results", "0");
assertTag(repositorySpan1, "crnk.status", "OK");
}
use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.
the class AbstractBraveModuleTest method testFindAll.
@Test
public void testFindAll() {
Task task = new Task();
task.setId(13L);
task.setName("myTask");
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "doe"));
taskRepo.findAll(querySpec);
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(isOkHttp ? 1 : 1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("get", callSpan.name());
Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan = serverSpans.get(0);
Assert.assertEquals("crnk:get:/tasks/", repositorySpan.name());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertTag(repositorySpan, "lc", "crnk");
assertTag(repositorySpan, "crnk.query", "?filter[tasks][name][EQ]=doe");
assertTag(repositorySpan, "crnk.results", "0");
assertTag(repositorySpan, "crnk.status", "OK");
}
use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.
the class AbstractBraveModuleTest method testCreate.
@Test
public void testCreate() {
Task task = new Task();
task.setId(13L);
task.setName("myTask");
taskRepo.create(task);
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.name());
Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan = serverSpans.get(0);
Assert.assertEquals("crnk:post:/tasks/13/", repositorySpan.name());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertTag(repositorySpan, "lc", "crnk");
assertTag(repositorySpan, "crnk.query", "?");
}
use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.
the class AbstractBraveModuleTest method testError.
@Test
public void testError() {
Task task = new Task();
task.setId(13L);
try {
taskRepo.create(task);
} catch (Exception e) {
// ok
}
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.name());
Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
assertTag(callSpan, "http.status_code", "500");
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan = serverSpans.get(0);
Assert.assertEquals("crnk:post:/tasks/13/", repositorySpan.name());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertTag(repositorySpan, "lc", "crnk");
assertTag(repositorySpan, "crnk.query", "?");
assertTag(repositorySpan, "crnk.status", "EXCEPTION");
}
use of io.opencensus.proto.trace.v1.Span in project instrumentation-java by census-instrumentation.
the class StackdriverV2ExporterHandler method generateSpan.
@VisibleForTesting
Span generateSpan(SpanData spanData, Map<String, AttributeValue> resourceLabels, Map<String, AttributeValue> fixedAttributes) {
SpanContext context = spanData.getContext();
final String spanIdHex = context.getSpanId().toLowerBase16();
SpanName spanName = SpanName.newBuilder().setProject(projectId).setTrace(context.getTraceId().toLowerBase16()).setSpan(spanIdHex).build();
Span.Builder spanBuilder = Span.newBuilder().setName(spanName.toString()).setSpanId(spanIdHex).setDisplayName(toTruncatableStringProto(toDisplayName(spanData.getName(), spanData.getKind()))).setStartTime(toTimestampProto(spanData.getStartTimestamp())).setAttributes(toAttributesProto(spanData.getAttributes(), resourceLabels, fixedAttributes)).setTimeEvents(toTimeEventsProto(spanData.getAnnotations(), spanData.getMessageEvents()));
io.opencensus.trace.Status status = spanData.getStatus();
if (status != null) {
spanBuilder.setStatus(toStatusProto(status));
}
Timestamp end = spanData.getEndTimestamp();
if (end != null) {
spanBuilder.setEndTime(toTimestampProto(end));
}
spanBuilder.setLinks(toLinksProto(spanData.getLinks()));
Integer childSpanCount = spanData.getChildSpanCount();
if (childSpanCount != null) {
spanBuilder.setChildSpanCount(Int32Value.newBuilder().setValue(childSpanCount).build());
}
if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) {
spanBuilder.setParentSpanId(spanData.getParentSpanId().toLowerBase16());
}
/*@Nullable*/
Boolean hasRemoteParent = spanData.getHasRemoteParent();
if (hasRemoteParent != null) {
spanBuilder.setSameProcessAsParentSpan(BoolValue.of(!hasRemoteParent));
}
return spanBuilder.build();
}
Aggregations