import { AsyncLocalStorage } from 'async_hooks';

// src/observability/context-storage.ts
var spanContextStorage = new AsyncLocalStorage();
function getCurrentSpan() {
  return spanContextStorage.getStore();
}
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 };
//# sourceMappingURL=chunk-5Z576KMI.js.map
//# sourceMappingURL=chunk-5Z576KMI.js.map