Request ID Middleware (middleware/request-id.ts)

veritas-kanban · server/src/middleware/request-id.ts · typescript · MIT
infra, integration, fw:express

Generates or preserves a unique UUID for incoming HTTP requests. Use this to enable distributed tracing and debugging across your service architecture.

// Source: https://github.com/BradGroux/veritas-kanban | License: MIT | Copyright 2026 Digital Meld
// Provided via justclaw.it.com; keep this notice with the code.
import { Request, Response, NextFunction } from 'express';
import { randomUUID } from 'crypto';

/**
 * Request ID Middleware
 *
 * Assigns a unique identifier to every incoming request for tracing and
 * debugging. If the client sends an `X-Request-ID` header (e.g. from a
 * gateway or another service in a distributed system), that value is
 * preserved. Otherwise a new UUIDv4 is generated.
 *
 * The request ID is:
 *  - Stored in `res.locals.requestId` for downstream middleware / routes
 *  - Echoed back to the client via the `X-Request-ID` response header
 */
export function requestIdMiddleware(req: Request, res: Response, n

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key