Avoided to interrupt the process of the application in the `SWExecutionHookWrapper` wrapper class. (#5803)

* Avoided to interrupt the process of the application in the `SWExecutionHookWrapper` wrapper class.

* Polishing.

Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
This commit is contained in:
zifeihan 2020-11-06 15:18:14 +08:00 committed by GitHub
parent 96014ddac2
commit c3c56acf0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 8 deletions

View File

@ -23,6 +23,8 @@ import com.netflix.hystrix.HystrixInvokable;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
/**
@ -31,6 +33,8 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI
public class SWExecutionHookWrapper extends HystrixCommandExecutionHook {
private final HystrixCommandExecutionHook actual;
private static ILog LOGGER = LogManager.getLogger(SWExecutionHookWrapper.class);
public SWExecutionHookWrapper(HystrixCommandExecutionHook actual) {
this.actual = actual;
}
@ -42,10 +46,14 @@ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook {
return;
}
EnhancedInstance enhancedInstance = (EnhancedInstance) commandInstance;
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) enhancedInstance.getSkyWalkingDynamicField();
if (ContextManager.isActive()) {
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
try {
EnhancedInstance enhancedInstance = (EnhancedInstance) commandInstance;
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) enhancedInstance.getSkyWalkingDynamicField();
if (ContextManager.isActive()) {
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
}
} catch (Exception e) {
LOGGER.error("Failed to set ContextSnapshot.", e);
}
actual.onStart(commandInstance);
}
@ -194,10 +202,14 @@ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook {
return;
}
EnhancedInstance enhancedInstance = (EnhancedInstance) commandInstance;
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) enhancedInstance.getSkyWalkingDynamicField();
if (ContextManager.isActive()) {
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
try {
EnhancedInstance enhancedInstance = (EnhancedInstance) commandInstance;
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) enhancedInstance.getSkyWalkingDynamicField();
if (ContextManager.isActive()) {
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
}
} catch (Exception e) {
LOGGER.error("Failed to set ContextSnapshot.", e);
}
actual.onStart(commandInstance);
}