UNPKG

@sentry/lynx-react

Version:
97 lines (94 loc) 3.68 kB
import { logger } from '@sentry/core'; import { getFetch } from '../utils/fetch.mjs'; import { getLynx } from '../environment.mjs'; const NAME = 'DevelopmentSymbolicator'; const PREFIX = `[${NAME}]`; const SYMBOLICATOR_ENDPOINT = '/__sentry__/symbolicate'; function developmentSymbolicatorIntegration() { return { name: NAME, processEvent: async (event) => { var _a, _b, _c, _d, _e, _f; if (event.type !== undefined) { // Not an error event return event; } for (const exception of (_b = (_a = event.exception) === null || _a === void 0 ? void 0 : _a.values) !== null && _b !== void 0 ? _b : []) { const newFrames = await symbolicateFrames((_c = exception.stacktrace) === null || _c === void 0 ? void 0 : _c.frames); if (exception.stacktrace) { exception.stacktrace.frames = newFrames; } } for (const thread of (_e = (_d = event.threads) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : []) { const newFrames = await symbolicateFrames((_f = thread.stacktrace) === null || _f === void 0 ? void 0 : _f.frames); if (thread.stacktrace) { thread.stacktrace.frames = newFrames; } } return event; }, }; } async function symbolicateFrames(frames) { if (!frames) { return undefined; } if (frames.length === 0) { return frames; } try { const fetch = getFetch(); if (!fetch) { logger.warn('No fetch implementation found'); return frames; } const developmentServerUrl = getDevelopmentServerUrl(); if (!developmentServerUrl) { logger.warn('No development server url found'); return frames; } logger.debug(`${PREFIX} Symbolicating ${frames.length} frames using ${developmentServerUrl}.`); const response = await fetch(`${developmentServerUrl}${SYMBOLICATOR_ENDPOINT}`, { method: 'POST', body: JSON.stringify({ frames }), }); const data = await response.json(); if (!response.ok) { logger.error(`${PREFIX} Error symbolicating frames`, data); return frames; } return data.frames; } catch (error) { logger.error('Error symbolicating frames', error); return frames; } } /** * Returns the development server base url, e.g. http://192.168.0.94:3000 * * Only works in development and on mobile platforms */ function getDevelopmentServerUrl() { var _a, _b, _c; const lynx = getLynx(); if (!lynx) { return undefined; } const sourceName = (_c = (_b = (_a = lynx.getApp) === null || _a === void 0 ? void 0 : _a.call(lynx)) === null || _b === void 0 ? void 0 : _b._params) === null || _c === void 0 ? void 0 : _c.srcName; if (typeof sourceName !== 'string') { return undefined; } return parseUrlFromSourceName(sourceName); } /** * Converts http://192.168.0.94:3000/main.lynx.bundle?fullscreen=true to http://192.168.0.94:3000 */ function parseUrlFromSourceName(sourceName) { // Match protocol, hostname, and port, stopping before any path or query params // Can't use URL because it's noop in Lynx const match = sourceName.match(/^(.*?:\/\/[^/]+)/); return match ? match[1] : sourceName; } export { developmentSymbolicatorIntegration, getDevelopmentServerUrl, parseUrlFromSourceName }; //# sourceMappingURL=developmentSymbolicator.mjs.map