You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/05/06 10:42:27 UTC

[GitHub] [skywalking] woshishitou opened a new issue #6900: SpringcloudGateway can't get traceId

woshishitou opened a new issue #6900:
URL: https://github.com/apache/skywalking/issues/6900


   Please answer these questions before submitting your issue.
   
   - Why do you submit this issue?
   - [√] Question or discussion
   - [ ] Bug
   - [ ] Requirement
   - [ ] Feature or performance improvement
   
   ___
   ### Question
   - What do you want to know?
   Why I can't get traceId? And how can I get it in gateway?
   
   ___
   ### Bug
   - Which version of SkyWalking, OS, and JRE?
   
   - Which company or project?
   
   - What happened?
   If possible, provide a way to reproduce the error. e.g. demo application, component version.
   My code is below
   
   ___
   ### Requirement or improvement
   - Please describe your requirements or improvement suggestions.
   Skywalking: 8.4
   SpringcloudGateway: 2.1.1
   Springcloud: Greenwich.SR1 
   Springboot: 2.1.6
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou edited a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou edited a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001298651


   > 
   
   `
   // 获取skywalking设置到exchange中的span实例,并使用反射获取其owner字段(该字段从父类的父类继承而来,类型为TracingContext)
               Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
               Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
               Field field = entrySpanClazz.getDeclaredField("owner");
               // 利用反射调用owner的getReadablePrimaryTraceId()方法,以获取traceId
               field.setAccessible(true);
               Object ownerInstance = field.get(entrySpanInstance);
               Class<?> ownerClazz = ownerInstance.getClass();
               Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
               String traceId = (String) getTraceId.invoke(ownerInstance);
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833427133


   Is that what I'm getting wrong?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou edited a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou edited a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001298651


   
   ```java
   // 获取skywalking设置到exchange中的span实例,并使用反射获取其owner字段(该字段从父类的父类继承而来,类型为TracingContext)
               Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
               Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
               Field field = entrySpanClazz.getDeclaredField("owner");
               // 利用反射调用owner的getReadablePrimaryTraceId()方法,以获取traceId
               field.setAccessible(true);
               Object ownerInstance = field.get(entrySpanInstance);
               Class<?> ownerClazz = ownerInstance.getClass();
               Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
               String traceId = (String) getTraceId.invoke(ownerInstance);
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou edited a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou edited a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001299649


   > 
   
   Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
   
   Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
   
   Field field = entrySpanClazz.getDeclaredField("owner");
   
   field.setAccessible(true);
   
   Object ownerInstance = field.get(entrySpanInstance);
   
   Class<?> ownerClazz = ownerInstance.getClass();
   
   Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
   
   String traceId = (String) getTraceId.invoke(ownerInstance);
   
   
   -----------------------------------------------------------------------------
   
   You need to write this code in the filter method.
   
   Hope it helps you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-913945335


   There are related classes in the skywalking source code in this picture.
   Finally, you can get the traceid through the method getReadablePrimaryTraceId() in interface AbstractTracerContext.
   ![image](https://user-images.githubusercontent.com/22254487/132275108-11cbe067-5e72-4570-8630-672d9134aa20.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou removed a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou removed a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833424090


   `package com.example.gatewaydemo.filter;
   
   import org.apache.skywalking.apm.toolkit.trace.TraceContext;
   import org.springframework.cloud.gateway.filter.GatewayFilterChain;
   import org.springframework.cloud.gateway.filter.GlobalFilter;
   import org.springframework.context.annotation.Bean;
   import org.springframework.context.annotation.Configuration;
   import org.springframework.core.Ordered;
   import org.springframework.web.server.ServerWebExchange;
   import reactor.core.publisher.Mono;
   
   @Configuration
   public class FilterConfig {
   
       @Bean
       public GlobalFilter b() {
           return new BFilter();
       }
   
       public class BFilter implements GlobalFilter, Ordered {
   
           @Override
           public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   			// 这里获取到的traceId是N/A
               exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
               return chain.filter(exchange).then(Mono.fromRunnable(() ->
               {
   				// 这里获取到的也是N/A
                   String traceId2 = TraceContext.traceId();
                   System.out.println("traceId:" + traceId2);
               }));
           }
   
           @Override
           public int getOrder() {
               return 1;
           }
       }
   
   }
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833431713


   Gateway has a complex thread model, you only could get value when your codes and skywalking instrument codes sharing thread.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001299649


   > 
   
   Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
   Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
   Field field = entrySpanClazz.getDeclaredField("owner");
   field.setAccessible(true);
   Object ownerInstance = field.get(entrySpanInstance);
   Class<?> ownerClazz = ownerInstance.getClass();
   Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
   String traceId = (String) getTraceId.invoke(ownerInstance);
   
   
   You need to write this code in the filter method.
   
   Hope it helps you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou removed a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou removed a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833424297


   `
   package com.example.gatewaydemo.filter;
   
   import org.apache.skywalking.apm.toolkit.trace.TraceContext;
   import org.springframework.cloud.gateway.filter.GatewayFilterChain;
   import org.springframework.cloud.gateway.filter.GlobalFilter;
   import org.springframework.context.annotation.Bean;
   import org.springframework.context.annotation.Configuration;
   import org.springframework.core.Ordered;
   import org.springframework.web.server.ServerWebExchange;
   import reactor.core.publisher.Mono;
   
   @Configuration
   public class FilterConfig {
   
       @Bean
       public GlobalFilter b() {
           return new BFilter();
       }
   
       public class BFilter implements GlobalFilter, Ordered {
   
           @Override
           public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   			// 这里获取到的traceId是N/A
               exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
               return chain.filter(exchange).then(Mono.fromRunnable(() ->
               {
   				// 这里获取到的也是N/A
                   String traceId2 = TraceContext.traceId();
                   System.out.println("traceId:" + traceId2);
               }));
           }
   
           @Override
           public int getOrder() {
               return 1;
           }
       }
   
   }
   
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833424297


   `
   package com.example.gatewaydemo.filter;
   
   import org.apache.skywalking.apm.toolkit.trace.TraceContext;
   import org.springframework.cloud.gateway.filter.GatewayFilterChain;
   import org.springframework.cloud.gateway.filter.GlobalFilter;
   import org.springframework.context.annotation.Bean;
   import org.springframework.context.annotation.Configuration;
   import org.springframework.core.Ordered;
   import org.springframework.web.server.ServerWebExchange;
   import reactor.core.publisher.Mono;
   
   @Configuration
   public class FilterConfig {
   
       @Bean
       public GlobalFilter b() {
           return new BFilter();
       }
   
       public class BFilter implements GlobalFilter, Ordered {
   
           @Override
           public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   			// 这里获取到的traceId是N/A
               exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
               return chain.filter(exchange).then(Mono.fromRunnable(() ->
               {
   				// 这里获取到的也是N/A
                   String traceId2 = TraceContext.traceId();
                   System.out.println("traceId:" + traceId2);
               }));
           }
   
           @Override
           public int getOrder() {
               return 1;
           }
       }
   
   }
   
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou edited a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou edited a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001299649


   > 
   
   Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
   
   Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
   
   Field field = entrySpanClazz.getDeclaredField("owner");
   
   field.setAccessible(true);
   
   Object ownerInstance = field.get(entrySpanInstance);
   
   Class<?> ownerClazz = ownerInstance.getClass();
   
   Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
   
   String traceId = (String) getTraceId.invoke(ownerInstance);
   
   
   You need to write this code in the filter method.
   
   Hope it helps you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833424090


   `package com.example.gatewaydemo.filter;
   
   import org.apache.skywalking.apm.toolkit.trace.TraceContext;
   import org.springframework.cloud.gateway.filter.GatewayFilterChain;
   import org.springframework.cloud.gateway.filter.GlobalFilter;
   import org.springframework.context.annotation.Bean;
   import org.springframework.context.annotation.Configuration;
   import org.springframework.core.Ordered;
   import org.springframework.web.server.ServerWebExchange;
   import reactor.core.publisher.Mono;
   
   @Configuration
   public class FilterConfig {
   
       @Bean
       public GlobalFilter b() {
           return new BFilter();
       }
   
       public class BFilter implements GlobalFilter, Ordered {
   
           @Override
           public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   			// 这里获取到的traceId是N/A
               exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
               return chain.filter(exchange).then(Mono.fromRunnable(() ->
               {
   				// 这里获取到的也是N/A
                   String traceId2 = TraceContext.traceId();
                   System.out.println("traceId:" + traceId2);
               }));
           }
   
           @Override
           public int getOrder() {
               return 1;
           }
       }
   
   }
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] ralphgj commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
ralphgj commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-871862122


   Try to get traceid by implementing method of `HttpHeadersFilter#filter`
   
   > > `
   > > 包com.example.gatewaydemo.filter;
   > > 导入org.apache.skywalking.apm.toolkit.trace.TraceContext;
   > > 导入org.springframework.cloud.gateway.filter.GatewayFilterChain;
   > > 导入org.springframework.cloud.gateway.filter.GlobalFilter;
   > > 导入org.springframework.context.annotation.Bean;
   > > 导入org.springframework.context.annotation.Configuration;
   > > 导入org.springframework.core.Ordered;
   > > 导入org.springframework.web.server.ServerWebExchange;
   > > 导入reactor.core.publisher.Mono;
   > > @configuration
   > > 公共类FilterConfig {
   > > ```
   > > @Bean
   > > public GlobalFilter b() {
   > >     return new BFilter();
   > > }
   > > 
   > > public class BFilter implements GlobalFilter, Ordered {
   > > 
   > >     @Override
   > >     public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   > > 		// The value here is N/A
   > >         exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
   > >         return chain.filter(exchange).then(Mono.fromRunnable(() ->
   > >         {
   > > 			// The value here is also N/A
   > >             String traceId2 = TraceContext.traceId();
   > >             System.out.println("traceId:" + traceId2);
   > >         }));
   > >     }
   > > 
   > >     @Override
   > >     public int getOrder() {
   > >         return 1;
   > >     }
   > > }
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > }
   > > `
   > 
   > Hello, I also encountered this problem. Using TraceContext.traceId() in the gateway, the traceId cannot be obtained. How did you solve it?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-913945204


   There are related classes in the skywalking source code in this picture. 
   Finally, you can get the traceid through the method getReadablePrimaryTraceId() in interface AbstractTracerContext.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou removed a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou removed a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001298651


   
   ```java
   // 获取skywalking设置到exchange中的span实例,并使用反射获取其owner字段(该字段从父类的父类继承而来,类型为TracingContext)
               Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
               Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
               Field field = entrySpanClazz.getDeclaredField("owner");
               // 利用反射调用owner的getReadablePrimaryTraceId()方法,以获取traceId
               field.setAccessible(true);
               Object ownerInstance = field.get(entrySpanInstance);
               Class<?> ownerClazz = ownerInstance.getClass();
               Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
               String traceId = (String) getTraceId.invoke(ownerInstance);
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou edited a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou edited a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001299649


   > 
   
   Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
   
   Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
   
   Field field = entrySpanClazz.getDeclaredField("owner");
   
   field.setAccessible(true);
   
   Object ownerInstance = field.get(entrySpanInstance);
   
   Class<?> ownerClazz = ownerInstance.getClass();
   
   Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
   
   String traceId = (String) getTraceId.invoke(ownerInstance);
   
   
   
   
   You need to write this code in the filter method.
   
   Hope it helps you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-913942649


   > > `
   > > 包com.example.gatewaydemo.filter;
   > > 导入org.apache.skywalking.apm.toolkit.trace.TraceContext;
   > > 导入org.springframework.cloud.gateway.filter.GatewayFilterChain;
   > > 导入org.springframework.cloud.gateway.filter.GlobalFilter;
   > > 导入org.springframework.context.annotation.Bean;
   > > 导入org.springframework.context.annotation.Configuration;
   > > 导入org.springframework.core.Ordered;
   > > 导入org.springframework.web.server.ServerWebExchange;
   > > 导入reactor.core.publisher.Mono;
   > > @configuration
   > > 公共类FilterConfig {
   > > ```
   > > @Bean
   > > public GlobalFilter b() {
   > >     return new BFilter();
   > > }
   > > 
   > > public class BFilter implements GlobalFilter, Ordered {
   > > 
   > >     @Override
   > >     public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   > > 		// The value here is N/A
   > >         exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
   > >         return chain.filter(exchange).then(Mono.fromRunnable(() ->
   > >         {
   > > 			// The value here is also N/A
   > >             String traceId2 = TraceContext.traceId();
   > >             System.out.println("traceId:" + traceId2);
   > >         }));
   > >     }
   > > 
   > >     @Override
   > >     public int getOrder() {
   > >         return 1;
   > >     }
   > > }
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > }
   > > `
   > 
   > Hello, I also encountered this problem. Using TraceContext.traceId() in the gateway, the traceId cannot be obtained. How did you solve it?
   
   Hello,I got the traceid through reflection. Through debug, we can see that there is the traceId we need in the exchange object
   ![image](https://user-images.githubusercontent.com/22254487/132274359-3db30544-88d3-4d6a-8fcb-8dbd1c2812ff.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou removed a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou removed a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-913945204


   There are related classes in the skywalking source code in this picture. 
   Finally, you can get the traceid through the method getReadablePrimaryTraceId() in interface AbstractTracerContext.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] xiaozuo2020 commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
xiaozuo2020 commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001848175


   > 
   
   
   
   > > 
   > 
   > Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
   > 
   > Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
   > 
   > Field field = entrySpanClazz.getDeclaredField("owner");
   > 
   > field.setAccessible(true);
   > 
   > Object ownerInstance = field.get(entrySpanInstance);
   > 
   > Class<?> ownerClazz = ownerInstance.getClass();
   > 
   > Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
   > 
   > String traceId = (String) getTraceId.invoke(ownerInstance);
   > 
   > 您需要在过滤器方法中编写此代码。
   > 
   > 希望对你有帮助。
   
   3q,so much!!!
   that day, I found another way 
   modify the 2.1x gateway plugin,this plugin  includ webflux plugin code
   ![1122](https://user-images.githubusercontent.com/52436771/147524244-afcf41d6-fe9e-4002-8454-0780e0944256.png)
   
   then  i can get traceID in attributes
   
   ![445](https://user-images.githubusercontent.com/52436771/147524441-aa79abad-ca7c-4038-a553-6fe2327fdae2.png)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] xiaozuo2020 commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
xiaozuo2020 commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1000999397


   > There are related classes in the skywalking source code in this picture. Finally, you can get the traceid through the method getReadablePrimaryTraceId() in interface AbstractTracerContext. ![image](https://user-images.githubusercontent.com/22254487/132275108-11cbe067-5e72-4570-8630-672d9134aa20.png)
   
   hello could you show me the code? I try to get the traceID by reflection,but i am failed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou edited a comment on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou edited a comment on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001298651


   > 
   
   `// 获取skywalking设置到exchange中的span实例,并使用反射获取其owner字段(该字段从父类的父类继承而来,类型为TracingContext)
               Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
               Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
               Field field = entrySpanClazz.getDeclaredField("owner");
               // 利用反射调用owner的getReadablePrimaryTraceId()方法,以获取traceId
               field.setAccessible(true);
               Object ownerInstance = field.get(entrySpanInstance);
               Class<?> ownerClazz = ownerInstance.getClass();
               Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
               String traceId = (String) getTraceId.invoke(ownerInstance);`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng closed issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
wu-sheng closed issue #6900:
URL: https://github.com/apache/skywalking/issues/6900


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833425187


   We never said you could always have trace id. You misunderstand the feature I think.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-1001298651


   > 
   
   `            // 获取skywalking设置到exchange中的span实例,并使用反射获取其owner字段(该字段从父类的父类继承而来,类型为TracingContext)
               Object entrySpanInstance = exchange.getAttributes().get("SKYWALING_SPAN");
               Class<?> entrySpanClazz = entrySpanInstance.getClass().getSuperclass().getSuperclass();
               Field field = entrySpanClazz.getDeclaredField("owner");
               // 利用反射调用owner的getReadablePrimaryTraceId()方法,以获取traceId
               field.setAccessible(true);
               Object ownerInstance = field.get(entrySpanInstance);
               Class<?> ownerClazz = ownerInstance.getClass();
               Method getTraceId = ownerClazz.getMethod("getReadablePrimaryTraceId");
               String traceId = (String) getTraceId.invoke(ownerInstance);
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833425033


   `
   package com.example.gatewaydemo.filter;
   
   import org.apache.skywalking.apm.toolkit.trace.TraceContext;
   import org.springframework.cloud.gateway.filter.GatewayFilterChain;
   import org.springframework.cloud.gateway.filter.GlobalFilter;
   import org.springframework.context.annotation.Bean;
   import org.springframework.context.annotation.Configuration;
   import org.springframework.core.Ordered;
   import org.springframework.web.server.ServerWebExchange;
   import reactor.core.publisher.Mono;
   
   @Configuration
   public class FilterConfig {
   
       @Bean
       public GlobalFilter b() {
           return new BFilter();
       }
   
       public class BFilter implements GlobalFilter, Ordered {
   
           @Override
           public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   			// The value here is N/A
               exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
               return chain.filter(exchange).then(Mono.fromRunnable(() ->
               {
   				// The value here is also N/A
                   String traceId2 = TraceContext.traceId();
                   System.out.println("traceId:" + traceId2);
               }));
           }
   
           @Override
           public int getOrder() {
               return 1;
           }
       }
   
   }
   
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833433356


   Although I don't quite understand, but thank you for your explanation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] 504099993 commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
504099993 commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-844175401


   > `
   > 包com.example.gatewaydemo.filter;
   > 
   > 导入org.apache.skywalking.apm.toolkit.trace.TraceContext;
   > 导入org.springframework.cloud.gateway.filter.GatewayFilterChain;
   > 导入org.springframework.cloud.gateway.filter.GlobalFilter;
   > 导入org.springframework.context.annotation.Bean;
   > 导入org.springframework.context.annotation.Configuration;
   > 导入org.springframework.core.Ordered;
   > 导入org.springframework.web.server.ServerWebExchange;
   > 导入reactor.core.publisher.Mono;
   > 
   > @configuration
   > 公共类FilterConfig {
   > 
   > ```
   > @Bean
   > public GlobalFilter b() {
   >     return new BFilter();
   > }
   > 
   > public class BFilter implements GlobalFilter, Ordered {
   > 
   >     @Override
   >     public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   > 		// The value here is N/A
   >         exchange.getResponse().getHeaders().set("tid", TraceContext.traceId());
   >         return chain.filter(exchange).then(Mono.fromRunnable(() ->
   >         {
   > 			// The value here is also N/A
   >             String traceId2 = TraceContext.traceId();
   >             System.out.println("traceId:" + traceId2);
   >         }));
   >     }
   > 
   >     @Override
   >     public int getOrder() {
   >         return 1;
   >     }
   > }
   > ```
   > 
   > }
   > 
   > `
   
   Hello, I also encountered this problem. Using TraceContext.traceId() in the gateway, the traceId cannot be obtained. How did you solve it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] woshishitou commented on issue #6900: SpringcloudGateway can't get traceId

Posted by GitBox <gi...@apache.org>.
woshishitou commented on issue #6900:
URL: https://github.com/apache/skywalking/issues/6900#issuecomment-833426839


   https://github.com/apache/skywalking/issues/3891
   But he got the value here,we use the same method.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org