Search in sources :

Example 1 with ContextSnapshot

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

the class HystrixCommandGetFallbackInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
    ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback");
    activeSpan.setComponent(ComponentsDefine.HYSTRIX);
    ContextManager.continued(snapshot);
}
Also used : ContextSnapshot(org.apache.skywalking.apm.agent.core.context.ContextSnapshot) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 2 with ContextSnapshot

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

the class HystrixCommandRunInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    // create a local span, and continued, The `execution method` running in other thread if the
    // hystrix strategy is `THREAD`.
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
    ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution");
    activeSpan.setComponent(ComponentsDefine.HYSTRIX);
    ContextManager.continued(snapshot);
    // Because of `fall back` method running in other thread. so we need capture concurrent span for tracing.
    enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
}
Also used : ContextSnapshot(org.apache.skywalking.apm.agent.core.context.ContextSnapshot) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 3 with ContextSnapshot

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

Example 4 with ContextSnapshot

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

the class CallbackInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    AbstractSpan abstractSpan = ContextManager.createLocalSpan("Producer/Callback");
    // Get the SnapshotContext
    ContextSnapshot contextSnapshot = (ContextSnapshot) objInst.getSkyWalkingDynamicField();
    ContextManager.continued(contextSnapshot);
}
Also used : ContextSnapshot(org.apache.skywalking.apm.agent.core.context.ContextSnapshot) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

ContextSnapshot (org.apache.skywalking.apm.agent.core.context.ContextSnapshot)4 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)3 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)1 Test (org.junit.Test)1