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:43:07 UTC
[GitHub] [skywalking] woshishitou removed a comment on issue #6900: SpringcloudGateway can't get traceId
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