unnbound-logger-sdk
Version:
A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.
24 lines (23 loc) • 731 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.traceContext = void 0;
const async_hooks_1 = require("async_hooks");
class TraceContextManager {
constructor() {
this.storage = new async_hooks_1.AsyncLocalStorage();
}
static getInstance() {
if (!TraceContextManager.instance) {
TraceContextManager.instance = new TraceContextManager();
}
return TraceContextManager.instance;
}
run(traceId, callback) {
return this.storage.run({ traceId }, callback);
}
getTraceId() {
const context = this.storage.getStore();
return context?.traceId;
}
}
exports.traceContext = TraceContextManager.getInstance();