Skip to content

feat(server): add request logging middleware with request IDs#807

Open
Dayz-tech-co wants to merge 6 commits into
bakeronchain:mainfrom
Dayz-tech-co:fix-238-request-logger-main-v2
Open

feat(server): add request logging middleware with request IDs#807
Dayz-tech-co wants to merge 6 commits into
bakeronchain:mainfrom
Dayz-tech-co:fix-238-request-logger-main-v2

Conversation

@Dayz-tech-co
Copy link
Copy Markdown
Contributor

@Dayz-tech-co Dayz-tech-co commented Apr 24, 2026

Closes #238

Summary

This PR adds structured API request logging with per-request correlation IDs to improve backend observability and request tracing.

What Changed

  • Added server/src/middleware/request-logger.middleware.ts
  • Generates a UUID requestId for every incoming request
  • Attaches requestId to req
  • Returns X-Request-Id in every response
  • Logs structured JSON on response finish with:
    • requestId
    • method
    • path
    • statusCode
    • durationMs
  • Uses pino for structured logging
  • Registers app.use(requestLogger) before routes in server/src/index.ts
  • Extends Express request typings to include requestId
  • Adds tests for request ID propagation, structured logging, and silent behavior in test mode

Why

The backend previously had no structured request logging, which made it difficult to trace errors, investigate slow requests, and correlate frontend issues with backend logs.

Testing

  • npm test -- request-logger.middleware.test.ts

Notes

  • npm run build currently fails because of unrelated pre-existing TypeScript errors elsewhere in the repo.

@Anuoluwapo25
Copy link
Copy Markdown
Contributor

please fix conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add API request logging middleware with request IDs (correlation IDs)

2 participants