Search in sources :

Example 71 with TraceSegment

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));
}
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 72 with TraceSegment

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));
}
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 73 with TraceSegment

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));
}
Also used : TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) 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 74 with TraceSegment

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);
}
Also used : TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)

Example 75 with TraceSegment

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());
}
Also used : ContextSnapshot(org.apache.skywalking.apm.agent.core.context.ContextSnapshot) 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