UNPKG

@mastra/core

Version:
40 lines (37 loc) 1.34 kB
'use strict'; var chunkLP4WZA6D_cjs = require('./chunk-LP4WZA6D.cjs'); var async_hooks = require('async_hooks'); var spanContextStorage = new async_hooks.AsyncLocalStorage(); function getCurrentSpan() { return spanContextStorage.getStore(); } var initialized = false; function initContextStorage() { if (initialized) return; initialized = true; chunkLP4WZA6D_cjs.setCurrentSpanResolver(getCurrentSpan); chunkLP4WZA6D_cjs.setExecuteWithContext(executeWithContext); chunkLP4WZA6D_cjs.setExecuteWithContextSync(executeWithContextSync); } async function executeWithContext(params) { const { span, fn } = params; const wrappedFn = span ? () => spanContextStorage.run(span, fn) : fn; if (span?.executeInContext) { return span.executeInContext(wrappedFn); } return wrappedFn(); } function executeWithContextSync(params) { const { span, fn } = params; const wrappedFn = span ? () => spanContextStorage.run(span, fn) : fn; if (span?.executeInContextSync) { return span.executeInContextSync(wrappedFn); } return wrappedFn(); } exports.executeWithContext = executeWithContext; exports.executeWithContextSync = executeWithContextSync; exports.getCurrentSpan = getCurrentSpan; exports.initContextStorage = initContextStorage; //# sourceMappingURL=chunk-HOYHM6JF.cjs.map //# sourceMappingURL=chunk-HOYHM6JF.cjs.map