feat(http): add http.client.log for logging outgoing HTTP requests#4337
Open
reinkrul wants to merge 4 commits into
Open
feat(http): add http.client.log for logging outgoing HTTP requests#4337reinkrul wants to merge 4 commits into
reinkrul wants to merge 4 commits into
Conversation
Adds a configurable log level for outgoing HTTP requests/responses made by the node, mirroring http.log for incoming traffic. Reuses the existing http.LogLevel enum (nothing/metadata/metadata-and-body) and defaults to nothing. Wired up in http.configureClient() via a transport-wrapping hook on the http client package. Assisted by AI
The logging transport wrapper was decided when the HTTP client was created. Engines that build their clients before the HTTP engine is configured (e.g. auth's OpenID4VCI client) never got the wrapper, since client.RequestLogger was still nil at construction. The HTTP engine is registered/configured last, so http.client.log had no effect on those clients. Always install a thin loggingTransport indirection in getTransport that reads RequestLogger per request, mirroring how StrictMode is read at request time. Clients created before logging is configured now log. Assisted by AI
Contributor
0 new issues
|
Contributor
|
Coverage Impact ⬆️ Merging this pull request will increase total coverage on Modified Files with Diff Coverage (7)
🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
Make the log level the single control instead of also depending on the global debug verbosity: - Log request and response headers at both 'metadata' and 'metadata-and-body' (previously headers required debug verbosity). - Mask credential-bearing request headers (Authorization, Proxy-Authorization) so they don't leak into the logs. Response WWW-Authenticate is a challenge, not a credential, so it is not masked. Assisted by AI
Relocate the outgoing-request logger from the http package to http/client, where the rest of the client transport code lives, and address naming: - The round tripper is now loggingTransport (it logs both request and response), gated by client.LogRequests / client.LogRequestBodies which are read at request time. This replaces the clientRequestLogger type and the RequestLogger func indirection. - Extract the loggable-content-types list to http/log.IsLoggableContentType as the single source of truth, used by both the client logger and the server-side body logger (previously duplicated). Assisted by AI
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.

Summary
Adds a configurable log level for outgoing HTTP requests/responses made by the node, mirroring the existing
http.log(which logs incoming/server-side traffic). Reuses the existinghttp.LogLevelenum and defaults tonothing(no behavior change unless explicitly enabled).New config option
http.client.log:nothing(default)metadatamethod,uri,status,headersmetadata-and-bodyThe log level is the single control — no dependency on the global debug verbosity.
Header masking
Credential-bearing request headers are masked (
Authorization,Proxy-Authorization) so tokens don't leak into logs. ResponseWWW-Authenticateis a challenge, not a credential, so it is left intact.How it works
http/client(loggingTransport), alongside the rest of the client transport code. It logs both the request and the response.client.LogRequests/client.LogRequestBodies, which are read at request time, not when the client is created. This matters because the HTTP engine is configured last, while other engines (e.g. auth's OpenID4VCI client) build their HTTP clients earlier — a construction-time check would miss those clients.getTransportalways installsloggingTransport; whether anything is logged is decided per request.http.configureClient()maps thehttp.client.logenum to those two flags.http/log.IsLoggableContentType, used by both the client logger and the server-side body logger (previously duplicated).http/logonly depends oncore, so bothhttpandhttp/clientcan import it without a cycle.Notes
application/json,application/did+json,application/vc+json,application/x-www-form-urlencoded.HTTP client request failedline only appears for connection-level errors (refused/TLS/timeout/strict-mode rejection).Out of scope (flagged, not changed)
The server-side request logger checks
logger.Level >= logrus.DebugLevelon a*logrus.Entry(http/requestlogger.go).Entry.Levelis always0(panic level), so that "log headers at debug" path is effectively dead. Left untouched here to keep this diff tight; worth a follow-up.Tests
http/client/requestlogger_test.go— disabled, metadata-only (headers present), metadata-and-body, sensitive-header masking, non-loggable content type, transport error.http/client/client_test.go— regression: client created before logging is enabled still logs.http/engine_test.go—configureClientmaps each level to the client flags.Assisted by AI