Reporting Crashes for React Native
Covered here are APIs relevant to crash reporting for your React Native app.
Privacy Policy
It is highly recommended to mention in your privacy policy that you may be collecting logging data in order to assist with troubleshooting crashes.
React Native Crash Types
- Crash: Fatal crashes refer to an error or issue that causes the app to terminate unexpectedly, meaning the app completely shuts down and is no longer usable until the user restarts it. These crashes interrupt the user experience, as the app cannot recover from the issue on its own and must be relaunched.
Fatal crashes are the most severe type of crashes, and they generate crash reports that help developers investigate what caused the app to crash. Typically, they occur due to unhandled errors, system conflicts, or serious resource issues. Here are the types of fatal crashes:
- JavaScript exceptions: Crashes caused by unhandled exceptions in JavaScript, the main programming language for React Native apps. These include syntax errors, type errors, or issues like undefined is not an object.
- Native module crashes: Since React Native bridges JavaScript and native code, crashes can happen when the native code (either Android or iOS) throws an exception or crashes. These would fall under the respective platform's crash types.
- ANR (Application Not Responding): When the main thread is blocked for too long, leading to an ANR error. This is an Android-specific type where the system prompts the user to either wait or force close the app.
- OOM: Out-of-memory crashes occur when the app uses more memory than the device can provide, causing the system to terminate the app to free up resources. Common causes of OOM crashes include: Memory leaks, Heavy resource usage, and Retaining too many objects.
- Non-Fatal: Non-fatal crashes refer to an error or issue that occurs in the app but doesn’t cause the app to completely shut down or crash. Instead, the app encounters a problem, such as an exception or unexpected behavior, but is able to continue running without quitting. Non-fatal crashes are useful for developers because they provide insights into bugs or problems that need fixing before they turn into full-blown crashes.
With Instabug Crash Reporting there are two ways to have your application report a crash, either automatically or manually. After the crash is sent to your dashboard, you can sort and filter for specific crashes easily.
Automatic Crash Reporting
If you enable Crash Reporting, crashes will automatically be reported to and viewable from the crashes page of your Instabug dashboard.
You'll also see the trends covering the previous 7 days, including:
- Crash-free sessions: the percentage of sessions that ran and concluded without any fatal errors.
- Crash-free users: the percentage of users that haven't encountered any fatal errors.
- Crashing sessions: the number of sessions that ran and concluded with a fatal error.
- Affected users: the number of unique users who had one or more sessions that ended with a fatal error.
- Total number of occurrences: by hovering on it, you’ll get a breakdown of the number of fatal sessions, the number of OOM sessions, the number of ANR sessions, and the number of non-fatal sessions.
If there is a sharp decline in the crash-free sessions rate, an email will be sent to notify you.
Warning
Crash reporting will not function correctly if the device is connected to Xcode. When it is, Xcode catches all exceptions and they will not be sent to your dashboard.
Manual Crash Reporting
You can offer your users Instabug Bug Reporting to report bugs. However, you can use the following method and API to manually report any error or exception that you handle in your code and assign it a severity level.
Report Exception
To report exceptions manually, use the following method.
try {
throw new SyntaxError();
} catch (err) {
if (err instanceof Error) {
CrashReporting.reportError(err);
}
}
Release Mode
Crashes will only be reported in release mode and not in debug mode.
Min Required SDK version
Customizing crash level and custom grouping is supported starting SDK v13.1.1.
Add Level to Exception
You can set different severity levels for manually reported exceptions using the following API:
try {
throw new SyntaxError();
} catch (err) {
if (err instanceof Error) {
CrashReporting.reportError(err,{
level: NonFatalErrorLevel.critical,
});
}
}
Here are the different severity levels available. In case no level is indicated, the default level would be error
.
NonFatalErrorLevel.info;
NonFatalErrorLevel.error;
NonFatalErrorLevel.warning;
NonFatalErrorLevel.critical;
Grouping
When an already existing crash occurs once more for any user, that crash is reported as an occurrence in the original entry. However, in order to calculate whether a crash already exists and needs to be grouped, Instabug generates a fingerprint based on attributes used in the grouping logic.
The default Instabug grouping algorithm uses a mix of the exception and stack trace information. In some cases, you might want to change how the issues are grouped together using fingerprints.
Custom Fingerprinting
Overriding the default grouping
Please note that using custom fingerprinting will override Instabug's default grouping by sending a fingerprint string.
In the event that you'd like to report the exception manually with a custom grouping fingerprint in mind, you can use the below APIs to do just that.
try {
throw new SyntaxError();
} catch (err) {
if (err instanceof Error) {
CrashReporting.reportError(err, {
fingerprint: 'grouping fingerprint',
userAttributes: userAttributesObject,
});
}
}
Crashes List
This section contains a list of all the crashes that have been reported by your application. The title of each crash is usually the most significant line in the stack trace.
Next to each crash in the list, you can find the following details, all of which can be used to sort the crashes:
- Occurrences: The number of times this crash has occurred and a bar graph representing its occurrences over the past seven days.
- Users: The number of users affected by this crash.
- Min ver.: The oldest app version that was affected by this crash.
- Max ver.: The latest app version that was affected by this crash.
- Last seen: The last time an occurrence of this crash was reported.
You can then filter for crashes that match any of the following criteria:
- App version
- Date
- Device
- OS
- User attributes
- Type
- Status
- Assignee
- Team
- Tags
- Current view
- Experiments
Updated about 1 month ago
Learn more about the content contained in crash reports as well as how to symbolicate them. You can also use event handlers to collect additional information.