Basically, I want to log a request/response informations in one log containing bodies/headers with a Spring WebClient
.
With Spring RestTemplate
we can do it with a ClientHttpRequestInterceptor
. I find about ExchangeFilterFunction
for Spring WebClient
but haven't managed to do something similar in a clean way. We can use this filter and log the request AND THEN the response but I need both on the same log trace.
Moreover, I haven't managed to get the response body with ExchangeFilterFunction.ofResponseProcessor
method.
I expect a log like this (current implementation working with a ClientHttpRequestInterceptor) with all the informations I need:
{
"@timestamp": "2019-05-14T07:11:29.089+00:00",
"@version": "1",
"message": "GET https://awebservice.com/api",
"logger_name": "com.sample.config.resttemplate.LoggingRequestInterceptor",
"thread_name": "http-nio-8080-exec-5",
"level": "TRACE",
"level_value": 5000,
"traceId": "e65634ee6a7c92a7",
"spanId": "7a4d2282dbaf7cd5",
"spanExportable": "false",
"X-Span-Export": "false",
"X-B3-SpanId": "7a4d2282dbaf7cd5",
"X-B3-ParentSpanId": "e65634ee6a7c92a7",
"X-B3-TraceId": "e65634ee6a7c92a7",
"parentId": "e65634ee6a7c92a7",
"method": "GET",
"uri": "https://awebservice.com/api",
"body": "[Empty]",
"elapsed_time": 959,
"status_code": 200,
"status_text": "OK",
"content_type": "text/html",
"response_body": "{"message": "Hello World!"}"
}
Does anyone manage to do something like this with Spring WebClient ? Or how would one proceed to track request/reponses issue with a Spring WebClient ?