Search in sources :

Example 91 with TraceSegment

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

the class XMemcachedMethodInterceptorTest method testIntercept.

@Test
public void testIntercept() throws Throwable {
    interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
    interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null);
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertMemcacheSpan(spans.get(0));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 92 with TraceSegment

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

the class TraceAnnotationTest method testTrace.

@Test
public void testTrace() throws Throwable {
    Method withOperationNameMethod = TestAnnotationMethodClass.class.getDeclaredMethod("testMethodWithDefaultValue");
    methodInterceptor.beforeMethod(enhancedInstance, withOperationNameMethod, null, null, null);
    methodInterceptor.afterMethod(enhancedInstance, withOperationNameMethod, null, null, null);
    assertThat(storage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = storage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    AbstractTracingSpan tracingSpan = spans.get(0);
    assertThat(tracingSpan.getOperationName(), is(TestAnnotationMethodClass.class.getName() + "." + withOperationNameMethod.getName() + "()"));
    SpanAssert.assertLogSize(tracingSpan, 0);
    SpanAssert.assertTagSize(tracingSpan, 0);
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) Method(java.lang.reflect.Method) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 93 with TraceSegment

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

the class TraceAnnotationTest method testTraceWithOperationName.

@Test
public void testTraceWithOperationName() throws Throwable {
    Method withOperationNameMethod = TestAnnotationMethodClass.class.getDeclaredMethod("testMethodWithOperationName");
    methodInterceptor.beforeMethod(enhancedInstance, withOperationNameMethod, null, null, null);
    tagInterceptor.beforeMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null);
    tagInterceptor.afterMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null);
    methodInterceptor.afterMethod(enhancedInstance, withOperationNameMethod, null, null, null);
    assertThat(storage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = storage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    AbstractTracingSpan tracingSpan = spans.get(0);
    assertThat(tracingSpan.getOperationName(), is("testMethod"));
    SpanAssert.assertLogSize(tracingSpan, 0);
    SpanAssert.assertTagSize(tracingSpan, 1);
    List<KeyValuePair> tags = SpanHelper.getTags(tracingSpan);
    assertThat(tags.get(0).getKey(), is("testTagKey"));
    assertThat(tags.get(0).getValue(), is("testTagValue"));
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) Method(java.lang.reflect.Method) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 94 with TraceSegment

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

the class RestMappingMethodInterceptorTest method testDummy.

@Test
public void testDummy() throws Throwable {
    controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
    RestMappingClass1 mappingClass1 = new RestMappingClass1();
    Method m = mappingClass1.getClass().getMethod("dummy");
    when(request.getRequestURI()).thenReturn("/test");
    when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test"));
    ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(request, response);
    RequestContextHolder.setRequestAttributes(servletRequestAttributes);
    interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult);
    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), "");
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) Method(java.lang.reflect.Method) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 95 with TraceSegment

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

the class RestMappingMethodInterceptorTest method testPatchMapping.

@Test
public void testPatchMapping() throws Throwable {
    controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
    RestMappingClass1 mappingClass1 = new RestMappingClass1();
    Method m = mappingClass1.getClass().getMethod("patchRequestURL");
    when(request.getRequestURI()).thenReturn("/test/testRequestURL");
    when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/patchRequestURL"));
    ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(request, response);
    RequestContextHolder.setRequestAttributes(servletRequestAttributes);
    interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult);
    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), "/patchRequestURL");
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) Method(java.lang.reflect.Method) 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