Skip to content

[BE-31] Add structured request logging middleware with correlation IDs in opsce module #756

@yusuftomilola

Description

@yusuftomilola

Problem

The backend has no request logging. When errors occur in production, there is no way to trace a request through the system or correlate incoming requests with outgoing responses in logs.

Proposed Solution

Create backend/src/opsce/common/middleware/logger.middleware.ts. Generate a UUID correlationId per request, attach it to request and response headers, and log structured JSON per request/response.

Acceptance Criteria

  • Each request gets a X-Correlation-Id UUID header (generated if not provided by the client)
  • Logs incoming request: method, URL, correlationId, userAgent, IP
  • Logs outgoing response: statusCode, duration in ms, correlationId
  • Sensitive headers (Authorization, Cookie) are redacted from logs
  • Middleware applied globally in OpsceModule
  • Log output is structured JSON for log aggregation compatibility

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions