Search in sources :

Example 1 with Span

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");
}
Also used : Task(io.crnk.test.mock.models.Task) Span(org.springframework.cloud.sleuth.Span) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Span

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);
    }
}
Also used : RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Span(org.springframework.cloud.sleuth.Span)

Example 3 with 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");
}
Also used : Project(io.crnk.test.mock.models.Project) Serializable(java.io.Serializable) Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Span(org.springframework.cloud.sleuth.Span) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Span

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", "?");
}
Also used : Task(io.crnk.test.mock.models.Task) Span(org.springframework.cloud.sleuth.Span) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Span

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");
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Span(org.springframework.cloud.sleuth.Span) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Span (org.springframework.cloud.sleuth.Span)5 Task (io.crnk.test.mock.models.Task)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)1 Project (io.crnk.test.mock.models.Project)1 Serializable (java.io.Serializable)1