Skip to content

feat: wire WithLogger into the default request pipeline - #690

Open
michaeldcanady wants to merge 3 commits into
mainfrom
feat/withlogger-middleware
Open

feat: wire WithLogger into the default request pipeline#690
michaeldcanady wants to merge 3 commits into
mainfrom
feat/withlogger-middleware

Conversation

@michaeldcanady

Copy link
Copy Markdown
Owner

Summary

  • Adds a Kiota-style LoggingMiddleware to internal/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).
  • Wires WithLogger through to the pipeline: the option previously stored a logger that nothing ever invoked, so BYO logging had no effect.
  • Secret safety: headers and bodies are never read; URLs are sanitized (query string, fragment, userinfo stripped) before logging; transport errors are unwrapped past *url.Error so embedded full URLs aren't echoed. Tests assert Bearer tokens, cookies, body contents, and query values never appear in output.
  • Default stays NoOpLogger — zero behavior change out of the box. Clients supplied via WithHTTPClient keep their own pipeline (documented).
  • Documents emitted fields/levels in 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.

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.
@github-actions github-actions Bot added type: documentation Improvements or additions to documentation module: core Issues related to the Core Module labels Aug 25, 2026
@gitguardian

gitguardian Bot commented Aug 25, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
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
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. 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


🦉 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.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Review failed — opencode did not produce a review. See the workflow run for details.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://michaeldcanady.github.io/servicenow-sdk-go/pr-preview/pr-690/

Built to branch gh-pages at 2026-08-25 19:14 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.66%. Comparing base (c9f9074) to head (9b1e966).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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              
Files with missing lines Coverage Δ
internal/http/logging_middleware.go 100.00% <100.00%> (ø)
internal/http/servicenow_client_config.go 100.00% <100.00%> (ø)
internal/http/servicenow_request_adapter_config.go 100.00% <ø> (ø)
internal/http/servicenow_request_adapter_option.go 100.00% <100.00%> (+3.03%) ⬆️
servicenow_service_client_config.go 94.28% <100.00%> (+0.73%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

-g 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: core Issues related to the Core Module type: documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: BYO logging via WithLogger option

1 participant