UNPKG

@sentry/lynx-react

Version:
111 lines (108 loc) 4 kB
import { logger, supportsFetch, getIntegrationsToSetup, stackParserFromStackParserOptions, initAndBind, GLOBAL_OBJ, inboundFiltersIntegration, functionToStringIntegration, dedupeIntegration } from '@sentry/core'; import { LynxClient } from './client.mjs'; import { defaultStackParser, makeFetchTransport, breadcrumbsIntegration, linkedErrorsIntegration, httpContextIntegration, browserApiErrorsIntegration, globalHandlersIntegration, browserSessionIntegration } from '@sentry/browser'; import { dropTopLevelUndefinedKeys } from './utils/dropTopLevelUndefinedKeys.mjs'; import { isLynxBackgroundThread, isBrowserMainThread, notMobile } from './environment.mjs'; import { getFetch } from './utils/fetch.mjs'; import { developmentSymbolicatorIntegration } from './integrations/developmentSymbolicator.mjs'; import { lynxGlobalHandlersIntegration } from './integrations/globalHandlers.mjs'; /** Get the default integrations for the Lynx SDK. */ function getDefaultIntegrations(_options) { const integrations = [ // TODO(v10): Replace with `eventFiltersIntegration` once we remove the deprecated `inboundFiltersIntegration` // eslint-disable-next-line deprecation/deprecation inboundFiltersIntegration(), functionToStringIntegration(), breadcrumbsIntegration({ history: false, dom: false, }), linkedErrorsIntegration(), dedupeIntegration(), httpContextIntegration(), developmentSymbolicatorIntegration(), lynxGlobalHandlersIntegration(), ]; if (isBrowserMainThread()) { integrations.push(browserApiErrorsIntegration(), globalHandlersIntegration(), browserSessionIntegration()); } return integrations; } /** Exported only for tests. */ function applyDefaultOptions(optionsArg = {}) { var _a; const defaultOptions = { defaultIntegrations: getDefaultIntegrations(), release: (_a = GLOBAL_OBJ.SENTRY_RELEASE) === null || _a === void 0 ? void 0 : _a.id, sendClientReports: true, }; return { ...defaultOptions, ...dropTopLevelUndefinedKeys(optionsArg), }; } /** * The Sentry Lynx SDK Client. * * To use this SDK, call the {@link init} function as early as possible when * loading the application. To set context information or send manual events, use * the provided methods. * * @example * * ``` * * import { init } from '@sentry/lynx-react'; * * init({ * dsn: '__DSN__', * // ... * }); * ``` * * @example * ``` * * import { addBreadcrumb } from '@sentry/lynx-react'; * addBreadcrumb({ * message: 'My Breadcrumb', * // ... * }); * ``` * * @example * * ``` * * import * as Sentry from '@sentry/lynx-react'; * Sentry.captureMessage('Hello, world!'); * Sentry.captureException(new Error('Good bye')); * Sentry.captureEvent({ * message: 'Manual', * stacktrace: [ * // ... * ], * }); * ``` * * @see {@link LynxOptions} for documentation on configuration options. */ function init(lynxOptions = {}) { if (!isLynxBackgroundThread() && !isBrowserMainThread()) { logger.info('Sentry initialization skipped: Sentry is only enabled on the mobile background thread or browser main thread.'); return; } const options = applyDefaultOptions(lynxOptions); if (!supportsFetch() && notMobile()) { logger.warn('No Fetch API detected. The Sentry SDK requires a Fetch API compatible environment to send events. Please add a Fetch API polyfill.'); } const clientOptions = { ...options, stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser), integrations: getIntegrationsToSetup(options), transport: options.transport || ((transportOptions) => makeFetchTransport(transportOptions, getFetch())), }; return initAndBind(LynxClient, clientOptions); } export { applyDefaultOptions, getDefaultIntegrations, init }; //# sourceMappingURL=sdk.mjs.map