use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractTracingClientTest method testErrorUnknownHostException.
@Test
public void testErrorUnknownHostException() {
String url = "http://nonexisting.example.com";
try {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setInterceptors(Collections.<ClientHttpRequestInterceptor>singletonList(new TracingRestTemplateInterceptor(mockTracer)));
restTemplate.getForEntity(url, String.class);
} catch (ResourceAccessException ex) {
// ok UnknownHostException
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals("GET", mockSpan.operationName());
Assert.assertEquals(5, mockSpan.tags().size());
Assert.assertEquals(RestTemplateSpanDecorator.StandardTags.COMPONENT_NAME, mockSpan.tags().get(Tags.COMPONENT.getKey()));
Assert.assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(url, mockSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey()));
Assert.assertEquals(1, mockSpan.logEntries().size());
Assert.assertEquals(2, mockSpan.logEntries().get(0).fields().size());
Assert.assertEquals(Tags.ERROR.getKey(), mockSpan.logEntries().get(0).fields().get("event"));
Assert.assertNotNull(mockSpan.logEntries().get(0).fields().get("error.object"));
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testView.
@Test
public void testView() {
{
getRestTemplate().getForEntity("/view", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("view", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/view"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(200, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testFilterException.
@Test
public void testFilterException() throws Exception {
{
getRestTemplate().getForEntity(ExceptionFilter.EXCEPTION_URL, String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("GET", span.operationName());
Assert.assertEquals(6, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl(ExceptionFilter.EXCEPTION_URL), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(500, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
Assert.assertEquals(Boolean.TRUE, span.tags().get(Tags.ERROR.getKey()));
// request is not hitting controller
assertLogEvents(span.logEntries(), Arrays.asList("error"));
// error logs
Assert.assertEquals(3, span.logEntries().get(0).fields().size());
Assert.assertEquals(Tags.ERROR.getKey(), span.logEntries().get(0).fields().get("event"));
Assert.assertNotNull(span.logEntries().get(0).fields().get("stack"));
Assert.assertEquals(ExceptionFilter.EXCEPTION_MESSAGE, span.logEntries().get(0).fields().get("message"));
span = mockSpans.get(1);
Assert.assertEquals(0, span.tags().size());
Assert.assertEquals(mockSpans.get(0).context().spanId(), span.parentId());
Assert.assertEquals(0, span.tags().size());
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
Assert.assertEquals("BasicErrorController", span.logEntries().get(0).fields().get("handler.class_simple_name"));
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testContextPropagation.
@Test
public void testContextPropagation() throws Exception {
{
HttpHeaders headers = new HttpHeaders();
headers.set("spanid", "1");
headers.set("traceid", "345");
HttpEntity<String> entity = new HttpEntity<>(headers);
getRestTemplate().exchange("/sync", HttpMethod.GET, entity, String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals(1, span.parentId());
Assert.assertEquals(345, span.context().traceId());
Assert.assertEquals("sync", span.operationName());
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testControllerMappedException.
@Test
public void testControllerMappedException() throws Exception {
{
getRestTemplate().getForEntity("/mappedException", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("mappedException", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/mappedException"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(409, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
span = mockSpans.get(1);
Assert.assertEquals(0, span.tags().size());
Assert.assertEquals(mockSpans.get(0).context().spanId(), span.parentId());
Assert.assertEquals(0, span.tags().size());
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
Assert.assertEquals("BasicErrorController", span.logEntries().get(0).fields().get("handler.class_simple_name"));
}
Aggregations