jiraCloud/lib/correlation.js
jmcqueen 0b056739e9 Add modular Jira-to-Webex approvals service with Docker deployment.
Stabilize logging, correlation IDs, service-account Jira auth, and direct approver reminder DMs while splitting the monolith into focused modules with Compose-based deployment.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 08:34:47 -04:00

23 lines
605 B
JavaScript

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);
}