dd-trace
Version:
Datadog APM tracing client for JavaScript
30 lines (22 loc) • 1.03 kB
JavaScript
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
}
})
}