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);
}

你可能感兴趣的:(Spring,Cloud)