NODEJS Contents

Correlation IDs

Correlation IDs tie together logs from a single request across services, making debugging and incident response far faster.

On this page

What Is a Correlation ID

A correlation ID (often called requestId) is a unique identifier assigned at the start of a request and included in every log line related to that request.

Why It Matters

Without correlation IDs, tracing a failure across logs is guesswork. With them, you can filter logs instantly by requestId.

Implementation Pattern

import crypto from 'crypto';

function requestIdMiddleware(req, res, next) {
  req.requestId = crypto.randomUUID();
  res.setHeader('X-Request-Id', req.requestId);
  next();
}

Cross-Service Propagation

Forward correlation IDs to downstream services via headers. This enables distributed tracing and log stitching.

Production Rule

Every error response should include requestId so support teams can correlate client reports with logs.