import { AsyncLocalStorage } from 'async_hooks'; import { randomUUID } from 'crypto'; const correlationStore = new AsyncLocalStorage(); export function createCorrelationId({ issueKey, routeName } = {}) { const shortId = randomUUID().split('-')[0]; if (issueKey) { return `${issueKey}-${shortId}`; } if (routeName) { return `${routeName}-${shortId}`; } return shortId; } export function getCorrelationId() { return correlationStore.getStore(); } export function runWithCorrelationId(correlationId, fn) { return correlationStore.run(correlationId, fn); }