I’d like to generate a random unique ID, possibly a UUID, for each request before forwarding it to my web app (using reverse_proxy).
I tried to avoid having to generate the request ID in Caddy (aka a “web server”), but I’d like to use Caddy’s access logs, which means that if I generate the request ID in my application then I won’t be able to correlate between the HTTP request and the application logs.
Any ideas?
Thanks in advance!
Edit: Now that I think about it, access logs also contain response headers, which would/should include the request ID, even if it was generated in the application. Is this still a good enough approach?
You can use the {http.request.uuid} placeholder to generate a UUID for the current request. This is cached, so if it’s used again during the same request, it will be reused. You can pass it to the upstream with header_up in your reverse_proxy.
Headers passed to the upstream won’t contain the UUID though, unless like you said, you add it to the response headers as well (which you could certainly do).
We don’t currently have a mechanism for adding arbitrary information to access logs, but that’s something we’re thinking about and that would certainly be a good usecase for this.