MCPcopy
hub / github.com/getsentry/sentry-react-native / init

Function init

packages/core/src/js/sdk.tsx:60–188  ·  view source on GitHub ↗
(passedOptions: ReactNativeOptions)

Source from the content-addressed store, hash-verified

58 * Inits the SDK and returns the final options.
59 */
60export function init(passedOptions: ReactNativeOptions): void {
61 if (isRunningInMetroDevServer()) {
62 return;
63 }
64
65 const userOptions = {
66 ...RN_GLOBAL_OBJ.__SENTRY_OPTIONS__,
67 ...passedOptions,
68 };
69
70 const maxQueueSize =
71 userOptions.maxQueueSize ?? userOptions.transportOptions?.bufferSize ?? DEFAULT_OPTIONS.maxQueueSize;
72
73 const enableNative =
74 userOptions.enableNative === undefined || userOptions.enableNative ? NATIVE.isNativeAvailable() : false;
75
76 useEncodePolyfill();
77 if (enableNative) {
78 enableSyncToNative(getGlobalScope());
79 enableSyncToNative(getIsolationScope());
80 }
81
82 const getURLFromDSN = (dsn: string | undefined): string | undefined => {
83 if (!dsn) {
84 return undefined;
85 }
86 const dsnComponents = makeDsn(dsn);
87 if (!dsnComponents) {
88 debug.error('Failed to extract url from DSN: ', dsn);
89 return undefined;
90 }
91 const port = dsnComponents.port ? `:${dsnComponents.port}` : '';
92 return `${dsnComponents.protocol}://${dsnComponents.host}${port}`;
93 };
94
95 const userBeforeBreadcrumb = safeFactory(userOptions.beforeBreadcrumb, {
96 loggerMessage: 'The beforeBreadcrumb threw an error',
97 });
98
99 // Exclude Dev Server and Sentry Dsn request from Breadcrumbs
100 const devServerUrl = getDevServer()?.url;
101 const dsn = getURLFromDSN(userOptions.dsn);
102 const defaultBeforeBreadcrumb = (breadcrumb: Breadcrumb, _hint?: BreadcrumbHint): Breadcrumb | null => {
103 const type = breadcrumb.type || '';
104 const url = typeof breadcrumb.data?.url === 'string' ? breadcrumb.data.url : '';
105 if (type === 'http' && ((devServerUrl && url.startsWith(devServerUrl)) || (dsn && url.startsWith(dsn)))) {
106 return null;
107 }
108 return breadcrumb;
109 };
110
111 const chainedBeforeBreadcrumb = (breadcrumb: Breadcrumb, hint?: BreadcrumbHint): Breadcrumb | null => {
112 let modifiedBreadcrumb = breadcrumb;
113 if (userBeforeBreadcrumb) {
114 const result = userBeforeBreadcrumb(breadcrumb, hint);
115 if (result === null) {
116 return null;
117 }

Callers 1

sdk.test.tsFile · 0.90

Calls 15

useEncodePolyfillFunction · 0.90
enableSyncToNativeFunction · 0.90
safeFactoryFunction · 0.90
getDevServerFunction · 0.90
getDefaultReleaseFunction · 0.90
shouldEnableNativeNaggerFunction · 0.90
safeTracesSamplerFunction · 0.90
getDefaultEnvironmentFunction · 0.90
getDefaultIntegrationsFunction · 0.90

Tested by

no test coverage detected