Search in sources :

Example 1 with LogDataEntity

use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.

the class HttpClientExecuteInterceptorTest method assertHttpSpanErrorLog.

private void assertHttpSpanErrorLog(List<LogDataEntity> logs) {
    assertThat(logs.size(), is(1));
    LogDataEntity logData = logs.get(0);
    Assert.assertThat(logData.getLogs().size(), is(4));
    Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.<Object>is("error"));
    Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.<Object>is(RuntimeException.class.getName()));
    Assert.assertThat(logData.getLogs().get(2).getValue(), is("testException"));
    assertNotNull(logData.getLogs().get(3).getValue());
}
Also used : LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)

Example 2 with LogDataEntity

use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.

the class SwPreparedStatementTest method testMultiHostWithException.

@Test(expected = SQLException.class)
public void testMultiHostWithException() throws SQLException {
    when(mysqlPreparedStatement.executeQuery()).thenThrow(new SQLException());
    try {
        PreparedStatement preparedStatement = multiHostConnection.prepareStatement("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, new byte[] { 1, 2 });
        preparedStatement.setLong(5, 100L);
        ResultSet resultSet = preparedStatement.executeQuery();
        preparedStatement.close();
    } finally {
        verify(mysqlPreparedStatement, times(1)).executeQuery();
        verify(mysqlPreparedStatement, times(0)).close();
        verify(mysqlPreparedStatement, times(1)).setBigDecimal(anyInt(), any(BigDecimal.class));
        verify(mysqlPreparedStatement, times(1)).setBlob(anyInt(), any(InputStream.class));
        verify(mysqlPreparedStatement, times(1)).setBlob(anyInt(), any(InputStream.class), anyLong());
        verify(mysqlPreparedStatement, times(1)).setByte(anyInt(), anyByte());
        TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
        List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
        assertThat(spans.size(), is(1));
        assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeQuery", "SELECT * FROM test WHERE a = ? or b = ? or c=? or d = ? or e=?");
        List<LogDataEntity> logData = SpanHelper.getLogs(spans.get(0));
        Assert.assertThat(logData.size(), is(1));
        assertThat(logData.size(), is(1));
        assertDBSpanLog(logData.get(0));
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) ResultSet(java.sql.ResultSet) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 3 with LogDataEntity

use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.

the class JedisMethodInterceptorTest method assertLogData.

private void assertLogData(List<LogDataEntity> logDataEntities) {
    assertThat(logDataEntities.size(), is(1));
    LogDataEntity logData = logDataEntities.get(0);
    Assert.assertThat(logData.getLogs().size(), is(4));
    Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.<Object>is("error"));
    Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.<Object>is(RuntimeException.class.getName()));
    Assert.assertNull(logData.getLogs().get(2).getValue());
    assertNotNull(logData.getLogs().get(3).getValue());
}
Also used : LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)

Example 4 with LogDataEntity

use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.

the class DefaultHttpClientInterceptorTest method testException.

@Test
public void testException() throws Throwable {
    defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
    defaultHttpClientInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new NullPointerException("testException"));
    Response response = mock(Response.class);
    when(response.status()).thenReturn(200);
    defaultHttpClientInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
    AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
    assertSpan(finishedSpan);
    List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
    assertThat(tags.size(), is(2));
    assertThat(tags.get(0).getValue(), is("GET"));
    assertThat(tags.get(1).getValue(), is("http://skywalking.org/"));
    Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
    Assert.assertEquals(1, SpanHelper.getLogs(finishedSpan).size());
    LogDataEntity logDataEntity = SpanHelper.getLogs(finishedSpan).get(0);
    assertThat(logDataEntity.getLogs().size(), is(4));
    assertThat(logDataEntity.getLogs().get(0).getValue(), CoreMatchers.<Object>is("error"));
    assertThat(logDataEntity.getLogs().get(1).getValue(), CoreMatchers.<Object>is(NullPointerException.class.getName()));
    assertThat(logDataEntity.getLogs().get(2).getValue(), is("testException"));
    assertNotNull(logDataEntity.getLogs().get(3).getValue());
}
Also used : Response(feign.Response) KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with LogDataEntity

use of org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity in project incubator-skywalking by apache.

the class RestMappingMethodInterceptorTest method testWithOccurException.

@Test
public void testWithOccurException() throws Throwable {
    controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
    RestMappingClass1 mappingClass1 = new RestMappingClass1();
    Method m = mappingClass1.getClass().getMethod("getRequestURL");
    when(request.getRequestURI()).thenReturn("/test/testRequestURL");
    when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/getRequestURL"));
    ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(request, response);
    RequestContextHolder.setRequestAttributes(servletRequestAttributes);
    interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult);
    interceptor.handleMethodException(enhancedInstance, m, arguments, argumentType, new RuntimeException());
    interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertHttpSpan(spans.get(0), "/getRequestURL");
    List<LogDataEntity> logDataEntities = SpanHelper.getLogs(spans.get(0));
    assertThat(logDataEntities.size(), is(1));
    SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class);
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity) Method(java.lang.reflect.Method) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Aggregations

LogDataEntity (org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)20 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)15 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)15 Test (org.junit.Test)13 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 BigDecimal (java.math.BigDecimal)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Response (feign.Response)1 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)1 KeyValuePair (org.apache.skywalking.apm.agent.core.context.util.KeyValuePair)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1