Crash reporting in Firebase - Time & Space Complexity
When using Firebase Crash Reporting, it's important to understand how the number of crash reports affects processing time.
We want to know how the system handles more crash events as they come in.
Analyze the time complexity of sending multiple crash reports to Firebase.
for (let i = 0; i < crashEvents.length; i++) {
firebase.crash().log("Crash event " + i);
firebase.crash().recordError(new Error("Error " + i));
}
This code logs and records each crash event individually to Firebase Crash Reporting.
Look at what repeats as the number of crash events grows.
- Primary operation: Sending a crash log and error report to Firebase for each event.
- How many times: Once per crash event, so as many times as there are events.
Each new crash event causes two Firebase calls: one to log and one to record the error.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 20 calls (2 per event) |
| 100 | 200 calls |
| 1000 | 2000 calls |
Pattern observation: The number of API calls grows directly with the number of crash events.
Time Complexity: O(n)
This means the time to send crash reports grows in a straight line as the number of crashes increases.
[X] Wrong: "Sending many crash reports happens instantly and does not add up."
[OK] Correct: Each crash report requires a network call, so more crashes mean more time spent sending data.
Understanding how operations scale with input size helps you design efficient cloud systems and explain your reasoning clearly.
"What if we batch multiple crash events into a single API call? How would the time complexity change?"
Practice
Solution
Step 1: Understand Crashlytics role
Firebase Crashlytics is designed to track and report app crashes automatically.Step 2: Compare with other options
Storing user data, improving speed, and managing authentication are not Crashlytics functions.Final Answer:
To automatically collect and report app crashes -> Option DQuick Check:
Crashlytics = crash reporting [OK]
- Confusing Crashlytics with user data storage
- Thinking it speeds up the app
- Mixing it with authentication services
Solution
Step 1: Identify logging method
The method to add custom logs before a crash is crashlytics.log().Step 2: Understand other methods
recordError() reports errors, sendReport() and startSession() are not valid Crashlytics methods.Final Answer:
crashlytics.log() -> Option CQuick Check:
Logging = crashlytics.log() [OK]
- Using recordError() to log messages
- Assuming sendReport() exists
- Confusing startSession() with logging
try {
throw new Error('Test crash');
} catch (e) {
firebase.crashlytics().recordError(e);
}Solution
Step 1: Analyze try-catch behavior
The error is thrown but caught, so the app does not crash.Step 2: Understand recordError effect
recordError() sends a non-fatal error report to Crashlytics with the error message.Final Answer:
Crashlytics reports a non-fatal error with message 'Test crash' -> Option AQuick Check:
recordError() = non-fatal error report [OK]
- Thinking caught errors cause app crash
- Assuming no report if error is caught
- Confusing recordError() with crash trigger
firebase.crashlytics().log('User clicked button'); but no logs appear in Crashlytics dashboard. What is the likely issue?Solution
Step 1: Check Crashlytics log behavior
Logs sent by log() appear only when a crash happens afterward.Step 2: Verify other options
SDK initialization is required but if logs never appear, it's likely due to no crash. log() exists and sendReport() is not a Crashlytics method.Final Answer:
Logs only appear after a crash occurs -> Option AQuick Check:
Logs show after crash [OK]
- Assuming logs show immediately
- Thinking log() method is missing
- Trying to send logs manually
Solution
Step 1: Add context with custom keys
Use setCustomKey() to add extra info about the error context.Step 2: Report error as non-fatal
Call recordError() to send the caught error along with custom keys to Crashlytics.Final Answer:
Use crashlytics().setCustomKey() before recordError() -> Option BQuick Check:
Custom keys + recordError() = detailed non-fatal report [OK]
- Only logging message without keys
- Throwing error again causes crash
- Using non-existent sendReport() method
Ready to prove it?
Pass the test and this pattern moves unknown
