From c3c56acf0c002bc6f717b7d889123e56a283e0b3 Mon Sep 17 00:00:00 2001 From: zifeihan Date: Fri, 6 Nov 2020 15:18:14 +0800 Subject: [PATCH] Avoided to interrupt the process of the application in the `SWExecutionHookWrapper` wrapper class. (#5803) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Avoided to interrupt the process of the application in the `SWExecutionHookWrapper` wrapper class. * Polishing. Co-authored-by: 吴晟 Wu Sheng --- .../hystrix/v1/SWExecutionHookWrapper.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java index 9c8df3efd5..0efddf8c84 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java @@ -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); } -- GitLab