Created
January 28, 2020 16:28
-
-
Save Ananto30/376efa522390301415dd7cf5a03dcdc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Slf4j | |
public class TraceIdFilter implements WebFilter { | |
@Override | |
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | |
Map<String, String> headers = exchange.getRequest().getHeaders().toSingleValueMap(); | |
var traceId = ""; | |
if (headers.containsKey("X-B3-TRACEID")) { | |
traceId = headers.get("X-B3-TRACEID"); | |
MDC.put("X-B3-TraceId", traceId); | |
} else if (!exchange.getRequest().getURI().getPath().contains("/actuator")) { | |
log.warn("TRACE_ID not present in header: {}", exchange.getRequest().getURI()); | |
} | |
return chain.filter(exchange); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment