import { setCurrentSpanResolver, setExecuteWithContext, setExecuteWithContextSync } from './chunk-JK5J6E2A.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-6VZD3BHY.js.map
//# sourceMappingURL=chunk-6VZD3BHY.js.map