Fix the issue that Hystrix plugin case NPE (#1293)

This commit is contained in:
Xin,Zhang 2018-05-31 08:48:19 +08:00 committed by 吴晟 Wu Sheng
parent 3f7a86f98f
commit a960272f71
3 changed files with 12 additions and 4 deletions

View File

@ -36,7 +36,9 @@ public class HystrixCommandGetFallbackInterceptor implements InstanceMethodsArou
AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback");
activeSpan.setComponent(ComponentsDefine.HYSTRIX);
ContextManager.continued(snapshot);
if (snapshot != null) {
ContextManager.continued(snapshot);
}
}
@Override

View File

@ -41,7 +41,9 @@ public class HystrixCommandRunInterceptor implements InstanceMethodsAroundInterc
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());

View File

@ -41,7 +41,9 @@ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook {
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 class SWExecutionHookWrapper extends HystrixCommandExecutionHook {
@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);
}