wu-sheng closed pull request #1293: Fix the issue that Hystrix plugin case NPE URL: https://github.com/apache/incubator-skywalking/pull/1293
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java index f935c77eb..2dd1f4f9c 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java @@ -36,7 +36,9 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback"); activeSpan.setComponent(ComponentsDefine.HYSTRIX); - ContextManager.continued(snapshot); + if (snapshot != null) { + ContextManager.continued(snapshot); + } } @Override diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java index c6f1bcc97..28dce1a39 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java @@ -41,7 +41,9 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution"); activeSpan.setComponent(ComponentsDefine.HYSTRIX); - ContextManager.continued(snapshot); + if (snapshot != null) { + ContextManager.continued(snapshot); + } // Because of `fall back` method running in other thread. so we need capture concurrent span for tracing. enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); 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 eedc646cd..fbe0022a0 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 @@ -41,7 +41,9 @@ public SWExecutionHookWrapper(HystrixCommandExecutionHook actual) { public <T> void onStart(HystrixInvokable<T> commandInstance) { EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); - enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + if (ContextManager.isActive()) { + enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + } actual.onStart(commandInstance); } @@ -166,7 +168,9 @@ public SWExecutionHookWrapper(HystrixCommandExecutionHook actual) { @Override public <T> void onStart(HystrixCommand<T> commandInstance) { EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); - enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + if (ContextManager.isActive()) { + enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + } actual.onStart(commandInstance); } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services