firebase-android-sdk
firebase-android-sdk copied to clipboard
Firebase Crashlytics setCustomKeys stacked for all non-fatals
[READ] Step 1: Are you in the right place?
Yes
[REQUIRED] Step 2: Describe your environment
- Android Studio version: Android Studio Bumblebee | 2021.1.1 Patch 2
- Firebase Component: Crashlytics
- Component version: 29.0.0
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
- Have a function which records exceptions & sets custom keys
fun recordException(message: String, customKeys: Map<String, String> = emptyMap()) {
val crashlytics = Firebase.crashlytics
crashlytics.setCustomKeys { customKeys.forEach { key(it.key, it.value) } }
crashlytics.recordException(Throwable(message))
}
- Call this function several times in a single app usage session
recordException("Non fatal without keys")
recordException("Non fatal with keys", mapOf("key_1" to "value_1"))
recordException("Non fatal with another keys", mapOf("key_2" to "value_2"))
Result:
When the logs are flushed (at the next app start up) the custom keys are associated with all generated logs.
Effectively this means that in the steps above all non fatal logs have the key_1
& key_2
associated with them.
Another defect caused by the issue is that if the app generates a lot of logs with keys (via recordException
) is that after the 64th customKey
no other keys are added.
This produces erroneous log trail by the app & messes up the search by key feature in the Firebase Crashlytics console.
Expected result:
Based on this documentation I am left with the impression that the customKeys
will be associated with the log they are fired for.
Note:
The iOS Crashlytics SDK has the capability of assigning keys for each log by using the userInfo
in NSError
, but that is not possible on Android (Java/Kotlin) because the Throwable
does not provide such map (hence the SDK does not work in that way).
Hi @peterplamenovpenchev, thanks for reporting. I was able to reproduce the same behavior, I'll notify an engineer and see what we can do here.
We are aware of this inconsistency between iOS and Android. We're considering making the two platforms consistent, but it's not a priority right now. We're hesitant because it would change a behaviour that many customers may currently rely on or expect.
Regarding the issue of dropping any keys after the 64th, switching it to retaining the most recently set keys seems like a good improvement and we've logged it as a feature request.
Thanks! I am really looking forward into the changed behaviour of this aspect of the SDK.
@mrober is there a way to implement this on Android atm? I mean - having log specific keys?
I also ran into this issue. As far as I can tell setCustomKey()
does the exact same thing on both iOS and Android. So I do not think there is an inconsistency there.
The userInfo
property that iOS uses to set specific properties for the logged exception is a missing feature on Android. I think the real solution is not to change the setCustomKey()
functionality but to add an overload to the recordException
method allowing us to pass in a map of other values for the specific exception.
Something like this:
public void recordException(@NonNull Throwable throwable, @NonNull Map<String, String> userInfo)
Yea, this sounds very reasonable.
I went by the book & used setCusomKeys
in order to achieve the log specific properties.
I think that what @dperez37 proposes makes a lot of sense.
Have you @mrober considered this or similar solutions? They won't change the existing behaviour.
Thanks for the suggestions. We will keep the user info as a feature request.
We discussed switching custom keys to retain the most recently set keys, but decided not to do it because it would change a subtle behaviour. For example, setting the most important custom key once at app launch.
I was confused by the same problem until I understood exactly how Crashlytics 's setCustomKey
works. I think @dperez37 suggestion is a good idea. However, if the feature request is not possible, I think the Crashlytics
documentation needs to be supplemented with a little more detail about setCustomKey
and the Key
notice displayed in the Firebase Console.
Any update, roadmap? non-fatal API errors in crashlytics are mostly unusuable without custom keys record method, I'm shocked how iOS SDK is much better than Android 😳