2626#import < Sentry/SentryException.h>
2727#import < Sentry/SentryFormatter.h>
2828#import < Sentry/SentryGeo.h>
29- #import < Sentry/SentryOptions.h>
30- #import < Sentry/SentryOptionsInternal.h>
3129#import < Sentry/SentryScreenFrames.h>
3230#import < Sentry/SentryUser.h>
3331
@@ -89,20 +87,57 @@ - (instancetype)init
8987RCT_EXPORT_METHOD(initNativeSdk : (NSDictionary *_Nonnull)options resolve : (
9088 RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject)
9189{
90+
91+ SentryBeforeSendEventCallback beforeSend = ^SentryEvent *(SentryEvent *event) {
92+ // We don't want to send an event after startup that came from a Unhandled JS Exception of
93+ // React Native because we sent it already before the app crashed.
94+ if (nil != event.exceptions .firstObject .type &&
95+ [event.exceptions.firstObject.type rangeOfString: @" Unhandled JS Exception" ].location
96+ != NSNotFound ) {
97+ return nil ;
98+ }
99+
100+ // Regex and Str are set when one of them has value so we only need to check one of them.
101+ if (self->_ignoreErrorPatternsStr || self->_ignoreErrorPatternsRegex ) {
102+ for (SentryException *exception in event.exceptions ) {
103+ if ([self shouldIgnoreError: exception.value]) {
104+ return nil ;
105+ }
106+ }
107+ if ([self shouldIgnoreError: event.message.message]) {
108+ return nil ;
109+ }
110+ }
111+
112+ [self setEventOriginTag: event];
113+ return event;
114+ };
115+
116+ NSMutableDictionary *mutableOptions = [options mutableCopy ];
117+ [mutableOptions setValue: beforeSend forKey: @" beforeSend" ];
118+
119+ // remove performance traces sample rate and traces sampler since we don't want to synchronize
120+ // these configurations to the Native SDKs. The user could tho initialize the SDK manually and
121+ // set themselves.
122+ [mutableOptions removeObjectForKey: @" tracesSampleRate" ];
123+ [mutableOptions removeObjectForKey: @" tracesSampler" ];
124+ [mutableOptions removeObjectForKey: @" enableTracing" ];
125+
126+ #if SENTRY_TARGET_REPLAY_SUPPORTED
127+ BOOL isSessionReplayEnabled = [RNSentryReplay updateOptions: mutableOptions];
128+ #else
129+ // Defaulting to false for unsupported targets
130+ BOOL isSessionReplayEnabled = NO ;
131+ #endif
132+ NSString *dsn = [self getURLFromDSN: [mutableOptions valueForKey: @" dsn" ]];
133+ [self trySetIgnoreErrors: mutableOptions];
92134 NSError *error = nil ;
93- SentryOptions *sentryOptions = [ self createOptionsWithDictionary: options error: &error];
135+ [SentrySDKWrapper setupWithDictionary: mutableOptions isSessionReplayEnabled: isSessionReplayEnabled dsn: dsn error: &error];
94136 if (error != nil ) {
95137 reject (@" SentryReactNative" , error.localizedDescription , error);
96138 return ;
97139 }
98140
99- NSString *sdkVersion = [PrivateSentrySDKOnly getSdkVersionString ];
100- [PrivateSentrySDKOnly setSdkName: NATIVE_SDK_NAME andVersionString: sdkVersion];
101- [PrivateSentrySDKOnly addSdkPackage: REACT_NATIVE_SDK_PACKAGE_NAME
102- version: REACT_NATIVE_SDK_PACKAGE_VERSION];
103-
104- [SentrySDKWrapper startWithOptions: sentryOptions];
105-
106141#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST
107142 BOOL appIsActive =
108143 [[UIApplication sharedApplication ] applicationState ] == UIApplicationStateActive;
@@ -113,8 +148,8 @@ - (instancetype)init
113148 // If the app is active/in foreground, and we have not sent the SentryHybridSdkDidBecomeActive
114149 // notification, send it.
115150 if (appIsActive && !sentHybridSdkDidBecomeActive
116- && (PrivateSentrySDKOnly. options . enableAutoSessionTracking
117- || PrivateSentrySDKOnly. options . enableWatchdogTerminationTracking )) {
151+ && ([SentrySDKWrapper enableAutoSessionTracking ]
152+ || [SentrySDKWrapper enableWatchdogTerminationTracking ] )) {
118153 [[NSNotificationCenter defaultCenter ] postNotificationName: @" SentryHybridSdkDidBecomeActive"
119154 object: nil ];
120155
@@ -128,7 +163,7 @@ - (instancetype)init
128163 resolve (@YES );
129164}
130165
131- - (void )trySetIgnoreErrors : (NSMutableDictionary *)options
166+ - (void )trySetIgnoreErrors : (NSDictionary *)options
132167{
133168 NSArray *ignoreErrorsStr = nil ;
134169 NSArray *ignoreErrorsRegex = nil ;
@@ -194,135 +229,6 @@ - (BOOL)shouldIgnoreError:(NSString *)message
194229 return NO ;
195230}
196231
197- - (SentryOptions *_Nullable)createOptionsWithDictionary : (NSDictionary *_Nonnull)options
198- error : (NSError *_Nonnull *_Nonnull)errorPointer
199- {
200- SentryBeforeSendEventCallback beforeSend = ^SentryEvent *(SentryEvent *event) {
201- // We don't want to send an event after startup that came from a Unhandled JS Exception of
202- // React Native because we sent it already before the app crashed.
203- if (nil != event.exceptions .firstObject .type &&
204- [event.exceptions.firstObject.type rangeOfString: @" Unhandled JS Exception" ].location
205- != NSNotFound ) {
206- return nil ;
207- }
208-
209- // Regex and Str are set when one of them has value so we only need to check one of them.
210- if (self->_ignoreErrorPatternsStr || self->_ignoreErrorPatternsRegex ) {
211- for (SentryException *exception in event.exceptions ) {
212- if ([self shouldIgnoreError: exception.value]) {
213- return nil ;
214- }
215- }
216- if ([self shouldIgnoreError: event.message.message]) {
217- return nil ;
218- }
219- }
220-
221- [self setEventOriginTag: event];
222- return event;
223- };
224-
225- NSMutableDictionary *mutableOptions = [options mutableCopy ];
226- [mutableOptions setValue: beforeSend forKey: @" beforeSend" ];
227-
228- // remove performance traces sample rate and traces sampler since we don't want to synchronize
229- // these configurations to the Native SDKs. The user could tho initialize the SDK manually and
230- // set themselves.
231- [mutableOptions removeObjectForKey: @" tracesSampleRate" ];
232- [mutableOptions removeObjectForKey: @" tracesSampler" ];
233- [mutableOptions removeObjectForKey: @" enableTracing" ];
234-
235- #if SENTRY_TARGET_REPLAY_SUPPORTED
236- BOOL isSessionReplayEnabled = [RNSentryReplay updateOptions: mutableOptions];
237- #else
238- // Defaulting to false for unsupported targets
239- BOOL isSessionReplayEnabled = NO ;
240- #endif
241-
242- SentryOptions *sentryOptions = [SentryOptionsInternal initWithDict: mutableOptions
243- didFailWithError: errorPointer];
244- if (*errorPointer != nil ) {
245- return nil ;
246- }
247-
248- // Exclude Dev Server and Sentry Dsn request from Breadcrumbs
249- NSString *dsn = [self getURLFromDSN: [mutableOptions valueForKey: @" dsn" ]];
250- NSString *devServerUrl = [mutableOptions valueForKey: @" devServerUrl" ];
251- sentryOptions.beforeBreadcrumb
252- = ^SentryBreadcrumb *_Nullable (SentryBreadcrumb *_Nonnull breadcrumb)
253- {
254- NSString *url = breadcrumb.data [@" url" ] ?: @" " ;
255-
256- if ([@" http" isEqualToString: breadcrumb.type]
257- && ((dsn != nil && [url hasPrefix: dsn])
258- || (devServerUrl != nil && [url hasPrefix: devServerUrl]))) {
259- return nil ;
260- }
261- return breadcrumb;
262- };
263-
264- if ([mutableOptions valueForKey: @" enableNativeCrashHandling" ] != nil ) {
265- BOOL enableNativeCrashHandling = [mutableOptions[@" enableNativeCrashHandling" ] boolValue ];
266-
267- if (!enableNativeCrashHandling) {
268- sentryOptions.enableCrashHandler = NO ;
269- }
270- }
271-
272- // Set spotlight option
273- if ([mutableOptions valueForKey: @" spotlight" ] != nil ) {
274- id spotlightValue = [mutableOptions valueForKey: @" spotlight" ];
275- if ([spotlightValue isKindOfClass: [NSString class ]]) {
276- NSLog (@" Using Spotlight on address: %@ " , spotlightValue);
277- sentryOptions.enableSpotlight = true ;
278- sentryOptions.spotlightUrl = spotlightValue;
279- } else if ([spotlightValue isKindOfClass: [NSNumber class ]]) {
280- sentryOptions.enableSpotlight = [spotlightValue boolValue ];
281- id defaultSpotlightUrl = [mutableOptions valueForKey: @" defaultSidecarUrl" ];
282- if (defaultSpotlightUrl != nil ) {
283- sentryOptions.spotlightUrl = defaultSpotlightUrl;
284- }
285- }
286- }
287-
288- if ([mutableOptions valueForKey: @" enableLogs" ] != nil ) {
289- id enableLogsValue = [mutableOptions valueForKey: @" enableLogs" ];
290- if ([enableLogsValue isKindOfClass: [NSNumber class ]]) {
291- [RNSentryExperimentalOptions setEnableLogs: [enableLogsValue boolValue ]
292- sentryOptions: sentryOptions];
293- }
294- }
295- [self trySetIgnoreErrors: mutableOptions];
296-
297- // Enable the App start and Frames tracking measurements
298- if ([mutableOptions valueForKey: @" enableAutoPerformanceTracing" ] != nil ) {
299- BOOL enableAutoPerformanceTracing =
300- [mutableOptions[@" enableAutoPerformanceTracing" ] boolValue ];
301- PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = enableAutoPerformanceTracing;
302- #if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST
303- PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = enableAutoPerformanceTracing;
304- #endif
305- }
306-
307- // Failed requests can only be enabled in one SDK to avoid duplicates
308- sentryOptions.enableCaptureFailedRequests = NO ;
309-
310- NSDictionary *experiments = options[@" _experiments" ];
311- if (experiments != nil && [experiments isKindOfClass: [NSDictionary class ]]) {
312- BOOL enableUnhandledCPPExceptions =
313- [experiments[@" enableUnhandledCPPExceptionsV2" ] boolValue ];
314- [RNSentryExperimentalOptions setEnableUnhandledCPPExceptionsV2: enableUnhandledCPPExceptions
315- sentryOptions: sentryOptions];
316- }
317-
318- if (isSessionReplayEnabled) {
319- [RNSentryExperimentalOptions setEnableSessionReplayInUnreliableEnvironment: YES
320- sentryOptions: sentryOptions];
321- }
322-
323- return sentryOptions;
324- }
325-
326232- (NSString *_Nullable)getURLFromDSN : (NSString *)dsn
327233{
328234 NSURL *url = [NSURL URLWithString: dsn];
@@ -460,7 +366,7 @@ - (void)stopObserving
460366 contexts[@" os" ] = os;
461367 }
462368
463- NSString *releaseName = SentrySDKInternal. options . releaseName ;
369+ NSString *releaseName = [SentrySDKWrapper releaseName ] ;
464370 if (releaseName) {
465371 contexts[@" release" ] = releaseName;
466372 }
@@ -492,7 +398,7 @@ - (void)stopObserving
492398RCT_EXPORT_METHOD (fetchNativeDeviceContexts : (RCTPromiseResolveBlock)resolve rejecter : (
493399 RCTPromiseRejectBlock)reject)
494400{
495- if (PrivateSentrySDKOnly. options . debug ) {
401+ if ([SentrySDKWrapper debug ] ) {
496402 NSLog (@" Bridge call to: deviceContexts" );
497403 }
498404 __block NSMutableDictionary <NSString *, id > *serializedScope;
@@ -507,7 +413,7 @@ - (void)stopObserving
507413 forKey: @" user" ];
508414 }
509415
510- if (PrivateSentrySDKOnly. options . debug ) {
416+ if ([SentrySDKWrapper debug ] ) {
511417 NSData *data = [NSJSONSerialization dataWithJSONObject: serializedScope
512418 options: 0
513419 error: nil ];
0 commit comments