chore: remove unused correlation middleware exports (#5333)

Verified dead-code removal: typecheck + tests + ESLint clean. Integrated into release/v3.8.41. Thanks @JxnLexn!
This commit is contained in:
Jan Leon
2026-06-29 15:07:27 +02:00
committed by GitHub
parent 105f0c84da
commit 6e66df78ae
2 changed files with 9 additions and 56 deletions

View File

@@ -41,58 +41,3 @@ export function runWithCorrelation(correlationId, fn) {
const id = correlationId || generateCorrelationId();
return correlationStore.run(id, fn);
}
/**
* Express/Next.js middleware that injects correlation IDs.
*
* Usage:
* // In Next.js middleware or Express app
* import { correlationMiddleware } from './correlationId.js';
* app.use(correlationMiddleware);
*
* @param {Request} request
* @param {Function} next
* @returns {Promise<Response>}
*/
export function correlationMiddleware(request, next) {
const requestId =
request.headers.get("x-request-id") ||
request.headers.get("x-correlation-id") ||
generateCorrelationId();
return runWithCorrelation(requestId, async () => {
const response = await next();
// Attach correlation ID to response
if (response && response.headers) {
response.headers.set("x-request-id", requestId);
}
return response;
});
}
/**
* Create a logger wrapper that automatically includes correlation IDs.
*
* @param {Object} baseLogger - Base logger with info/warn/error methods
* @returns {Object} Wrapped logger
*/
export function createCorrelatedLogger(baseLogger) {
const withCorrelation = (level, ...args) => {
const correlationId = getCorrelationId();
if (correlationId) {
const meta = typeof args[args.length - 1] === "object" ? args.pop() : {};
meta.correlationId = correlationId;
args.push(meta);
}
baseLogger[level](...args);
};
return {
info: (...args) => withCorrelation("info", ...args),
warn: (...args) => withCorrelation("warn", ...args),
error: (...args) => withCorrelation("error", ...args),
debug: (...args) => withCorrelation("debug", ...args),
};
}

View File

@@ -171,7 +171,15 @@ test("requestTimeout: getProviderTimeout returns provider-specific value", () =>
// ─── Correlation ID Tests ────────────────────────────
import { getCorrelationId, runWithCorrelation } from "../../src/shared/middleware/correlationId.ts";
import * as correlationId from "../../src/shared/middleware/correlationId.ts";
const { getCorrelationId, runWithCorrelation } = correlationId;
test("correlationId: public surface excludes unused wrapper helpers", () => {
assert.equal(Object.hasOwn(correlationId, "correlationMiddleware"), false);
assert.equal(Object.hasOwn(correlationId, "createCorrelatedLogger"), false);
assert.equal(typeof correlationId.getCorrelationId, "function");
assert.equal(typeof correlationId.runWithCorrelation, "function");
});
test("correlationId: getCorrelationId returns undefined outside context", () => {
assert.equal(getCorrelationId(), undefined);