use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class HandleInterceptorTest method testWithSerializedContextData.
@Test
public void testWithSerializedContextData() throws Throwable {
when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
jettyInvokeInterceptor.afterMethod(enhancedInstance, null, 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));
assertTraceSegmentRef(traceSegment.getRefs().get(0));
}
use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class HandleInterceptorTest method testWithoutSerializedContextData.
@Test
public void testWithoutSerializedContextData() throws Throwable {
jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
jettyInvokeInterceptor.afterMethod(enhancedInstance, null, 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));
}
use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class KafkaConsumerInterceptorTest method testConsumerWithMessage.
@Test
public void testConsumerWithMessage() throws Throwable {
consumerInterceptor.beforeMethod(consumerInstance, null, new Object[0], new Class[0], null);
consumerInterceptor.afterMethod(consumerInstance, null, new Object[0], new Class[0], messages);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
assertThat(traceSegments.size(), is(1));
TraceSegment traceSegment = traceSegments.get(0);
List<TraceSegmentRef> refs = traceSegment.getRefs();
assertThat(refs.size(), is(1));
assertTraceSegmentRef(refs.get(0));
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
assertConsumerSpan(spans.get(0));
}
use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class TracingContext method finish.
/**
* Finish this context, and notify all {@link TracingContextListener}s, managed by {@link
* TracingContext.ListenerManager}
*/
private void finish() {
TraceSegment finishedSegment = segment.finish(isLimitMechanismWorking());
/**
* Recheck the segment if the segment contains only one span.
* Because in the runtime, can't sure this segment is part of distributed trace.
*
* @see {@link #createSpan(String, long, boolean)}
*/
if (!segment.hasRef() && segment.isSingleSpanSegment()) {
if (!samplingService.trySampling()) {
finishedSegment.setIgnore(true);
}
}
TracingContext.ListenerManager.notifyFinish(finishedSegment);
}
use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class SkywalkingSpanActivationTest method testContinuation.
@Test
public void testContinuation() throws Throwable {
startSpan();
final MockEnhancedInstance continuationHolder = new MockEnhancedInstance();
constructorInterceptor.onConstruct(continuationHolder, null);
assertTrue(continuationHolder.getSkyWalkingDynamicField() instanceof ContextSnapshot);
new Thread() {
@Override
public void run() {
MockEnhancedInstance enhancedInstance = new MockEnhancedInstance();
try {
startSpan(enhancedInstance);
activateInterceptor.afterMethod(continuationHolder, SkywalkingContinuation.class.getMethod("activate"), null, null, null);
} catch (Throwable throwable) {
throwable.printStackTrace();
} finally {
try {
stopSpan(enhancedInstance);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
}.start();
Thread.sleep(1000L);
stopSpan();
List<TraceSegment> segments = storage.getTraceSegments();
assertThat(segments.size(), is(2));
TraceSegment traceSegment = segments.get(0);
assertThat(traceSegment.getRefs().size(), is(1));
traceSegment = segments.get(1);
assertNull(traceSegment.getRefs());
}
Aggregations