(passedOptions: ReactNativeOptions)
| 58 | * Inits the SDK and returns the final options. |
| 59 | */ |
| 60 | export 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 | } |
no test coverage detected