Spring Cloud Gateway添加自定义traceId

网关中增加全局过滤器

@Bean
public GlobalFilter c() {
    return (exchange, chain) -> {
        exchange.getRequest().mutate().header("traceId", UUID.randomUUID().toString()).build();
        return chain.filter(exchange);
    };
}

下游系统获取

@GetMapping("/test”)
public JSONObject search(@RequestHeader String traceId){
    log.info("traceId {}",traceId);
}

 

posted @ 2021-03-18 10:55  YoungDeng  阅读(1980)  评论(0编辑  收藏  举报