Implement structured logging with pino and request correlation
Description
The timing middleware in src/index.ts emits logs via a hand-rolled console.log(JSON.stringify(...)), gated on NODE_ENV !== "test". There is no log level, no error logging from the error handler, and no consistent field schema. This issue introduces a pino logger with the requestId as a correlation field and structured error logs.
Requirements and context
- Repository scope:
StableRoute-Org/Stableroute-backend only.
- Add
pino and create src/logger.ts (create file) exporting a configured logger with level from LOG_LEVEL.
- Replace the manual request log with a child logger bound to
requestId, method, path, status, durationMs.
- Log errors from the final error handler at
error level with the stack (but never the request body).
- Keep logs suppressed under
NODE_ENV=test (or route to a silent transport) so test output stays clean.
Suggested execution
- Fork the repo and create a branch
git checkout -b enhancement/observability-12-pino-logging
- Implement changes
- Write code in: create
src/logger.ts; update src/index.ts.
- Write comprehensive tests in:
src/__tests__/index.test.ts — assert the logger is invoked with the correlation id (spy/mock), and that test runs stay quiet.
- Add documentation: document
LOG_LEVEL in README.md.
- Add TSDoc on the logger module.
- Validate security: redact
Authorization/X-Api-Key headers from logs.
- Test and commit
Test and commit
- Run
npm run build, npm run lint, and npm test.
- Cover edge cases: error-path logging, redaction, level filtering.
- Paste full
npm test output in the PR.
Example commit message
feat(observability): add pino structured logging with request correlation
Guidelines
- Minimum 95 percent test coverage for impacted code.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
- ⭐ 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 pino and request correlation
Description
The timing middleware in
src/index.tsemits logs via a hand-rolledconsole.log(JSON.stringify(...)), gated onNODE_ENV !== "test". There is no log level, no error logging from the error handler, and no consistent field schema. This issue introduces apinologger with therequestIdas a correlation field and structured error logs.Requirements and context
StableRoute-Org/Stableroute-backendonly.pinoand createsrc/logger.ts(create file) exporting a configured logger with level fromLOG_LEVEL.requestId, method, path, status, durationMs.errorlevel with the stack (but never the request body).NODE_ENV=test(or route to a silent transport) so test output stays clean.Suggested execution
git checkout -b enhancement/observability-12-pino-loggingsrc/logger.ts; updatesrc/index.ts.src/__tests__/index.test.ts— assert the logger is invoked with the correlation id (spy/mock), and that test runs stay quiet.LOG_LEVELinREADME.md.Authorization/X-Api-Keyheaders from logs.Test and commit
npm run build,npm run lint, andnpm test.npm testoutput in the PR.Example commit message
feat(observability): add pino structured logging with request correlationGuidelines
Community & contribution rewards