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

--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]