dd-trace
Version:
Datadog APM tracing client for JavaScript
33 lines (24 loc) • 1.12 kB
JavaScript
const { syncBuiltinESMExports } = require('node:module')
const { channel } = require('dc-polyfill')
const shimmer = require('../../datadog-shimmer')
const startSetUncaughtExceptionCaptureCallback = channel('datadog:process:setUncaughtExceptionCaptureCallback:start')
if (process.setUncaughtExceptionCaptureCallback) {
let currentCallback
shimmer.wrap(process, 'setUncaughtExceptionCaptureCallback',
function wrapSetUncaughtExceptionCaptureCallback (originalSetUncaughtExceptionCaptureCallback) {
return function setUncaughtExceptionCaptureCallback (newCallback) {
if (startSetUncaughtExceptionCaptureCallback.hasSubscribers) {
const abortController = new AbortController()
startSetUncaughtExceptionCaptureCallback.publish({ newCallback, currentCallback, abortController })
if (abortController.signal.aborted) {
return
}
}
const result = originalSetUncaughtExceptionCaptureCallback.apply(this, arguments)
currentCallback = newCallback
return result
}
})
syncBuiltinESMExports()
}