Search in sources :

Example 16 with LogDataEntity

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);
}
Also used : 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) Test(org.junit.Test)

Example 17 with LogDataEntity

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);
}
Also used : 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) Test(org.junit.Test)

Example 18 with LogDataEntity

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);
}
Also used : 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)

Example 19 with LogDataEntity

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));
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) 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) BigDecimal(java.math.BigDecimal) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 20 with LogDataEntity

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"));
}
Also used : TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) 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) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

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