Search in sources :

Example 21 with TraceSegment

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

the class DubboInterceptorTest method assertProvider.

private void assertProvider() {
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1));
    assertProviderSpan(SegmentHelper.getSpans(traceSegment).get(0));
    assertTraceSegmentRef(traceSegment.getRefs().get(0));
}
Also used : TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)

Example 22 with TraceSegment

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment 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 23 with TraceSegment

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

the class DefaultHttpClientInterceptorTest method testMethodsAroundError.

@Test
public void testMethodsAroundError() throws Throwable {
    defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
    Response response = mock(Response.class);
    when(response.status()).thenReturn(404);
    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(3));
    assertThat(tags.get(0).getValue(), is("GET"));
    assertThat(tags.get(1).getValue(), is("http://skywalking.org/"));
    assertThat(tags.get(2).getValue(), is("404"));
    Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
}
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) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with TraceSegment

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

the class StateInterceptorTest method testHttpClient.

@Test
public void testHttpClient() throws Throwable {
    AbstractSpan span = ContextManager.createLocalSpan("httpasyncclient/HttpAsyncRequestExecutor:");
    stateInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    stateInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    processResponseInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    processResponseInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertHttpSpan(spans.get(0));
    verify(request, times(1)).setHeader(anyString(), anyString());
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with TraceSegment

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

the class SWCallableStatementTest method testQuerySqlWithSql.

@Test
public void testQuerySqlWithSql() throws SQLException {
    CallableStatement preparedStatement = swConnection.prepareCall("SELECT * FROM test", 1, 1);
    ResultSet resultSet = preparedStatement.executeQuery("SELECT * FROM test");
    preparedStatement.getGeneratedKeys();
    preparedStatement.close();
    verify(mysqlCallableStatement, times(1)).executeQuery(anyString());
    verify(mysqlCallableStatement, times(1)).close();
    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");
}
Also used : CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Aggregations

TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)158 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)149 Test (org.junit.Test)147 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 PreparedStatement (java.sql.PreparedStatement)19 LogDataEntity (org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)15 SegmentStoragePoint (org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint)14 CallableStatement (java.sql.CallableStatement)13 Method (java.lang.reflect.Method)11 Statement (java.sql.Statement)11 SQLException (java.sql.SQLException)10 KeyValuePair (org.apache.skywalking.apm.agent.core.context.util.KeyValuePair)10 ResultSet (java.sql.ResultSet)7 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)7 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)7 Response (feign.Response)3 HashMap (java.util.HashMap)3 Response (okhttp3.Response)3 TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)3 TextMap (io.opentracing.propagation.TextMap)2