You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/09/11 05:44:43 UTC

[skywalking] branch master updated: spring-cloud-gateway traceid does not transmit #3411 (#3446)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 96b2baa  spring-cloud-gateway traceid does not transmit #3411 (#3446)
96b2baa is described below

commit 96b2baaddb59c4297756d84750cdf035e415e32f
Author: hi-sb <19...@qq.com>
AuthorDate: Wed Sep 11 13:44:36 2019 +0800

    spring-cloud-gateway traceid does not transmit #3411 (#3446)
    
    * spring-cloud-gateway traceid does not transmit #3411
    
    skywalking-version:6.5.0
    
    spring-gateway-version:2.1.2
    
    Error Description:
    
     Customize the filter, traceid does not transmit.
    
     "ServerWebExchangeDecorator" is a transport chain,His structure should be like this:
    
    	 serverWebExchangeDecorator
    	    -----(ServerWebExchangeDecorator)delegate
    		    ------(ServerWebExchangeDecorator)delegate
    			  ------.....
    			   -----(DefaultServerWebExchange)delegate
      In the current source code, there is no deep search, but only the next level. When there are multiple custom filters, you get an error.
    
    Repair method:
    
      Look for "delegate" of "ServerWebExchangeDecorator" recursively until "DefaultServerWebExchange"
    
    * spring-boot-webflux traceid does not transmit #3411
    
    spring-boot-starter-webflux-version:2.1.6
    
    Error Description:
    
    Customize the filter, traceid does not transmit.
    
    "ServerWebExchangeDecorator" is a transport chain,His structure should be like this:
    
     serverWebExchangeDecorator
        -----(ServerWebExchangeDecorator)delegate
    	    ------(ServerWebExchangeDecorator)delegate
    		  ------.....
    		   -----(DefaultServerWebExchange)delegate
    
    In the current source code, there is no deep search, but only the next level. When there are multiple custom filters, you get an error.
    
    Repair method:
    
    Look for "delegate" of "ServerWebExchangeDecorator" recursively until "DefaultServerWebExchange"
    
    * checkStyle
---
 .../v5/DispatcherHandlerHandleMethodInterceptor.java | 20 ++++++++++++++++----
 .../gateway/v21x/NettyRoutingFilterInterceptor.java  | 19 +++++++++++++++----
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/DispatcherHandlerHandleMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/DispatcherHandlerHandleMethodInterceptor.java
index 5330e22..712ca65 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/DispatcherHandlerHandleMethodInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/DispatcherHandlerHandleMethodInterceptor.java
@@ -82,13 +82,25 @@ public class DispatcherHandlerHandleMethodInterceptor implements InstanceMethods
     public static EnhancedInstance getInstance(Object o) {
         EnhancedInstance instance = null;
         if (o instanceof ServerWebExchangeDecorator) {
-            ServerWebExchange delegate = ((ServerWebExchangeDecorator) o).getDelegate();
-            if (delegate instanceof DefaultServerWebExchange) {
-                instance = (EnhancedInstance) delegate;
-            }
+            instance = getEnhancedInstance((ServerWebExchangeDecorator) o);
         } else if (o instanceof DefaultServerWebExchange) {
             instance = (EnhancedInstance) o;
         }
         return instance;
     }
+
+
+    private static EnhancedInstance getEnhancedInstance(ServerWebExchangeDecorator serverWebExchangeDecorator) {
+        Object o = serverWebExchangeDecorator.getDelegate();
+        if (o instanceof ServerWebExchangeDecorator) {
+            return getEnhancedInstance((ServerWebExchangeDecorator) o);
+        } else if (o instanceof DefaultServerWebExchange) {
+            return (EnhancedInstance) o;
+        } else if (o == null) {
+            throw new NullPointerException("The expected class DefaultServerWebExchange is null");
+        } else {
+            throw new RuntimeException("Unknown parameter types:" + o.getClass());
+        }
+    }
+
 }
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptor.java
index c37aab8..2511985 100644
--- a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptor.java
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptor.java
@@ -79,13 +79,24 @@ public class NettyRoutingFilterInterceptor implements InstanceMethodsAroundInter
     public static EnhancedInstance getInstance(Object o) {
         EnhancedInstance instance = null;
         if (o instanceof ServerWebExchangeDecorator) {
-            ServerWebExchange delegate = ((ServerWebExchangeDecorator) o).getDelegate();
-            if (delegate instanceof DefaultServerWebExchange) {
-                instance = (EnhancedInstance) delegate;
-            }
+            instance = getEnhancedInstance((ServerWebExchangeDecorator) o);
         } else if (o instanceof DefaultServerWebExchange) {
             instance = (EnhancedInstance) o;
         }
         return instance;
     }
+
+
+    private static EnhancedInstance getEnhancedInstance(ServerWebExchangeDecorator serverWebExchangeDecorator) {
+        Object o = serverWebExchangeDecorator.getDelegate();
+        if (o instanceof ServerWebExchangeDecorator) {
+            return getEnhancedInstance((ServerWebExchangeDecorator) o);
+        } else if (o instanceof DefaultServerWebExchange) {
+            return (EnhancedInstance) o;
+        } else if (o == null) {
+            throw new NullPointerException("The expected class DefaultServerWebExchange is null");
+        } else {
+            throw new RuntimeException("Unknown parameter types:" + o.getClass());
+        }
+    }
 }