Small question regarding how to log the time spent for a http request please.
To avoid confusion, this question is regarding logs (not metrics), this question is about Webflux, this question is about outbound call, I am the client, trying to make a call to a server, and I need to time this operation, but from a log perspective.
Based on this snippet I am using:
@Override
public Mono<String> sendOutboundRequest() {
return webClient.post().retrieve().bodyToMono(String.class);
}
So far, I tried .log() but this is not writing the time spent directly, this solution needs another layer of parsing of the timestamp from the on subscribe and the on complete of log4j time.
I also tried .metrics(), this gets the time, but this only generates metrics, not a log.
I also tried some method execution surround
long start = System.nanoTime();
Mono<String> result = webClientIdms.post().retrieve().bodyToMono(String.class);
long end = System.nanoTime() - start;
LOGGER.info("this will not print the actual http request time " + end);
return result;
but this is not working, since in a reactive stack, this will not time the execution of the request when the reactive pipeline is executed.
May I ask what is the proper way to log the time taken please?
Thank you