Implement structured logging with a real logger and request correlation
Description
Logging in src/index.ts is a single console.log(JSON.stringify(...)) in the request timer middleware, gated only by NODE_ENV !== "test", plus ad-hoc console.log/console.error in the shutdown path. There are no log levels, no redaction, and no shared logger. This issue introduces a structured logger (e.g. pino) with per-request correlation tied to the existing X-Request-Id.
Requirements and context
- Repository scope:
Agentpay-Org/Agentpay-backend only.
- Add a
src/logger.ts that exports a configured logger with a LOG_LEVEL env var.
- Replace the inline request-completion log and the shutdown
console.* calls with the logger, attaching requestId (already on req.id).
- Redact sensitive fields (
X-API-Key header, generated keys) from any logged object.
- Keep tests quiet by defaulting to
silent when NODE_ENV=test.
Suggested execution
- Fork the repo and create a branch
git checkout -b feature/observability-07-structured-logging
- Implement changes
- Write code in: new
src/logger.ts and the logging call sites in src/index.ts.
- Write comprehensive tests in: new
src/logger.test.ts — level filtering, redaction, requestId presence.
- Add documentation: document
LOG_LEVEL in README.md.
- Add TSDoc on the logger factory.
- Validate security assumptions: no secrets or full keys reach the log output.
- Test and commit
Test and commit
- Run
npm run build, npm test, and npm run lint.
- Cover edge cases: error logging, redaction of api keys, test-mode silence.
- Include the full
npm test output in the PR description.
Example commit message
feat: add structured pino logging with request correlation and redaction
Guidelines
- Minimum 95 percent test coverage for impacted modules.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
- ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.
Implement structured logging with a real logger and request correlation
Description
Logging in
src/index.tsis a singleconsole.log(JSON.stringify(...))in the request timer middleware, gated only byNODE_ENV !== "test", plus ad-hocconsole.log/console.errorin the shutdown path. There are no log levels, no redaction, and no shared logger. This issue introduces a structured logger (e.g. pino) with per-request correlation tied to the existingX-Request-Id.Requirements and context
Agentpay-Org/Agentpay-backendonly.src/logger.tsthat exports a configured logger with aLOG_LEVELenv var.console.*calls with the logger, attachingrequestId(already onreq.id).X-API-Keyheader, generated keys) from any logged object.silentwhenNODE_ENV=test.Suggested execution
git checkout -b feature/observability-07-structured-loggingsrc/logger.tsand the logging call sites insrc/index.ts.src/logger.test.ts— level filtering, redaction, requestId presence.LOG_LEVELinREADME.md.Test and commit
npm run build,npm test, andnpm run lint.npm testoutput in the PR description.Example commit message
feat: add structured pino logging with request correlation and redactionGuidelines
Community & contribution rewards