@@ -181,27 +181,30 @@ - (void)setReleaseVersionDist:(SentryEvent *)event {
181181
182182RCT_EXPORT_METHOD (startWithDsnString:(NSString * _Nonnull)dsnString)
183183{
184- NSError *error = nil ;
185- SentryClient *client = [[SentryClient alloc ] initWithDsn: dsnString didFailWithError: &error];
186- [SentryClient setSharedClient: client];
187- [SentryClient.sharedClient startCrashHandlerWithError: &error];
188- if (error) {
189- [NSException raise: @" SentryReactNative" format: @" %@ " , error.localizedDescription];
190- }
191- SentryClient.sharedClient .shouldSendEvent = ^BOOL (SentryEvent * _Nonnull event) {
192- // We don't want to send an event after startup that came from a NSException of react native
193- // Because we sent it already before the app crashed.
194- if (nil != event.exceptions .firstObject .type &&
195- [event.exceptions.firstObject.type rangeOfString: @" RCTFatalException" ].location != NSNotFound ) {
196- NSLog (@" RCTFatalException" );
197- return NO ;
184+ static dispatch_once_t onceStartToken;
185+ dispatch_once (&onceStartToken, ^{
186+ NSError *error = nil ;
187+ SentryClient *client = [[SentryClient alloc ] initWithDsn: dsnString didFailWithError: &error];
188+ [SentryClient setSharedClient: client];
189+ [SentryClient.sharedClient startCrashHandlerWithError: &error];
190+ if (error) {
191+ [NSException raise: @" SentryReactNative" format: @" %@ " , error.localizedDescription];
198192 }
199- return YES ;
200- };
201- SentryClient.sharedClient .beforeSerializeEvent = ^(SentryEvent * _Nonnull event) {
202- [self injectReactNativeFrames: event];
203- [self setReleaseVersionDist: event];
204- };
193+ SentryClient.sharedClient .shouldSendEvent = ^BOOL (SentryEvent * _Nonnull event) {
194+ // We don't want to send an event after startup that came from a NSException of react native
195+ // Because we sent it already before the app crashed.
196+ if (nil != event.exceptions .firstObject .type &&
197+ [event.exceptions.firstObject.type rangeOfString: @" RCTFatalException" ].location != NSNotFound ) {
198+ NSLog (@" RCTFatalException" );
199+ return NO ;
200+ }
201+ return YES ;
202+ };
203+ SentryClient.sharedClient .beforeSerializeEvent = ^(SentryEvent * _Nonnull event) {
204+ [self injectReactNativeFrames: event];
205+ [self setReleaseVersionDist: event];
206+ };
207+ });
205208}
206209
207210RCT_EXPORT_METHOD (activateStacktraceMerging:(RCTPromiseResolveBlock)resolve
0 commit comments