use of org.springframework.cloud.sleuth.Span in project crnk-framework by crnk-project.
the class SleuthModuleTest 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);
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.getName());
Assert.assertTrue(callSpan.toString().contains("\"cs\""));
Assert.assertTrue(callSpan.toString().contains("\"cr\""));
assertBinaryAnnotation(callSpan, "http.status_code", "500");
// check server local span
Assert.assertEquals(1, reportedSpans.spans.size());
Span repositorySpan = reportedSpans.spans.get(0);
Assert.assertEquals("crnk:post:/tasks/13", repositorySpan.getName());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan, "lc", "crnk");
assertBinaryAnnotation(repositorySpan, "crnk.query", "?");
assertBinaryAnnotation(repositorySpan, "crnk.status", "EXCEPTION");
}
use of org.springframework.cloud.sleuth.Span in project crnk-framework by crnk-project.
the class SleuthRepositoryFilter method filterRequest.
@Override
public JsonApiResponse filterRequest(RepositoryFilterContext context, RepositoryRequestFilterChain chain) {
RepositoryRequestSpec request = context.getRequest();
String query = SleuthUtil.getQuery(request, moduleContext.getResourceRegistry());
Span span = tracer.createSpan(SleuthUtil.getSpanName(request));
JsonApiResponse result = null;
Exception exception = null;
try {
span.tag("lc", COMPONENT_NAME);
result = chain.doFilter(context);
return result;
} catch (RuntimeException e) {
exception = e;
throw e;
} finally {
boolean resultError = result != null && result.getErrors() != null && result.getErrors().iterator().hasNext();
boolean failed = exception != null || resultError;
String status = failed ? STRING_EXCEPTION : STRING_OK;
span.tag(STATUS_CODE_ANNOTATION, status);
writeQuery(span, query);
writeResults(span, result);
tracer.close(span);
}
}
use of org.springframework.cloud.sleuth.Span in project crnk-framework by crnk-project.
the class SleuthModuleTest method testFindTargets.
@Test
public void testFindTargets() {
RelationshipRepositoryV2<Project, Serializable, Task, Serializable> relRepo = client.getQuerySpecRepository(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);
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("get", callSpan.getName());
Assert.assertTrue(callSpan.toString().contains("\"cs\""));
Assert.assertTrue(callSpan.toString().contains("\"cr\""));
// check server local span
Assert.assertEquals(2, reportedSpans.spans.size());
Span repositorySpan0 = reportedSpans.spans.get(0);
Assert.assertEquals("crnk:get:/tasks", repositorySpan0.getName());
Assert.assertTrue(repositorySpan0.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan0, "lc", "crnk");
assertBinaryAnnotation(repositorySpan0, "crnk.results", "0");
assertBinaryAnnotation(repositorySpan0, "crnk.status", "OK");
Span repositorySpan1 = reportedSpans.spans.get(1);
Assert.assertEquals("crnk:get:/projects/123/tasks", repositorySpan1.getName());
Assert.assertTrue(repositorySpan1.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan1, "lc", "crnk");
assertBinaryAnnotation(repositorySpan1, "crnk.query", "?");
assertBinaryAnnotation(repositorySpan1, "crnk.results", "0");
assertBinaryAnnotation(repositorySpan1, "crnk.status", "OK");
}
use of org.springframework.cloud.sleuth.Span in project crnk-framework by crnk-project.
the class SleuthModuleTest 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);
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.getName());
Assert.assertTrue(callSpan.toString().contains("\"cs\""));
Assert.assertTrue(callSpan.toString().contains("\"cr\""));
// check server local span
Assert.assertEquals(1, reportedSpans.spans.size());
Span repositorySpan = reportedSpans.spans.get(0);
Assert.assertEquals("crnk:post:/tasks/13", repositorySpan.getName());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan, "lc", "crnk");
assertBinaryAnnotation(repositorySpan, "crnk.query", "?");
}
use of org.springframework.cloud.sleuth.Span in project crnk-framework by crnk-project.
the class SleuthModuleTest 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);
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("get", callSpan.getName());
Assert.assertTrue(callSpan.toString().contains("\"cs\""));
Assert.assertTrue(callSpan.toString().contains("\"cr\""));
// check server local span
Assert.assertEquals(1, reportedSpans.spans.size());
Span repositorySpan = reportedSpans.spans.get(0);
Assert.assertEquals("crnk:get:/tasks", repositorySpan.getName());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan, "lc", "crnk");
assertBinaryAnnotation(repositorySpan, "crnk.query", "?filter[tasks][name][EQ]=doe");
assertBinaryAnnotation(repositorySpan, "crnk.results", "0");
assertBinaryAnnotation(repositorySpan, "crnk.status", "OK");
}
Aggregations