13 lines
321 B
TypeScript
13 lines
321 B
TypeScript
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
|
export interface RequestContext {
|
|
requestId: string;
|
|
userId?: string;
|
|
}
|
|
|
|
export const requestContextStorage = new AsyncLocalStorage<RequestContext>();
|
|
|
|
export function getRequestId(): string {
|
|
return requestContextStorage.getStore()?.requestId ?? 'unknown';
|
|
}
|