Search in sources :

Example 36 with Span

use of zipkin2.proto3.Span in project spring-cloud-sleuth by spring-cloud.

the class TraceFilterWebIntegrationTests method should_not_create_a_span_for_error_controller.

@Test
public void should_not_create_a_span_for_error_controller() {
    try {
        new RestTemplate().getForObject("http://localhost:" + port() + "/", String.class);
        BDDAssertions.fail("should fail due to runtime exception");
    } catch (Exception e) {
    }
    then(Tracing.current().tracer().currentSpan()).isNull();
    then(this.accumulator.getSpans()).hasSize(1);
    Span fromFirstTraceFilterFlow = this.accumulator.getSpans().get(0);
    then(fromFirstTraceFilterFlow.tags()).containsEntry("http.status_code", "500").containsEntry("http.method", "GET").containsEntry("mvc.controller.class", "ExceptionThrowingController").containsEntry("error", "Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception");
    // issue#714
    String hex = fromFirstTraceFilterFlow.traceId();
    String[] split = capture.toString().split("\n");
    List<String> list = Arrays.stream(split).filter(s -> s.contains("Uncaught exception thrown")).filter(s -> s.contains(hex + "," + hex + ",true]")).collect(Collectors.toList());
    then(list).isNotEmpty();
}
Also used : BDDAssertions(org.assertj.core.api.BDDAssertions) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Span(zipkin2.Span) DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) Sampler(brave.sampler.Sampler) After(org.junit.After) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) SpringRunner(org.springframework.test.context.junit4.SpringRunner) OutputCapture(org.springframework.boot.test.rule.OutputCapture) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) RestTemplate(org.springframework.web.client.RestTemplate) Before(org.junit.Before) HttpAdapter(brave.http.HttpAdapter) Tracing(brave.Tracing) HttpSampler(brave.http.HttpSampler) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Test(org.junit.Test) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) Configuration(org.springframework.context.annotation.Configuration) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) List(java.util.List) Rule(org.junit.Rule) Assertions.fail(org.assertj.core.api.Assertions.fail) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Environment(org.springframework.core.env.Environment) ResponseEntity(org.springframework.http.ResponseEntity) Pattern(java.util.regex.Pattern) Bean(org.springframework.context.annotation.Bean) RestTemplate(org.springframework.web.client.RestTemplate) Span(zipkin2.Span) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with Span

use of zipkin2.proto3.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");
}
Also used : Project(io.crnk.monitor.brave.mock.models.Project) Serializable(java.io.Serializable) Task(io.crnk.monitor.brave.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Span(zipkin2.Span) Test(org.junit.Test)

Example 38 with Span

use of zipkin2.proto3.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");
}
Also used : Task(io.crnk.monitor.brave.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Span(zipkin2.Span) Test(org.junit.Test)

Example 39 with Span

use of zipkin2.proto3.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", "?");
}
Also used : Task(io.crnk.monitor.brave.mock.models.Task) Span(zipkin2.Span) Test(org.junit.Test)

Example 40 with Span

use of zipkin2.proto3.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");
}
Also used : Task(io.crnk.monitor.brave.mock.models.Task) Span(zipkin2.Span) Test(org.junit.Test)

Aggregations

Span (zipkin2.Span)290 Test (org.junit.Test)203 Test (org.junit.jupiter.api.Test)69 Endpoint (zipkin2.Endpoint)62 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)41 ArrayList (java.util.ArrayList)29 V1Span (zipkin2.v1.V1Span)23 List (java.util.List)19 Map (java.util.Map)18 Annotation (zipkin2.Annotation)13 AggregateCall (zipkin2.internal.AggregateCall)13 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)12 IOException (java.io.IOException)10 LinkedHashMap (java.util.LinkedHashMap)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 Arrays.asList (java.util.Arrays.asList)9 Span (com.google.devtools.cloudtrace.v2.Span)8 Trace (com.google.devtools.cloudtrace.v1.Trace)7 Call (zipkin2.Call)7 Span (zipkin2.proto3.Span)7