Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow native SDK options to be specified by user without needing to re-initialize native SDK. #1263

Closed
5 of 11 tasks
serhiipalash opened this issue Jan 3, 2021 · 13 comments
Closed
5 of 11 tasks

Comments

@serhiipalash
Copy link

serhiipalash commented Jan 3, 2021

OS:

  • Windows
  • MacOS
  • Linux

Platform:

  • iOS
  • Android

SDK:

  • @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
  • No

Are you using sentry.io or on-premise?

  • 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://[email protected]/...',
  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

@serhiipalash
Copy link
Author

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

@serhiipalash
Copy link
Author

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

@jennmueng
Copy link
Member

jennmueng commented Jan 4, 2021

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.

@jennmueng jennmueng changed the title Not possible to disable native breadcrumbs Allow native SDK options to be specified by user without needing to re-initialize native SDK. Jan 4, 2021
@jennmueng
Copy link
Member

jennmueng commented Jan 4, 2021

Actually, now that we just merged #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.

@serhiipalash
Copy link
Author

serhiipalash commented Jan 4, 2021

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.

@serhiipalash
Copy link
Author

JS-exceptions attach breadcrumbs from previous session

It seems like it only happens on Android

@serhiipalash
Copy link
Author

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

@jennmueng is there a way to do the same in Android native code?

@jennmueng
Copy link
Member

Yes you can do something similar in node_modules/@sentry/react-native/android/src/main/java/io/sentry/RNSentryModule.java.

@serhiipalash
Copy link
Author

Final patch

diff --git a/node_modules/@sentry/react-native/android/src/main/java/io/sentry/RNSentryModule.java b/node_modules/@sentry/react-native/android/src/main/java/io/sentry/RNSentryModule.java
index e3fac8d..f31ebc4 100644
--- a/node_modules/@sentry/react-native/android/src/main/java/io/sentry/RNSentryModule.java
+++ b/node_modules/@sentry/react-native/android/src/main/java/io/sentry/RNSentryModule.java
@@ -29,6 +29,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import io.sentry.android.core.AnrIntegration;
+import io.sentry.android.core.ActivityBreadcrumbsIntegration;
 import io.sentry.android.core.NdkIntegration;
 import io.sentry.android.core.SentryAndroid;
 import io.sentry.Sentry;
@@ -156,6 +157,13 @@ public class RNSentryModule extends ReactContextBaseJavaModule {
                 }
             }
 
+            final List<Integration> integrations = options.getIntegrations();
+            for (final Integration integration : integrations) {
+                if (integration instanceof ActivityBreadcrumbsIntegration) {
+                    integrations.remove(integration);
+                }
+            }
+
             logger.info(String.format("Native Integrations '%s'", options.getIntegrations().toString()));
             sentryOptions = options;
         });
diff --git a/node_modules/@sentry/react-native/ios/RNSentry.m b/node_modules/@sentry/react-native/ios/RNSentry.m
index da0488d..b46913b 100644
--- a/node_modules/@sentry/react-native/ios/RNSentry.m
+++ b/node_modules/@sentry/react-native/ios/RNSentry.m
@@ -64,6 +64,9 @@ + (BOOL)requiresMainQueueSetup {
         reject(@"SentryReactNative", error.localizedDescription, error);
         return;
     }
+    NSMutableArray *integrations = [SentryOptions defaultIntegrations].mutableCopy;
+    [integrations removeObject:@"SentryAutoBreadcrumbTrackingIntegration"];
+    sentryOptions.integrations = integrations;
     [SentrySDK startWithOptionsObject:sentryOptions];
 
     resolve(@YES);

@jennmueng
Copy link
Member

That looks about right, yep.

@serhiipalash
Copy link
Author

Hi @jennmueng ! Can you please help me? We have upgraded our @sentry/react-native from v2.1.0 to v2.4.0 and now I am trying to apply patch for disabling activity breadcrumbs on native side. I see that new config option isEnableActivityLifecycleBreadcrumbs was added on Android.

  1. Is it already exposed to React Native?
  2. Can I use it?
  3. Will it work for iOS or should I keep the iOS patch as is?

@jennmueng
Copy link
Member

@serhiipalash

  1. No it is not
  2. Yes you can by supplying it as an option to the init call on Android with setEnableActivityLifecycleBreadcrumbs.
  3. It's not an option on iOS

@serhiipalash
Copy link
Author

Great! Thank you for answers @jennmueng !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants