Skip to content

Instantly share code, notes, and snippets.

@Ananto30
Created January 28, 2020 16:28
Show Gist options
  • Save Ananto30/376efa522390301415dd7cf5a03dcdc6 to your computer and use it in GitHub Desktop.
Save Ananto30/376efa522390301415dd7cf5a03dcdc6 to your computer and use it in GitHub Desktop.
@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