Skip to content

feat(gateway): add per-request logging to gateway with --request-logging#13147

Merged
rvagg merged 2 commits intomasterfrom
rvagg/gateway-logging
Jun 21, 2025
Merged

feat(gateway): add per-request logging to gateway with --request-logging#13147
rvagg merged 2 commits intomasterfrom
rvagg/gateway-logging

Conversation

@rvagg
Copy link
Member

@rvagg rvagg commented May 29, 2025

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])"}

@rvagg rvagg requested review from ZenGround0, Copilot and rjan90 May 29, 2025 05:36
@github-project-automation github-project-automation bot moved this to 📌 Triage in FilOz May 29, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces an optional request-logging middleware that captures incoming HTTP requests (including POST bodies) for debugging.

  • Adds a --request-logging CLI flag and wires it into the gateway handler options.
  • Implements LoggingHandler middleware 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 rjan90 added the skip/changelog This change does not require CHANGELOG.md update label May 29, 2025
@rjan90 rjan90 moved this from 📌 Triage to 🔎 Awaiting Review in FilOz May 29, 2025
@github-project-automation github-project-automation bot moved this from 🔎 Awaiting Review to ✔️ Approved by reviewer in FilOz May 29, 2025
@rvagg
Copy link
Member Author

rvagg commented May 29, 2025

some good copilot suggestions in there, I'll tweak when I have time

@BigLep
Copy link
Member

BigLep commented Jun 10, 2025

@rvagg : are you able to land this week?

@rvagg
Copy link
Member Author

rvagg commented Jun 10, 2025

Maybe

rvagg added 2 commits June 20, 2025 11:57
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).
@rvagg rvagg force-pushed the rvagg/gateway-logging branch from f6140ac to a778889 Compare June 20, 2025 10:48
@rvagg rvagg requested a review from masih June 20, 2025 10:49
@rvagg
Copy link
Member Author

rvagg commented Jun 20, 2025

Rebased and some of the minor suggestions addressed 🤞

@rvagg rvagg merged commit 287ae92 into master Jun 21, 2025
97 of 98 checks passed
@rvagg rvagg deleted the rvagg/gateway-logging branch June 21, 2025 00:15
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FilOz Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip/changelog This change does not require CHANGELOG.md update

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

6 participants