Firebase Crashlytics reporting with custom keys

Viewed 5123

I wanted to send some custom keys for each crash, say a crash identifier to identify the user reported crash from crashlytics. I see the Crashlytics API provides a method setObjectValue(forkey:) to do this, but, where in code should this be called ? Do we have any Crashlytics callback that gets triggered when a crash happens? So far I have seen, there is only a callback to know whether crash happened during the last session.

  1. So which would be the best place to add custom keys to be associated for each crash?
  2. Docs say that Crashlytics supports a maximum of 64 such key/value pairs, does it mean that we can add custom keys only for 64 crashes or how does that work ?
2 Answers

You can add custom keys whenever you want, after initializing Crashlytics. The keys would be attached to any future crash during the life of the app.

You can have up to 64 key/value pairs (after that, they aren't saved). So if you sent into Crashlytics 64 key/value pairs, then later the app crashed, those 64 key/value pairs would be added info in the crash report which is created and sent to Fabric and Firebase at next launch of the app.

There are no callbacks due to a crash in the app session... the app crashed and thus terminated, after all! :)

To add an identifier to a recorded exception in FirebaseCrashlytics, you can set an identifier: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#set-user-ids

Although sometimes you won't need an identifier, but just extra information, like the ID of the involved object(s) related to the crash. This can be set up with custom keys: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#add-keys

One little addition to this topic, is that right after tracking an Exception with FirebaseCrashlytics.getInstance().recordException(Exception()), the custom keys will be consumed, but not the identifier.

Related