This guide describes how to customize your crash reports using the Firebase Crashlytics SDK. By default, Crashlytics automatically collects crash reports for all your app's users (you can turn off automatic crash reporting and enable opt-in reporting for your users instead). Crashlytics provides four logging mechanisms out of the box: custom keys, custom logs, user identifiers, and caught exceptions.
Add custom keys
Custom keys help you get the specific state of your app leading up to a crash. You can associate arbitrary key/value pairs with your crash reports and see them in the Firebase console.
Use the setCustomKey
instance method to set key/value pairs:
Java
setCustomKey
is overloaded for the value
parameter to accept any
primitive or String argument. For example:
// Set a key to a string. FirebaseCrashlytics.getInstance().setCustomKey("str_key", "hello"); // Set a key to a boolean. FirebaseCrashlytics.getInstance().setCustomKey("bool_key", true); // Set a key to an int. FirebaseCrashlytics.getInstance().setCustomKey("int_key", 1); // Set a key to a long. FirebaseCrashlytics.getInstance().setCustomKey("int_key", 1L); // Set a key to a float. FirebaseCrashlytics.getInstance().setCustomKey("float_key", 1.0f); // Set a key to a double. FirebaseCrashlytics.getInstance().setCustomKey("double_key", 1.0);
Kotlin
// Set a key to a string. FirebaseCrashlytics.getInstance().setCustomKey("str_key", "hello") // Set a key to a boolean. FirebaseCrashlytics.getInstance().setCustomKey("bool_key", true) // Set a key to an int. FirebaseCrashlytics.getInstance().setCustomKey("int_key", 1) // Set a key to an long. FirebaseCrashlytics.getInstance().setCustomKey("int_key", 1L) // Set a key to a float. FirebaseCrashlytics.getInstance().setCustomKey("float_key", 1.0f) // Set a key to a double. FirebaseCrashlytics.getInstance().setCustomKey("double_key", 1.0)
You can also modify the value of an existing key by calling the key and setting it to a different value. For example:
Java
FirebaseCrashlytics.getInstance().setCustomKey("int_key", 50); // Set int_key from 50 to 100. FirebaseCrashlytics.getInstance().setCustomKey("int_key", 100);
Kotlin
FirebaseCrashlytics.getInstance().setCustomKey("int_key", 50) // Set int_key from 50 to 100. FirebaseCrashlytics.getInstance().setCustomKey("int_key", 100)
Add custom log messages
To give yourself more context for the events leading up to a crash, you can add custom Crashlytics logs to your app. Crashlytics associates the logs with your crash data and displays them in the Crashlytics page of the Firebase console, under the Logs tab.
Use log
to help pinpoint issues. For example:
Java
FirebaseCrashlytics.getInstance().log("Higgs-Boson detected! Bailing out");
Kotlin+KTX
FirebaseCrashlytics.getInstance().log("Higgs-Boson detected! Bailing out")
Set user identifiers
To diagnose an issue, it’s often helpful to know which of your users experienced a given crash. Crashlytics includes a way to anonymously identify users in your crash reports.
To add user IDs to your reports, assign each user a unique identifier in the form of an ID number, token, or hashed value:
Java
FirebaseCrashlytics.getInstance().setUserId("12345");
Kotlin+KTX
FirebaseCrashlytics.getInstance().setUserId("12345")
If you ever need to clear a user identifier after you set it, reset the value to a blank string. Clearing a user identifier does not remove existing Crashlytics records. If you need to delete records associated with a user ID, contact Firebase support.
Report non-fatal exceptions
In addition to automatically reporting your app’s crashes, Crashlytics lets you record non-fatal exceptions and sends them to you the next time your app launches.
Use the recordException
method to record non-fatal exceptions in
your app's catch
blocks. For example:
Java
try { methodThatThrows(); } catch (Exception e) { FirebaseCrashlytics.getInstance().recordException(e); // ...handle the exception. }
Kotlin+KTX
try { methodThatThrows() } catch (e: Exception) { FirebaseCrashlytics.getInstance().recordException(e) // ...handle the exception. }
All recorded exceptions appear as non-fatal issues in the Firebase console. The issue summary contains all the state information you normally get from crashes, along with breakdowns by Android version and hardware device.
Crashlytics processes exceptions on a dedicated background thread to minimize the performance impact to your app. To reduce your users’ network traffic, Crashlytics batches logged exceptions together and sends them the next time the app launches.
Enable opt-in reporting
By default, Crashlytics automatically collects crash reports for all your app's users. To give users more control over the data they send, you can enable opt-in reporting for your users by disabling automatic collection and initializing Crashlytics only for selected users:
In the
application
block of yourAndroidManifest.xml
file, add ameta-data
tag to turn off automatic collection:<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />
Enable collection for select users by calling the Crashlytics data collection override at runtime. The override value persists across launches of your app so Crashlytics can automatically collect reports. To opt out of automatic crash reporting, pass
false
as the override value. When set tofalse
, the new value does not apply until the next run of the app.Java
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
Kotlin+KTX
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)
Manage Crash Insights data
Crash Insights helps you resolve issues by comparing your anonymized stack traces to traces from other Firebase apps and letting you know if your issue is part of a larger trend. For many issues, Crash Insights even provides resources to help you debug the crash.
Crash Insights uses aggregated crash data to identify common stability trends. If you’d prefer not to share your app's data, you can opt-out of Crash Insights from the Crash Insights menu at the top of your Crashlytics issue list in the Firebase console.