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/19 14:45:15 UTC

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

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