Webflux request/response logging
Asked Answered
A

0

7

I believe it is a standard to log request and response in order to track down any issues reported by users and also to integrate it with tools like Splunk.

I've found 2 approaches so far, but none of them is really solving this issue properly:

  1. https://mcmap.net/q/319511/-how-to-log-request-and-response-bodies-in-spring-webflux
  2. https://mcmap.net/q/319511/-how-to-log-request-and-response-bodies-in-spring-webflux

Someone even wrote it is against reactive stack: https://mcmap.net/q/319511/-how-to-log-request-and-response-bodies-in-spring-webflux

So I have questions:

  1. Isn't there any recommended way of doing it by Spring team?
  2. If logging in webflux is against reactive stack then how should we actually log request/response?
  3. If Webflux is not a proper place to log request/response then where should we catch those information from? Nginx could possibly log it with a request id - but is it a proper way of solving this issue?
Abortive answered 26/10, 2020 at 10:3 Comment(4)
I am not a spring-team member, however I am quite surprised that such basic topic has not be somehow clearly supported in official documentation of webflux - especially looking into countless questions of same type in SO and in general over internet; what I found "best" option for logging responses is from chapter 4.2 in baeldung.com/spring-log-webclient-calls, adding custom LoggingHandler directly into HttpClient; would be delighted to hear other opinions though :)Mobility
and my personal opinion on gateway (nginx) logging - assuming the "request ID" or other kind of "trace/span" is generated by the service - might be hard to correlate the log on nginx; also - nginx will not allow any easy obfuscation of sensitive data, like in example github.com/zalando/logbook offersMobility
@Mobility baeldung article is about logging webClient req&res. I meant req&res that comes directly to Webflux app. Not calls that Webflix make using webClient (although this is another issue). As far as I know nginx can generate a random UUID and add it as a new header to a request. Then in your application you can log this header too so you will have a correlationAbortive
@Abortive Did you find anything?Uncomfortable

© 2022 - 2024 — McMap. All rights reserved.