UNPKG

@sentry/core

Version:
50 lines (49 loc) • 1.52 kB
import { filenameIsInApp } from "./node-stack-trace.js"; import "./stacktrace.js"; // src/utils/anr.ts /** * A node.js watchdog timer * @param pollInterval The interval that we expect to get polled at * @param anrThreshold The threshold for when we consider ANR * @param callback The callback to call for ANR * @returns An object with `poll` and `enabled` functions {@link WatchdogReturn} */ function watchdogTimer(createTimer, pollInterval, anrThreshold, callback) { const timer = createTimer(); let triggered = false; let enabled = true; setInterval(() => { const diffMs = timer.getTimeMs(); if (triggered === false && diffMs > pollInterval + anrThreshold) { triggered = true; if (enabled) callback(); } if (diffMs < pollInterval + anrThreshold) triggered = false; }, 20); return { poll: () => { timer.reset(); }, enabled: (state) => { enabled = state; } }; } /** * Converts Debugger.CallFrame to Sentry StackFrame */ function callFrameToStackFrame(frame, url, getModuleFromFilename) { const filename = url ? url.replace(/^file:\/\//, "") : void 0; const colno = frame.location.columnNumber ? frame.location.columnNumber + 1 : void 0; const lineno = frame.location.lineNumber ? frame.location.lineNumber + 1 : void 0; return { filename, module: getModuleFromFilename(filename), function: frame.functionName || "?", colno, lineno, in_app: filename ? filenameIsInApp(filename) : void 0 }; } export { callFrameToStackFrame, watchdogTimer }; //# sourceMappingURL=anr.js.map