diff --git a/packages/dd-trace/src/profiling/profilers/wall.js b/packages/dd-trace/src/profiling/profilers/wall.js index d6e74d44e3..3e52eff209 100644 --- a/packages/dd-trace/src/profiling/profilers/wall.js +++ b/packages/dd-trace/src/profiling/profilers/wall.js @@ -85,25 +85,23 @@ function ensureChannelsActivated () { createHook({ before: () => beforeCh.publish() }).enable() + let inRun = false shimmer.wrap(AsyncLocalStorage.prototype, 'enterWith', function (original) { return function (...args) { const retVal = original.apply(this, args) - enterCh.publish() + if (!inRun) enterCh.publish() return retVal } }) - // TODO this will change in the future. It won't be experimental forever. - const needsWrappedCb = - !process.execArgv.includes('--experimental-async-context-frame') shimmer.wrap(AsyncLocalStorage.prototype, 'run', function (original) { return function (store, callback, ...args) { - const wrappedCb = needsWrappedCb - ? shimmer.wrapFunction(callback, cb => function (...args) { - enterCh.publish() - return cb.apply(this, args) - }) - : callback + const wrappedCb = shimmer.wrapFunction(callback, cb => function (...args) { + inRun = false + enterCh.publish() + return cb.apply(this, args) + }) + inRun = true const retVal = original.call(this, store, wrappedCb, ...args) enterCh.publish() return retVal