feat: wire WithLogger into the default request pipeline - #690
Open
michaeldcanady wants to merge 3 commits into
Open
feat: wire WithLogger into the default request pipeline#690michaeldcanady wants to merge 3 commits into
michaeldcanady wants to merge 3 commits into
Conversation
WithLogger stored a logger that nothing ever invoked, so BYO logging had no observable effect. Add a kiota-style LoggingMiddleware innermost in the default client pipeline: every physical attempt (each retry resend, each redirect hop) logs method, sanitized URL, status, duration, and attempt count. Headers and bodies are never read and query strings and userinfo are stripped before logging, so tokens and credentials cannot leak. Clients supplied via WithHTTPClient keep their own pipeline; the default NoOpLogger means zero behavior change out of the box.
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 36593731 | Triggered | Basic Auth String | 22ac53c | internal/http/logging_middleware_test.go | View secret |
| 36599320 | Triggered | Basic Auth String | 9b1e966 | internal/http/logging_middleware_test.go | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Contributor
|
Review failed — opencode did not produce a review. See the workflow run for details. |
Contributor
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #690 +/- ##
==========================================
+ Coverage 86.57% 86.66% +0.08%
==========================================
Files 337 338 +1
Lines 8439 8486 +47
==========================================
+ Hits 7306 7354 +48
+ Misses 1132 1131 -1
Partials 1 1
🚀 New features to boost your workflow:
|
added 2 commits
August 25, 2026 17:33
GitGuardian flags credential-shaped strings even when they are obviously fake test fixtures. Rename the middleware-test markers to low-entropy example values; the leak assertions are unchanged in strength.
Codecov flagged the two uncovered statements on the diff: the snerrors.ErrNilConfig guard in WithLogger and errorCause's pass-through when the wrapped *url.Error has no inner cause. Also defang the last hunter2 fixture so secret scanners stay green.
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
LoggingMiddlewaretointernal/http, appended innermost in the default client pipeline so every physical attempt — each retry resend and each redirect hop — logs its own pair of lines (method + URL at request, status + duration at response).WithLoggerthrough to the pipeline: the option previously stored a logger that nothing ever invoked, so BYO logging had no effect.*url.Errorso embedded full URLs aren't echoed. Tests assert Bearer tokens, cookies, body contents, and query values never appear in output.NoOpLogger— zero behavior change out of the box. Clients supplied viaWithHTTPClientkeep their own pipeline (documented).website/docs/user-guide/configuration.mdx.Fixes #499
Test plan
go build ./...passes.go test ./...passes (new table-driven tests for the middleware, secret-leak assertions, and end-to-end wiring through a real client against an httptest server).gofmt -s -l .clean for changed files.golangci-lint run ./...— 0 issues.