import { setCurrentSpanResolver, setExecuteWithContext, setExecuteWithContextSync } from './chunk-G2SVLNSC.js';
import { AsyncLocalStorage } from 'async_hooks';

var spanContextStorage = new AsyncLocalStorage();
function getCurrentSpan() {
  return spanContextStorage.getStore();
}
var initialized = false;
function initContextStorage() {
  if (initialized) return;
  initialized = true;
  setCurrentSpanResolver(getCurrentSpan);
  setExecuteWithContext(executeWithContext);
  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();
}

export { executeWithContext, executeWithContextSync, getCurrentSpan, initContextStorage };
//# sourceMappingURL=chunk-F2AHXK54.js.map
//# sourceMappingURL=chunk-F2AHXK54.js.map