Extracts/generates request ID for correlation, enabling HTTP logging and observability middleware.
// Source: https://github.com/SweetSophia/openclaw-pixel-agents | License: MIT | Copyright 2026 Sherina
// Provided via justclaw.it.com; keep this notice with the code.
import type { NextFunction, Request, Response } from "express";
import { randomUUID } from "node:crypto";
import { logger, type Logger } from "./logger";
const REQUEST_ID_HEADER = "X-Request-Id";
const REQUEST_ID_HEADER_KEY = REQUEST_ID_HEADER.toLowerCase();
const SAFE_ID = /^[a-zA-Z0-9_.\-]{1,128}$/;
/**
* Extract a request correlation id from the incoming `X-Request-Id` header,
* validating that it is a safe opaque token (alphanumeric + a few separators,
* max 128 chars) to prevent log injection. Falls back to a fresh UUID when
* the header is absent or invalid.
*
* The id is stored on `req.id` and echoed on the r
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key