'use strict';

var chunkH4CE7QA3_cjs = require('./chunk-H4CE7QA3.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;
  chunkH4CE7QA3_cjs.setCurrentSpanResolver(getCurrentSpan);
  chunkH4CE7QA3_cjs.setExecuteWithContext(executeWithContext);
  chunkH4CE7QA3_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-3FZXF5UV.cjs.map
//# sourceMappingURL=chunk-3FZXF5UV.cjs.map