1. The problem I’m having:
Hey. Currently we’re using Nginx and, through Lua plugin, we’re logging (JSON) request and response bodies of incoming HTTP requests. We’re seeing quite a lot of traffic and care for PII, so:
- PII data is obfuscated with Regex
- only first 1k characters of responses are stored
- only error (>=400 status) responses are stored
As far as I know, requests and responses are buffered in that case. This data is very useful for debugging purposes: whenever frontend sends a malformed request (missing required keys, invalid data types, missing client side validation etc), backend responds with an error (4xx) which we do not track otherwise. If a user reports a problem, we can then trace back user’s steps and see what exactly the user did and what went wrong.
The thing is that Caddy does not allow that; and I’m not seeing a 3rd party solution to use either. As mentioned in a similar topic, a placeholder containing request’s body is available, but cannot be used to log messages; there also would be no option to obfuscate it properly it seems. And response body is just not available as a placeholder at all.
One alternative I’ve considered is logging requests/responses on the application side, but this scatters the access log to different places and makes for a worse developer experience searching through both logs. It also makes it application specific, requiring us to implement it for every service we have, which is not ideal.
The most performant solution would be to implement this on the web server side, but I understand this comes with a performance penalty. Either way, that performance hit under conditions I’ve specified is still many times smaller than doing the same thing on the application level.
There were two posts like this in the past; but authors did not communicate why they needed this feature, which is why I created the third thread
So the two questions are:
- is it possible at all to implement it somewhat efficiently, given my conditions above?
- are there any other solutions to this problem that I’m unaware of?
Thanks
2. Error messages and/or full log output:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
3. Caddy version:
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
4. How I installed and ran Caddy:
a. System environment:
Docker image