-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix(crashlytics,ios): Explicitly set crash collection setting to opt in or out for iOS #4236
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/invertase/react-native-firebase/ezdtvl94z |
PR spawned from discussion here #4227
I read the text but haven't followed the links and checked the code yet, if it matches the text and I see what I'm expecting to see though, this could be what we've needed for a while! Either way I'm extremely thankful you've gotten the ball rolling here with a real PR for it and I'll look at it more tomorrow morning |
if ([self isCrashlyticsCollectionEnabled]) { | ||
[FIRApp registerInternalLibrary:self withName:@"react-native-firebase-crashlytics" withVersion:@"6.0.0"]; | ||
} | ||
[FIRApp registerInternalLibrary:self withName:@"react-native-firebase-crashlytics" withVersion:@"6.0.0"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a separate issue as well - the version number should be dynamic and track with the package but it is not. That has nothing to do with this PR though, I will peel that out to a separate issue
* At this point "configure" has already been called on the FIRApp instance. This behavior is meant to mirror | ||
* what is done in ReactNativeFirebaseCrashlyticsInitProvider.java | ||
* | ||
* This pattern may not be supported long term https://github.com/firebase/firebase-ios-sdk/issues/2933 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting callout here! I just scanned that issue and the resulting PRs
It looks like dynamic links has a very visible example of what the change means - that configureWithApp should go away, and that 'componentsToRegister' becomes the new natural home for the logic, with a new flag to initialize quickly
What I don't know though is where to put that flag that says we want init eagerly (for the default app since crashlytics does not do multi-app) - e.g. this https://github.com/firebase/firebase-ios-sdk/pull/4137/files/71f589926b74e69ea76d0a25ae24e58efee6836b#diff-f33c561b2a3430b947e6da076758c6d9R1887
I think this might be good enough (it will certainly work now) but we need a separate issue to track this as they will appear set to purge it for v7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuff is very hard to test! I can see the expected log out put though and I believe this is all correct. Will be good to get more feedback from other affected people
…e#4236) * Explicitly set crash collection setting PR spawned from discussion here invertase#4227
Description
PR spawned from discussion here #4227
By my reckoning, I think there may be some behavior that is maaaaybe not working as expected, and I also think there is some behavior that is definitely not working as I'd expect it.
Sorry if this is verbose, but some of this is very new for me so I wanted to be explicit. Also, apologies if I'm way off base on any of this
1.
FirebaseCrashlyticsCollectionEnabled
gets turned off by default by react-native-firebaseApp developers using Crashlytics can go out of their way to set
FirebaseCrashlyticsCollectionEnabled
tofalse
to turn off automatic crash collection in their apps. Why would a dev do that? Maybe they want to give users control over their data. They can make an "Opt-in" view in the app that allows users to opt-in to uploading crash reports.react-native-firebase does the opposite. It disables collecting crash reports by default.
Note here, the default for react-native-firebase is to always set
FirebaseCrashlyticsCollectionEnabled
to No/false unless_CRASHLYTICS_AUTO_DISABLE_ENABLED
is set to true, and_CRASHLYTICS_AUTO_DISABLE_ENABLED
is derived fromcrashlytics_disable_auto_disabler
. [2]If react-native-firebase devs don't set
crashlytics_disable_auto_disabler
totrue
infirebase.json
, then theFirebaseCrashlyticsCollectionEnabled
automatically gets set to false!Unexpected, but also, not actually a problem because it's still entirely possible for the app to send crash reports. It's just not automatic by default.
2. On iOS react-native-firebase apps never actually set the collection setting on the Crashlytics instance
I think this is actually a bug/missing bit of behavior.
react-native-firebase turns off automatic crash collection by default (see above), which is fine actually. it's fine because react-native-firebase can still explicitly enable collecting crash reports by calling
setCrashlyticsCollectionEnabled:true
. Calling that essentially overrides whatever was done withFirebaseCrashlyticsCollectionEnabled
.We call
setCrashlyticsCollectionEnabled
on the Java side, but not on the iOS side.On both the iOS and Java side, we have
isCrashlyticsCollectionEnabled()
. We use that method to infer if the app wants to enable or disable crashlytics using one of several mechanisms (including thecrashlytics_auto_collection_enabled
key infirebase.json
). Most importantly, we use the result of that to actually set the setting on our crashlytics instance in Java.react-native-firebase/packages/crashlytics/android/src/main/java/io/invertase/firebase/crashlytics/ReactNativeFirebaseCrashlyticsInitProvider.java
Line 54 in 55cd752
iOS has a mirror version of the
isCrashlyticsCollectionEnabled()
method. However, on the iOS side we never actually use the result of that method to set the setting on our Crashlytics instance.react-native-firebase/packages/crashlytics/ios/RNFBCrashlytics/RNFBCrashlyticsInitProvider.m
Line 54 in 55cd752
I verified that, by default,
isCrashlyticsCollectionEnabled
will returntrue
if the developer does nothing. But because iOS never sets the setting, we don't opt-in to collecting crashes!I feel like this is a bug, and we should use the change in this PR to do the same thing on iOS as in Java.
Related issues
Fixes discussion #4227
Release Summary
Update crash collection behavior on iOS
Checklist
Android
iOS
e2e
tests added or updated inpackages/\*\*/e2e
jest
tests added or updated inpackages/\*\*/__tests__
Test Plan
For the first issue I mentioned, build an app with react-native-firebase. Check out the builds logs in the report navigator in Xcode (filter on
[RNFB] Core Configuration
and expand all transcripts). Notice that the default behavior (with an empty{}
firebase.json`) is to disable automatic collection of crashes.For the second issue, enable
-FIRDebugEnabled
for the build to see Crashlytics logs.Add something like this to your AppDelegate.m. Before my changes, you should see that setting
crashlytics_auto_collection_enabled
totrue
orfalse
infirebase.json
doesn't actually change the result here. With my changes, you should see that the firebase.jsoncrashlytics_auto_collection_enabled
setting actually impacts whether or not Crashlytics collects crash reports.On my side, I couldn't get the crashlytics JS libraries to resolve properly from my in-development
../react-native-firebase
package (I don't contribute to packages often), so I just threw errors in some Swift bridged code I had. I built on the simulator, killed the app to detach the debugger, then launched it and ran code that triggered a bunch offatalError()
in the native code.crashlytics_auto_collection_enabled
wasfalse
, then after several crashes I switched it totrue
, re-launched, and saw my exceptions show up in Crashlytics.Something that kinda sucks is the log looks a little confusing. The AppDelegate check is accurate, but since
configure
was already called beforehand, it has an earlier log message saying,Automatic data collection is disabled.
, which is technically accurate, but then immediately negated. Subsequent launch debug logs would look more consistent.Without my changes, I could only change enable crash collection with
[[FIRCrashlytics crashlytics] setCrashlyticsCollectionEnabled:false];
(ortrue
) in native code. Changingfirebase.json
and re-building didn't work.Searching for
unsent
in the logs allowed me to see that reports were collecting on device and that I could then try changing the collection status to test changes.Important testing note! Please keep in mind that
setCrashlyticsCollectionEnabled:
writes changes to disk. it is not ephermeral. If that method is called, the setting used will stick until either the app is deleted or the setting is explicitly changed.🔥