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