-
Notifications
You must be signed in to change notification settings - Fork 594
Open
Labels
1 - triagedTickets that are safe to pick up for contributing in terms of likeliness of being acceptedTickets that are safe to pick up for contributing in terms of likeliness of being acceptedhelp wantedIdentifies issues that the core team will likely not have time to work onIdentifies issues that the core team will likely not have time to work ont:docsIssues related to the documentationIssues related to the documentation
Description
I need to customise the logger that gets returned by extractLog( log -> () ) so I can attach the current correlationId / userId / other fields into the MDC. However, I'm unable to accomplish this with the documentation I found. This is what I got so far:
public static RouteAdapter extractCorrelationId(Function<String, Route> inner) {
return optionalHeaderValueByName("X-CorrelationId", (corr) -> extractLog(log -> {
String correlationId = corr.orElseGet(() -> {
String c = UUID.randomUUID().toString();
log.debug("request does not have a upstream correlationId, assigning " + c);
return c;
});
return provide(correlationId, inner);
}));
}
and I was planning to decorate my root-route as follows:
public Route createRoute() {
return extractCorrelationId(corr -> extractLog(log -> {
LoggingAdapter newLog = log;
var newMDC = newLog.mdc().$plus(Tuple2.apply("correlationId", corr)); // this is a MDC and not a LoggingAdapter :(
// how to bring the newMDC into the newLog ? because AFAIK the MDC is a immutable list, thus I cannot simply change its values
return withLog(newLog, () -> allRoutes());
}));
}
Please provide a way on how a valid "LoggingAdapter" can be constructed from Java.
Metadata
Metadata
Assignees
Labels
1 - triagedTickets that are safe to pick up for contributing in terms of likeliness of being acceptedTickets that are safe to pick up for contributing in terms of likeliness of being acceptedhelp wantedIdentifies issues that the core team will likely not have time to work onIdentifies issues that the core team will likely not have time to work ont:docsIssues related to the documentationIssues related to the documentation