feat(http-backend): add injectable structured request logging hook - #370
feat(http-backend): add injectable structured request logging hook#370melanindebbie wants to merge 1 commit into
Conversation
createHttpWalletBackend now accepts an optional logHook that is invoked once
per completed request with { method, url, status, durationMs }, so consumers
can parse, filter, and route on structured fields instead of free-form output.
Backwards-compatible: omitting the hook leaves logging disabled. Adds a test
suite covering success, failure, the 404 lookup edge case, and the no-hook
path, and documents the new interface in the README.
|
Hi @melanindebbie — thanks for the contribution! We do not accept pull requests to the You don't need to reopen anything — your work is preserved and this PR now targets |
|
Thanks for the contribution — but contributor PRs may only change files inside This PR touches file(s) outside that folder:
Please open a new PR with your changes scoped to Questions? Ask in the Telegram group. |
Closes #247
Summary
Adds an optional structured logging hook to
createHttpWalletBackendso consumer log pipelines can parse, filter, and route on structured fields (method,url,status,durationMs) instead of free-form console output.What changed
src/http-backend.ts— exportedRequestLoginterface,RequestLogHooktype, and added an optional thirdlogHookparameter tocreateHttpWalletBackend. The internalposthelper now measures round-trip duration withperformance.now()and invokes the hook once per completed request (success and failure alike).src/http-backend.test.ts— new test file with 7 tests covering the logging hook on every endpoint and edge case (see below).README.md— added a "Logging" section with a usage example and updated the Helpers table to document thelog?parameter.Key design decisions
undefined). No opinionated logger dependency, noconsole.*calls. Consumers wire their own structured logger.fetchImplreturns, before error-throwing logic, so a 500 or 503 is logged the same way as a 200.fetchImplcontract and keeps the behavior predictable. Consumer hooks should be fast and fail-safe.performance.now()for timing — browser/Node native, sub-millisecond precision, no extra dependencies.Acceptance criteria checklist
logHook?: RequestLogHookthird param oncreateHttpWalletBackendRequestLoginterface has all four fields; hook is called inpost()with values from the actual requesthttp-backend.test.ts: success paths (create, submit), failure paths (create 500, connect 401, submit 503), edge case (404 returns undefined), and no-hook no-opTest output
All 521 tests pass. Typecheck (
tsc --noEmit) is clean. No lint issues.Follow-ups
Security note
No secrets, keys, or sensitive data are included in log entries. The hook receives only the HTTP method, full URL (which may include a base URL the consumer controls), status code, and duration. No request or response bodies are logged.