use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testControllerException.
@Test
public void testControllerException() throws Exception {
{
getRestTemplate().getForEntity("/exception", 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("exception", 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("/exception"), 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()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion", "error"));
// error log
Assert.assertEquals(3, span.logEntries().get(2).fields().size());
Assert.assertEquals(Tags.ERROR.getKey(), span.logEntries().get(2).fields().get("event"));
Assert.assertEquals(TestController.EXCEPTION_MESSAGE, span.logEntries().get(2).fields().get("message"));
Assert.assertNotNull(span.logEntries().get(2).fields().get("stack"));
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 testSecuredURLAuthorized.
@Test
public void testSecuredURLAuthorized() throws Exception {
{
getRestTemplate().withBasicAuth("user", "password").getForEntity("/secured", 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("secured", 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("/secured"), 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 testForward.
@Test
public void testForward() {
{
getRestTemplate().getForEntity("/forward", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals("sync", mockSpan.operationName());
assertLogEvents(mockSpan.logEntries(), Arrays.asList("preHandle", "preHandle", "afterCompletion", "afterCompletion"));
Assert.assertEquals("forward", mockSpan.logEntries().get(0).fields().get(HandlerInterceptorSpanDecorator.HandlerUtils.HANDLER_METHOD_NAME));
Assert.assertEquals("sync", mockSpan.logEntries().get(1).fields().get(HandlerInterceptorSpanDecorator.HandlerUtils.HANDLER_METHOD_NAME));
Assert.assertTrue(mockSpan.logEntries().get(2).fields().get(HandlerInterceptorSpanDecorator.HandlerUtils.HANDLER).toString().contains("sync"));
Assert.assertTrue(mockSpan.logEntries().get(3).fields().get(HandlerInterceptorSpanDecorator.HandlerUtils.HANDLER).toString().contains("forward"));
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testSecuredURLUnAuthorized.
@Test
public void testSecuredURLUnAuthorized() throws Exception {
{
getRestTemplate().getForEntity("/secured", 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(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("/secured"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(401, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
// request does not hit any controller
assertLogEvents(span.logEntries(), Collections.<String>emptyList());
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 testSyncWithStandardTags.
@Test
public void testSyncWithStandardTags() throws Exception {
{
getRestTemplate().getForEntity("/sync", 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("sync", 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("/sync"), 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"));
}
Aggregations