feat(gateway): add per-request logging to gateway with --request-logging#13147
Merged
feat(gateway): add per-request logging to gateway with --request-logging#13147
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces an optional request-logging middleware that captures incoming HTTP requests (including POST bodies) for debugging.
- Adds a
--request-loggingCLI flag and wires it into the gateway handler options. - Implements
LoggingHandlermiddleware that reads, optionally truncates, and logs request details. - Provides a helper to extract the remote IP address.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| gateway/handler.go | Add LoggingHandler, WithRequestLogging option, and body logging logic |
| cmd/lotus-gateway/main.go | Add request-logging CLI flag and pass it to WithRequestLogging |
Comments suppressed due to low confidence (1)
gateway/handler.go:354
- LoggingHandler lacks unit tests. Add tests to verify behavior for different HTTP methods, body sizes, and error scenarios.
// LoggingHandler logs incoming HTTP requests with details
rjan90
approved these changes
May 29, 2025
Member
Author
|
some good copilot suggestions in there, I'll tweak when I have time |
Member
|
@rvagg : are you able to land this week? |
Member
Author
|
Maybe |
Logs POST bodies too, so probably not ideal for environments where performance is critical, or where you think there might be data leakage (although the gateway is intended for non-sensitive traffic).
f6140ac to
a778889
Compare
Member
Author
|
Rebased and some of the minor suggestions addressed 🤞 |
masih
reviewed
Jun 20, 2025
masih
approved these changes
Jun 20, 2025
ZenGround0
approved these changes
Jun 20, 2025
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Logs POST bodies too, so probably not ideal for environments where performance is critical, or where you think there might be data leakage (although the gateway is intended for non-sensitive traffic).
This was just a private branch feature but I found it super useful for debugging and decided there's a good chance I'm going to want this again. I also tried logging to stdout, but having it interleaved with error logs ended up being more useful. Unfortunately the JSON bodies get escaped to be reproduced as JSON output, but it's not terrible.
Another alternative I considered was providing a filename, so it ends up a bit like a classic HTTP server log,
--request-logging=access.log, but it goes a bit further than HTTP server logging with the request body capture so it may be best to not give the impression that this is the right thing to do.{"level":"info","ts":"2025-05-28T22:58:32.768+1000","logger":"gateway","caller":"gateway/handler.go:380","msg":"request","remote_ip":"192.168.1.12","method":"POST","url":"/rpc/v1","body":"{\"id\":\"0f6d72ba-f240-4ef9-83c8-9ecc42f5a635\",\"jsonrpc\":\"2.0\",\"method\":\"eth_getBalance\",\"params\":[\"0x0542c82a785fab8b53c7c59aaad7093d87265f3a\",\"0x29414a\"]}"} {"level":"info","ts":"2025-05-28T22:58:32.769+1000","logger":"gateway","caller":"gateway/handler.go:380","msg":"request","remote_ip":"192.168.1.12","method":"POST","url":"/rpc/v1","body":"{\"id\":\"e764c4b6-234c-44c0-b59c-5b75407488fe\",\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{\"to\":\"0x0e690d3e60b0576d01352ab03b258115eb84a047\",\"data\":\"0x01ffc9a780 ac58cd00000000000000000000000000000000000000000000000000000000\"},\"0x29414a\"]}"} {"level":"warn","ts":"2025-05-28T22:58:32.773+1000","logger":"rpc","caller":"go-jsonrpc@v0.7.0/handler.go:421","msg":"error in RPC call to 'eth_call': message execution failed (exit=[33], revert reason=[message failed with backtrace:\n00: f0162143 (method 3844450837) -- contract reverted at 86 (33)\n01: f0162143 (method 6) -- contract reverted at 349 (33)\n (RetCode=33)], vm error=[none])"}