UNPKG

@sentry/remix

Version:
45 lines (42 loc) • 1.22 kB
import { captureException } from '@sentry/browser'; import { tracingChannel } from './diagnosticsChannelShim.js'; const MECHANISM_TYPE = "auto.ui.remix_v3"; const RUN_CHANNELS = ["orchestrion:@remix-run/ui:run", "orchestrion:@remix-run/component:run"]; const attached = /* @__PURE__ */ new WeakSet(); let subscribed = false; function captureRuntimeErrors(app) { if (attached.has(app)) { return; } attached.add(app); app.addEventListener("error", (event) => { captureException(readComponentError(event), { mechanism: { handled: false, type: MECHANISM_TYPE } }); }); } function instrumentClientRuntime() { if (subscribed) { return; } subscribed = true; for (const name of RUN_CHANNELS) { tracingChannel(name).subscribe({ end(context) { const app = context.result; if (isAppRuntime(app)) { captureRuntimeErrors(app); } } }); } } function isAppRuntime(value) { return typeof value?.addEventListener === "function"; } function readComponentError(event) { const error = event.error; return error !== void 0 ? error : event; } export { captureRuntimeErrors, instrumentClientRuntime }; //# sourceMappingURL=errors.js.map