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");
}
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());
}
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);
}
}
};
}
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();
}
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));
}
Aggregations