use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.
the class MongoDBCollectionMethodInterceptorTest method testInterceptWithException.
@Test
public void testInterceptWithException() throws Throwable {
interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), null, null, null);
interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), null, null, new RuntimeException());
interceptor.afterMethod(enhancedInstance, getExecuteMethod(), null, null, null);
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertMongoSpan(spans.get(0));
List<LogDataEntity> logDataEntities = SpanHelper.getLogs(spans.get(0));
assertThat(logDataEntities.size(), is(1));
SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class);
}
use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.
the class MongoDBMethodInterceptorTest method testInterceptWithException.
@Test
public void testInterceptWithException() throws Throwable {
interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null);
interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, new RuntimeException());
interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null);
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertRedisSpan(spans.get(0));
List<LogDataEntity> logDataEntities = SpanHelper.getLogs(spans.get(0));
assertThat(logDataEntities.size(), is(1));
SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class);
}
use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.
the class MotanProviderInterceptorTest method assertTraceSegmentWhenOccurException.
private void assertTraceSegmentWhenOccurException() {
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertMotanProviderSpan(spans.get(0));
SpanAssert.assertLogSize(spans.get(0), 1);
List<LogDataEntity> logDataEntities = SpanHelper.getLogs(spans.get(0));
SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class);
}
use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.
the class SWCallableStatementTest method testMultiHostWithException.
@Test(expected = SQLException.class)
public void testMultiHostWithException() throws SQLException {
when(mysqlCallableStatement.executeQuery()).thenThrow(new SQLException());
try {
CallableStatement preparedStatement = multiHostConnection.prepareCall("SELECT * FROM test WHERE a = ? OR b = ? OR c=? OR d = ? OR e=?");
preparedStatement.setBigDecimal(1, new BigDecimal(10000));
preparedStatement.setBlob(2, inputStream);
preparedStatement.setBlob(3, inputStream, 1000000L);
preparedStatement.setByte(3, (byte) 1);
preparedStatement.setBytes(4, bytesParam);
preparedStatement.setLong(5, 100L);
ResultSet resultSet = preparedStatement.executeQuery();
preparedStatement.close();
} finally {
verify(mysqlCallableStatement, times(1)).executeQuery();
verify(mysqlCallableStatement, times(0)).close();
verify(mysqlCallableStatement, times(1)).setBigDecimal(anyInt(), any(BigDecimal.class));
verify(mysqlCallableStatement, times(1)).setBlob(anyInt(), any(InputStream.class));
verify(mysqlCallableStatement, times(1)).setBlob(anyInt(), any(InputStream.class), anyLong());
verify(mysqlCallableStatement, times(1)).setByte(anyInt(), anyByte());
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
assertDBSpan(spans.get(0), "Mysql/JDBI/CallableStatement/executeQuery", "SELECT * FROM test WHERE a = ? OR b = ? OR c=? OR d = ? OR e=?");
List<LogDataEntity> logs = SpanHelper.getLogs(spans.get(0));
Assert.assertThat(logs.size(), is(1));
assertDBSpanLog(logs.get(0));
}
}
use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.
the class ContextManagerTest method createMultipleEntrySpan.
@Test
public void createMultipleEntrySpan() {
ContextCarrier contextCarrier = new ContextCarrier().deserialize("1.2343.234234234|1|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|1.2343.234234234");
assertTrue(contextCarrier.isValid());
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier);
firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
SpanLayer.asHttp(firstEntrySpan);
AbstractSpan secondEntrySpan = ContextManager.createEntrySpan("/testSecondEntry", contextCarrier);
secondEntrySpan.setComponent(ComponentsDefine.DUBBO);
Tags.URL.set(firstEntrySpan, "dubbo://127.0.0.1:8080");
SpanLayer.asRPCFramework(secondEntrySpan);
ContextCarrier injectContextCarrier = new ContextCarrier();
AbstractSpan exitSpan = ContextManager.createExitSpan("/textExitSpan", injectContextCarrier, "127.0.0.1:12800");
exitSpan.errorOccurred();
exitSpan.log(new RuntimeException("exception"));
exitSpan.setComponent(ComponentsDefine.HTTPCLIENT);
ContextManager.stopSpan();
ContextManager.stopSpan();
SpanLayer.asHttp(firstEntrySpan);
firstEntrySpan.setOperationName("/testFirstEntry-setOperationName");
ContextManager.stopSpan();
assertThat(tracingData.getTraceSegments().size(), is(1));
TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
assertThat(actualSegment.getRefs().size(), is(1));
TraceSegmentRef ref = actualSegment.getRefs().get(0);
MatcherAssert.assertThat(TraceSegmentRefHelper.getPeerHost(ref), is("127.0.0.1:8080"));
assertThat(ref.getEntryOperationName(), is("/portal/"));
assertThat(ref.getEntryOperationId(), is(0));
List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment);
assertThat(spanList.size(), is(2));
AbstractTracingSpan actualEntrySpan = spanList.get(1);
assertThat(actualEntrySpan.getOperationName(), is("/testSecondEntry"));
assertThat(actualEntrySpan.getSpanId(), is(0));
assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1));
assertThat(SpanHelper.getComponentId(actualEntrySpan), is(ComponentsDefine.DUBBO.getId()));
assertThat(SpanHelper.getLayer(actualEntrySpan), is(SpanLayer.RPC_FRAMEWORK));
AbstractTracingSpan actualExitSpan = spanList.get(0);
assertThat(actualExitSpan.getOperationName(), is("/textExitSpan"));
assertThat(actualExitSpan.getSpanId(), is(1));
assertThat(AbstractTracingSpanHelper.getParentSpanId(actualExitSpan), is(0));
List<LogDataEntity> logs = AbstractTracingSpanHelper.getLogs(actualExitSpan);
assertThat(logs.size(), is(1));
assertThat(logs.get(0).getLogs().size(), is(4));
assertThat(injectContextCarrier.getSpanId(), is(1));
assertThat(injectContextCarrier.getEntryOperationName(), is("#/portal/"));
assertThat(injectContextCarrier.getPeerHost(), is("#127.0.0.1:12800"));
}
Aggregations