Search in sources :

Example 46 with TraceSegment

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

the class SkywalkingSpanActivationTest method testExtractWithInValidateContext.

@Test
public void testExtractWithInValidateContext() throws Throwable {
    spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
    startSpan();
    final Map<String, String> values = new HashMap<String, String>();
    TextMap carrier = new TextMap() {

        @Override
        public Iterator<Map.Entry<String, String>> iterator() {
            return values.entrySet().iterator();
        }

        @Override
        public void put(String key, String value) {
            values.put(key, value);
        }
    };
    values.put(SW3CarrierItem.HEADER_NAME, "aaaaaaaa|3|#192.168.1.8:18002|#/portal/|#/testEntrySpan|1.234.444");
    extractInterceptor.afterMethod(enhancedInstance, null, new Object[] { Format.Builtin.TEXT_MAP, carrier }, new Class[] {}, null);
    stopSpan();
    TraceSegment tracingSegment = assertTraceSemgnets();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(tracingSegment);
    assertNull(tracingSegment.getRefs());
    assertSpanCommonsAttribute(spans.get(0));
}
Also used : HashMap(java.util.HashMap) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TextMap(io.opentracing.propagation.TextMap) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 47 with TraceSegment

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

the class RestMappingMethodInterceptorTest method testGetMapping.

@Test
public void testGetMapping() 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.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");
}
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 48 with TraceSegment

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

the class RestMappingMethodInterceptorTest method testDeleteMapping.

@Test
public void testDeleteMapping() throws Throwable {
    controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
    RestMappingClass1 mappingClass1 = new RestMappingClass1();
    Method m = mappingClass1.getClass().getMethod("deleteRequestURL");
    when(request.getRequestURI()).thenReturn("/test/testRequestURL");
    when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/deleteRequestURL"));
    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), "/deleteRequestURL");
}
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 49 with TraceSegment

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

Example 50 with TraceSegment

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

the class RestMappingMethodInterceptorTest method testPostMapping.

@Test
public void testPostMapping() throws Throwable {
    controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
    RestMappingClass1 mappingClass1 = new RestMappingClass1();
    Method m = mappingClass1.getClass().getMethod("postRequestURL");
    when(request.getRequestURI()).thenReturn("/test/testRequestURL");
    when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/postRequestURL"));
    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), "/postRequestURL");
}
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