Allow native SDK options to be specified by user without needing to re-initialize native SDK. - TypeScript sentry-react-native

OS: - [ ] Windows - [x] MacOS - [ ] Linux

Platform: - [x] iOS - [ ] Android

SDK: - [x] @sentry/react-native (>= 1.0.0) - [ ] react-native-sentry (<= 0.43.2)

SDK version: 2.1.0

react-native version: 0.63.4

Are you using Expo? - [ ] Yes - [x] No

Are you using sentry.io or on-premise? - [x] sentry.io (SaaS) - [ ] on-premise

If you are using sentry.io, please post a link to your issue so we can take a look:

https://sentry.io/organizations/stroller-ab/issues/2118758655/?environment=development&project=246038&query=is%3Aunresolved&statsPeriod=14d

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: 'https://...@sentry.io/...',
  debug: false,
  enableAutoSessionTracking: true,
  integrations(integrations) {
    return integrations.filter(integration => integration.name !== 'Breadcrumbs')
  },
});

I have following issue:

I can see default breadcrumbs for native errors even after disabling Breadcrumbs integration during initing SDK

Steps to reproduce: - Init SDK with disabling Breadcrumbs - Raise Native error - Check tracked breadcrumbs

Actual result:

You can see default native breadcrumbs

Screenshot 2021-01-03 at 10 38 11 PM

Expected result:

You should see only exception in breadcrumbs

Screenshot 2021-01-03 at 10 39 34 PM

Asked Oct 10 '21 04:10
avatar serhiipalash
serhiipalash

6 Answer:

The issue is presented only on Native errors, on JS errors everything works as expected

https://sentry.io/organizations/stroller-ab/issues/2118676054/?environment=development&project=246038&query=is%3Aunresolved

1
Answered Jan 03 '21 at 21:34
avatar  of serhiipalash
serhiipalash

Should I do this manually in Native code?

import Sentry

SentrySDK.start(options: [
    //...
    "integrations": Sentry.Options.defaultIntegrations().filter { (name) -> Bool in
        return name != "SentryAutoBreadcrumbTrackingIntegration" // This will disable  SentryAutoBreadcrumbTrackingIntegration
    }
    //...
])

https://docs.sentry.io/platforms/apple/usage/#integrations

1
Answered Jan 04 '21 at 10:52
avatar  of serhiipalash
serhiipalash

Should I do this manually in Native code?

import Sentry

SentrySDK.start(options: [
    //...
    "integrations": Sentry.Options.defaultIntegrations().filter { (name) -> Bool in
        return name != "SentryAutoBreadcrumbTrackingIntegration" // This will disable  SentryAutoBreadcrumbTrackingIntegration
    }
    //...
])

https://docs.sentry.io/platforms/apple/usage/#integrations

No you shouldn't do this as it will initialize the SDK twice and cause both to not be synced. Currently you're not able to disable just Native breadcrumbs, but there is a way to do it with patch-package.

  1. Follow the setup instructions for patch-package here: https://github.com/ds300/patch-package

  2. Add these lines below to node_modules/@sentry/react-native/ios/RNSentry.m inside startWithOptions.

         reject(@"SentryReactNative", error.localizedDescription, error);
         return;
     }
+
+    NSMutableArray *integrations = [SentryOptions defaultIntegrations].mutableCopy;
+    [integrations removeObject:@"SentryAutoBreadcrumbTrackingIntegration"];
+    sentryOptions.integrations = integrations;
+
     [SentrySDK startWithOptionsObject:sentryOptions];

     resolve(@YES);
  1. Run yarn patch-package @sentry/react-native

Now every time you run yarn install it should patch the @sentry/react-native package to disable this integration.

1
Answered Jan 04 '21 at 13:50
avatar  of jennmueng
jennmueng

Actually, now that we just merged https://github.com/getsentry/sentry-react-native/pull/1259, when we release that you can just re-initialize the SDK in Swift/Objective-C and that won't break the SDK. However, for now you can use that patch-package workaround. Let's close this.

1
Answered Jan 04 '21 at 15:50
avatar  of jennmueng
jennmueng

Now every time you run yarn install it should patch the @sentry/react-native package to disable this integration.

Thanks! It works. It took me some time to test it in all environments.

Now all native breadcrumbs are disabled. Still, I have one issue with breadcrumbs.

JS-exceptions attach breadcrumbs from previous session (Android only)

Screenshot 2021-01-04 at 9 12 17 PM

https://sentry.io/organizations/stroller-ab/issues/2129847019/?environment=staging&project=246038&query=is%3Aunresolved&statsPeriod=14d

Native exceptions don't as expected

https://sentry.io/organizations/stroller-ab/issues/2120472646/?environment=development&environment=staging&project=246038&query=is%3Aunresolved&statsPeriod=14d

Screenshot 2021-01-04 at 9 21 40 PM

@jennmueng can you help with it? It's a minor issue and I can create a separate bug report for it, if you want to.

1
Answered Jan 04 '21 at 19:22
avatar  of serhiipalash
serhiipalash

JS-exceptions attach breadcrumbs from previous session

It seems like it only happens on Android

1
Answered Jan 04 '21 at 19:47
avatar  of serhiipalash
serhiipalash