Search in sources :

Example 96 with TraceSegment

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

the class RestMappingMethodInterceptorTest method testPutMapping.

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

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

the class TestException method testHttpClientWithException.

@Test
public void testHttpClientWithException() throws Throwable {
    AbstractSpan localSpan = ContextManager.createLocalSpan("httpasyncclient/HttpAsyncRequestExecutor:");
    stateInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    stateInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentsType, new RuntimeException("testException"));
    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);
    assertThat(spans.size(), is(3));
    AbstractTracingSpan span = spans.get(0);
    assertThat(SpanHelper.getErrorOccurred(span), is(true));
    assertHttpSpanErrorLog(SpanHelper.getLogs(span));
    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 98 with TraceSegment

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

the class TracingSegmentRunner method withAfters.

@Override
protected Statement withAfters(FrameworkMethod method, Object target, final Statement statement) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            if (field != null) {
                try {
                    tracingData = new SegmentStorage();
                    field.set(targetObject, tracingData);
                } catch (IllegalAccessException e) {
                }
            }
            tracingContextListener = new TracingContextListener() {

                @Override
                public void afterFinished(TraceSegment traceSegment) {
                    tracingData.addTraceSegment(traceSegment);
                }
            };
            ignoreTracerContextListener = new IgnoreTracerContextListener() {

                @Override
                public void afterFinished(IgnoredTracerContext tracerContext) {
                    tracingData.addIgnoreTraceContext(tracerContext);
                }
            };
            TracingContext.ListenerManager.add(tracingContextListener);
            IgnoredTracerContext.ListenerManager.add(ignoreTracerContextListener);
            try {
                statement.evaluate();
            } finally {
                TracingContext.ListenerManager.remove(tracingContextListener);
                IgnoredTracerContext.ListenerManager.remove(ignoreTracerContextListener);
            }
        }
    };
}
Also used : IgnoredTracerContext(org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext) Statement(org.junit.runners.model.Statement) IgnoreTracerContextListener(org.apache.skywalking.apm.agent.core.context.IgnoreTracerContextListener) TracingContextListener(org.apache.skywalking.apm.agent.core.context.TracingContextListener) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)

Example 99 with TraceSegment

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

the class TraceSegmentServiceClient method consume.

@Override
public void consume(List<TraceSegment> data) {
    if (CONNECTED.equals(status)) {
        final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false);
        StreamObserver<UpstreamSegment> upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver<Downstream>() {

            @Override
            public void onNext(Downstream downstream) {
            }

            @Override
            public void onError(Throwable throwable) {
                status.finished();
                if (logger.isErrorEnable()) {
                    logger.error(throwable, "Send UpstreamSegment to collector fail with a grpc internal exception.");
                }
                ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(throwable);
            }

            @Override
            public void onCompleted() {
                status.finished();
            }
        });
        for (TraceSegment segment : data) {
            try {
                UpstreamSegment upstreamSegment = segment.transform();
                upstreamSegmentStreamObserver.onNext(upstreamSegment);
            } catch (Throwable t) {
                logger.error(t, "Transform and send UpstreamSegment to collector fail.");
            }
        }
        upstreamSegmentStreamObserver.onCompleted();
        if (status.wait4Finish(TIMEOUT)) {
            segmentUplinkedCounter += data.size();
        }
    } else {
        segmentAbandonedCounter += data.size();
    }
    printUplinkStatus();
}
Also used : UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) Downstream(org.apache.skywalking.apm.network.proto.Downstream) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)

Example 100 with TraceSegment

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

the class RequestMappingMethodInterceptorTest method testWithoutSerializedContextData.

@Test
public void testWithoutSerializedContextData() throws Throwable {
    controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
    RequestMappingClass1 mappingClass1 = new RequestMappingClass1();
    Method m = mappingClass1.getClass().getMethod("testRequestURL");
    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 : 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