Commit a960272f authored by 张鑫's avatar 张鑫 Committed by 吴晟
Browse files

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

parent 3f7a86f9
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -36,8 +36,10 @@ public class HystrixCommandGetFallbackInterceptor implements InstanceMethodsArou

        AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback");
        activeSpan.setComponent(ComponentsDefine.HYSTRIX);
        if (snapshot != null) {
            ContextManager.continued(snapshot);
        }
    }

    @Override
    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+3 −1
Original line number Diff line number Diff line
@@ -41,7 +41,9 @@ public class HystrixCommandRunInterceptor implements InstanceMethodsAroundInterc

        AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution");
        activeSpan.setComponent(ComponentsDefine.HYSTRIX);
        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());

+6 −2
Original line number Diff line number Diff line
@@ -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();
        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();
        if (ContextManager.isActive()) {
            enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
        }
        actual.onStart(commandInstance);
    }