Skip to content

Commit

Permalink
fix: Bugfix/multiple install calls (#315)
Browse files Browse the repository at this point in the history
* docs: Change wording in docs

* fix: Remove dispatch once token
  • Loading branch information
HazAT authored Dec 20, 2017
1 parent 26f5f7e commit 665ea6d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 44 deletions.
24 changes: 8 additions & 16 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
React Native
============

This is the documentation for our beta clients for React-Native. The
React-Native client uses a native extension for iOS and Android but can
fall back to a pure JavaScript version if needed.
This is the documentation for our React-Native SDK. The
React-Native SDK uses a native extension for iOS and Android but will
fall back to a pure JavaScript version if necessary.

Installation
------------
Expand All @@ -25,25 +25,17 @@ The `link` step will pull in the native dependency and patch your project
accordingly. If you are using expo you don't have to (or can't) run that
link step. For more information about that see :doc:`expo`.

On linking you will automatically be prompted for your DSN and other
information and we will configure your app automatically for react-native
and change files accordingly. You will need to provide the following
data: your DSN, the slug of your organization in Sentry, the slug of your
project in Sentry as well as the Auth token. We need the Auth token for
uploading the sourcemaps.

You can find the slugs in the URL of your project
(``sentry.io/your-org-slug/your-project-slug``) If you don't have an auth
token yet you can `create an auth token here <https://sentry.io/api/>`_.
On linking the new `Sentry Wizard <https://github.com/getsentry/sentry-wizard>`_
will help you to configure your project and change files accordingly.

Upon linking the following changes will be performed:

* add the raven-java package for native crash reporting on Android
* add the sentry-java package for native crash reporting on Android
* add the sentry-swift package for native crash reporting on iOS
* enable the sentry gradle build step for android
* patch `AppDelegate.m` for iOS
* patch `MainApplication.java` for Android
* configure Sentry for the supplied DSN in your `index.js` files
* configure Sentry for the supplied DSN in your `index.js/App.js` files
* store build credentials in `ios/sentry.properties` and
`android/sentry.properties`.

Expand All @@ -65,7 +57,7 @@ latest version::
iOS Specifics
-------------

When you use xcode you can hook directly into the build process to upload
When you use Xcode you can hook directly into the build process to upload
debug symbols and sourcemaps. If you however are using bitcode you will
need to disable the "Upload Debug Symbols to Sentry" build phase and then
separately upload debug symbols from iTunes Connect to Sentry.
Expand Down
53 changes: 25 additions & 28 deletions ios/RNSentry.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,32 @@ - (void)setReleaseVersionDist:(SentryEvent *)event {

RCT_EXPORT_METHOD(startWithDsnString:(NSString * _Nonnull)dsnString options:(NSDictionary *_Nonnull)options)
{
static dispatch_once_t onceStartToken;
dispatch_once(&onceStartToken, ^{
NSError *error = nil;
self.moduleMapping = [[NSMutableDictionary alloc] init];
SentryClient *client = [[SentryClient alloc] initWithDsn:dsnString didFailWithError:&error];
client.beforeSerializeEvent = ^(SentryEvent * _Nonnull event) {
[self injectReactNativeFrames:event];
[self setReleaseVersionDist:event];
};
client.shouldSendEvent = ^BOOL(SentryEvent * _Nonnull event) {
// We don't want to send an event after startup that came from a NSException of react native
// Because we sent it already before the app crashed.
if (nil != event.exceptions.firstObject.type &&
[event.exceptions.firstObject.type rangeOfString:@"RCTFatalException"].location != NSNotFound) {
NSLog(@"RCTFatalException");
return NO;
}
// Since we set shouldSendEvent for react-native we need to duplicate the code for sampling here
if (nil != options[@"sampleRate"]) {
return ([options[@"sampleRate"] floatValue] >= ((double)arc4random() / 0x100000000));
}
return YES;
};
[SentryClient setSharedClient:client];
[SentryClient.sharedClient startCrashHandlerWithError:&error];
if (error) {
[NSException raise:@"SentryReactNative" format:@"%@", error.localizedDescription];
NSError *error = nil;
self.moduleMapping = [[NSMutableDictionary alloc] init];
SentryClient *client = [[SentryClient alloc] initWithDsn:dsnString didFailWithError:&error];
client.beforeSerializeEvent = ^(SentryEvent * _Nonnull event) {
[self injectReactNativeFrames:event];
[self setReleaseVersionDist:event];
};
client.shouldSendEvent = ^BOOL(SentryEvent * _Nonnull event) {
// We don't want to send an event after startup that came from a NSException of react native
// Because we sent it already before the app crashed.
if (nil != event.exceptions.firstObject.type &&
[event.exceptions.firstObject.type rangeOfString:@"RCTFatalException"].location != NSNotFound) {
NSLog(@"RCTFatalException");
return NO;
}
});
// Since we set shouldSendEvent for react-native we need to duplicate the code for sampling here
if (nil != options[@"sampleRate"]) {
return ([options[@"sampleRate"] floatValue] >= ((double)arc4random() / 0x100000000));
}
return YES;
};
[SentryClient setSharedClient:client];
[SentryClient.sharedClient startCrashHandlerWithError:&error];
if (error) {
[NSException raise:@"SentryReactNative" format:@"%@", error.localizedDescription];
}
}

RCT_EXPORT_METHOD(activateStacktraceMerging:(RCTPromiseResolveBlock)resolve
Expand Down

0 comments on commit 665ea6d

Please sign in to comment.