|
| 1 | +import { HttpClient, RewriteFrames } from '@sentry/integrations'; |
| 2 | +// import { Integrations as BrowserReactIntegrations } from '@sentry/react'; |
| 3 | +import type { Integration, StackFrame } from '@sentry/types'; |
| 4 | + |
| 5 | +import type { NativescriptClientOptions, NativescriptOptions } from '../options'; |
| 6 | +// import { HermesProfiling } from '../profiling/integration'; |
| 7 | +import { NativescriptTracing } from '../tracing'; |
| 8 | +// import { isExpoGo, notWeb } from '../utils/environment'; |
| 9 | +import { DeviceContext } from './devicecontext'; |
| 10 | +import { EventOrigin } from './eventorigin'; |
| 11 | +// import { ExpoContext } from './expocontext'; |
| 12 | +// import { ModulesLoader } from './modulesloader'; |
| 13 | +// import { NativeLinkedErrors } from './nativelinkederrors'; |
| 14 | +import { NativescriptErrorHandlers } from './nativescripterrorhandlers'; |
| 15 | +// import { ReactNativeInfo } from './reactnativeinfo'; |
| 16 | +import { Release } from './release'; |
| 17 | +// import { createReactNativeRewriteFrames } from './rewriteframes'; |
| 18 | +import { Screenshot } from './screenshot'; |
| 19 | +import { SdkInfo } from './sdkinfo'; |
| 20 | +// import { Spotlight } from './spotlight'; |
| 21 | +// import { ViewHierarchy } from './viewhierarchy'; |
| 22 | + |
| 23 | +export let rewriteFrameIntegration: { |
| 24 | + _iteratee: (frame: StackFrame) => StackFrame; |
| 25 | +}; |
| 26 | +/** |
| 27 | + * Returns the default ReactNative integrations based on the current environment. |
| 28 | + * |
| 29 | + * Native integrations are only returned when native is enabled. |
| 30 | + * |
| 31 | + * Web integrations are only returned when running on web. |
| 32 | + */ |
| 33 | +export function getDefaultIntegrations(options: NativescriptClientOptions & NativescriptOptions): Integration[] { |
| 34 | + const integrations: Integration[] = []; |
| 35 | + |
| 36 | + rewriteFrameIntegration = new RewriteFrames({ |
| 37 | + iteratee: (frame: StackFrame) => { |
| 38 | + if (frame.platform === 'javascript' && frame.filename) { |
| 39 | + let filename = frame.filename |
| 40 | + .replace(/^file\:\/\//, '') |
| 41 | + .replace(/^address at /, '') |
| 42 | + .replace(/^.*\/[^\.]+(\.app|CodePush|.*(?=\/))/, ''); |
| 43 | + |
| 44 | + if (frame.filename.indexOf('[native code]') === -1) { |
| 45 | + const appPrefix = options.appPrefix ?? '~/'; |
| 46 | + if (appPrefix.endsWith('//') && !appPrefix.endsWith('///')) { |
| 47 | + filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename}` : `${appPrefix}/${filename}`; |
| 48 | + } else { |
| 49 | + filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename.slice(1)}` : `${appPrefix}${filename}`; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + frame.filename = filename; |
| 54 | + if (options.colnoOffset) { |
| 55 | + frame.colno += options.colnoOffset; |
| 56 | + } |
| 57 | + // We always want to have a tripple slash |
| 58 | + } |
| 59 | + return frame; |
| 60 | + } |
| 61 | + }) as any; |
| 62 | + |
| 63 | + // if (notWeb()) { |
| 64 | + integrations.push( |
| 65 | + new NativescriptErrorHandlers(options), |
| 66 | + ); |
| 67 | + // integrations.push(new NativeLinkedErrors()); |
| 68 | + // } else { |
| 69 | + // integrations.push(new BrowserReactIntegrations.TryCatch()); |
| 70 | + // integrations.push(new BrowserReactIntegrations.GlobalHandlers()); |
| 71 | + // integrations.push(new BrowserReactIntegrations.LinkedErrors()); |
| 72 | + // } |
| 73 | + |
| 74 | + // @sentry/react default integrations |
| 75 | + // integrations.push(new BrowserReactIntegrations.InboundFilters()); |
| 76 | + // integrations.push(new BrowserReactIntegrations.FunctionToString()); |
| 77 | + // integrations.push(new BrowserReactIntegrations.Breadcrumbs()); |
| 78 | + // integrations.push(new BrowserReactIntegrations.Dedupe()); |
| 79 | + // integrations.push(new BrowserReactIntegrations.HttpContext()); |
| 80 | + // end @sentry/react-native default integrations |
| 81 | + |
| 82 | + integrations.push(new Release()); |
| 83 | + integrations.push(new EventOrigin()); |
| 84 | + integrations.push(new SdkInfo()); |
| 85 | + // integrations.push(new ReactNativeInfo()); |
| 86 | + |
| 87 | + // if (__DEV__ && notWeb()) { |
| 88 | + // integrations.push(new DebugSymbolicator()); |
| 89 | + // } |
| 90 | + |
| 91 | + integrations.push(rewriteFrameIntegration as any); |
| 92 | + |
| 93 | + if (options.enableNative) { |
| 94 | + integrations.push(new DeviceContext()); |
| 95 | + // integrations.push(new ModulesLoader()); |
| 96 | + if (options.attachScreenshot) { |
| 97 | + integrations.push(new Screenshot()); |
| 98 | + } |
| 99 | + // if (options.attachViewHierarchy) { |
| 100 | + // integrations.push(new ViewHierarchy()); |
| 101 | + // } |
| 102 | + // if (options._experiments && typeof options._experiments.profilesSampleRate === 'number') { |
| 103 | + // integrations.push(new HermesProfiling()); |
| 104 | + // } |
| 105 | + } |
| 106 | + |
| 107 | + // hasTracingEnabled from `@sentry/core` only check if tracesSampler or tracesSampleRate keys are present |
| 108 | + // that's different from prev imp here and might lead misconfiguration |
| 109 | + // `tracesSampleRate: undefined` should not enable tracing |
| 110 | + const hasTracingEnabled = |
| 111 | + options.enableTracing || |
| 112 | + typeof options.tracesSampleRate === 'number' || |
| 113 | + typeof options.tracesSampler === 'function'; |
| 114 | + if (hasTracingEnabled && options.enableAutoPerformanceTracing) { |
| 115 | + integrations.push(new NativescriptTracing()); |
| 116 | + } |
| 117 | + if (options.enableCaptureFailedRequests) { |
| 118 | + integrations.push(new HttpClient()); |
| 119 | + } |
| 120 | + |
| 121 | + // if (isExpoGo()) { |
| 122 | + // integrations.push(new ExpoContext()); |
| 123 | + // } |
| 124 | + |
| 125 | + // if (options.enableSpotlight) { |
| 126 | + // integrations.push( |
| 127 | + // Spotlight({ |
| 128 | + // sidecarUrl: options.spotlightSidecarUrl, |
| 129 | + // }), |
| 130 | + // ); |
| 131 | + // } |
| 132 | + |
| 133 | + return integrations; |
| 134 | +} |
0 commit comments