Commit f91e609
authored
chore: add segment error tracking to vault issues (MetaMask#19425)
## **Description**
This PR standardizes vault corruption tracking across MetaMask Mobile by
replacing inconsistent direct tracking calls with the centralized
`trackVaultCorruption` utility in multiple components.
**What is the reason for the change?**
1. **Inconsistent Tracking Implementation**: Multiple components (Login,
LockScreen, App, Authentication, EngineService) were using different
approaches to track vault corruption events
2. **Bypassed Utility Logic**: Some components used direct `track()`
calls that bypassed the `trackVaultCorruption` utility's error filtering
and MetaMetrics enabled state checking
3. **Missing Tracking Coverage**: Some critical vault corruption
scenarios (lockscreen failures, app startup failures, engine
initialization failures, migration issues) weren't being tracked at all
4. **Code Duplication**: Similar vault corruption tracking logic was
duplicated across multiple files
**What is the improvement/solution?**
1. **Standardized all vault corruption tracking** to use the
`trackVaultCorruption` utility across Login, LockScreen, App,
Authentication, EngineService, and migration components
2. **Added missing tracking coverage** for previously untracked vault
corruption scenarios
3. **Ensured consistent error filtering** using the utility's
`isVaultRelatedError()` function
4. **Proper MetaMetrics state checking** before tracking events
5. **Cleaned up debug logs** from the tracking utility
## **Analytics Tracking Information**
**Event Name:** `Vault Corruption Detected`
**Key Error Types to Monitor:**
**Login & Authentication Failures:**
- `vault_error` - Core vault unlock failures ("Cannot unlock without a
previous vault.")
- `json_parse_error` - Vault data corruption (JSON parsing issues)
- `lockscreen_authentication_failure` - Lock screen unlock failures
- `authentication_service_failure` - System authentication failures
- `app_startup_authentication_failure` - App startup authentication
issues
**Vault Recovery & Handling:**
- `vault_corruption_handling` - When vault recovery process is initiated
- `vault_corruption_handling_failed` - When vault recovery attempts fail
**System & Migration Issues:**
- `engine_initialization_failure` - Core engine startup failures ("Error
creating the vault")
- `migration_missing_vault` - Existing users missing vault during app
updates
**Context Information:**
- `login_authentication` - Errors during login flow
- `vault_corruption_recovery_attempt` - During vault recovery process
- `lockscreen_unlock_failed` - Lock screen specific failures
- `app_initialization_unlock_failed` - App startup unlock issues
- `engine_service_startup` - Engine initialization context
- `migration_existing_user_validation` - Migration-specific issues
- `app_triggered_auth_failed` - Authentication service failures
**Additional Properties:**
- `oauth_login` - Whether user was in OAuth/social login flow
- `migration_number` - Specific migration version for migration errors
- `has_existing_state` - Whether engine had existing state during
initialization
**Common Error Messages to Look For:**
- "Cannot unlock without a previous vault." - Login vault unlock
failures
- "Error creating the vault" - Engine/system vault creation issues
- "No vault in backup" - Backup restoration failures
- "Password does not exist when calling
SecureKeychain.getGenericPassword" - Keychain access failures
- "Migration X: Existing user missing vault in KeyringController" -
Migration vault issues
**What to Look For:**
- Spikes in vault corruption events across different components
- Patterns in specific error types that indicate systemic issues
- Migration-related vault corruption during app updates
- Authentication failures that could indicate keychain/storage problems
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: #[issue-number]
## **Manual testing steps**
```gherkin
Feature: Standardized vault corruption tracking across components
Scenario: Login component vault corruption tracking
Given user attempts to login with corrupted vault
When login fails with "Cannot unlock without a previous vault."
Then vault corruption is tracked using trackVaultCorruption utility
And event includes error_type="vault_error" and context="login_authentication"
Scenario: LockScreen component vault corruption tracking
Given user attempts to unlock from lock screen
When unlock fails with vault/authentication errors
Then vault corruption is tracked with error_type="lockscreen_authentication_failure"
And uses same utility as other components
Scenario: App startup vault corruption tracking
Given app starts with corrupted vault state
When authentication fails during startup
Then vault corruption is tracked with error_type="app_startup_authentication_failure"
And follows same tracking pattern as other components
Scenario: Engine initialization vault corruption tracking
Given engine fails to initialize due to vault issues
When EngineService catches "Error creating the vault" errors
Then vault corruption is tracked with error_type="engine_initialization_failure"
And includes has_existing_state property
Scenario: Migration vault corruption tracking
Given existing user during app migration
When migration detects missing vault
Then vault corruption is tracked with error_type="migration_missing_vault"
And includes migration_number property
```
## **Screenshots/Recordings**
<img width="1681" height="818" alt="image"
src="https://github.com/user-attachments/assets/794380b6-150d-412d-9807-874c95c62542"
/>
<!-- This is an analytics standardization with no UI changes -->
### **Before**
- Inconsistent vault corruption tracking across components
- Some components missing vault corruption tracking entirely
- Direct track calls bypassing utility's error filtering and state
checking
- Different tracking patterns and property structures across files
### **After**
- Standardized `trackVaultCorruption` utility usage across all
components
- Comprehensive vault corruption tracking coverage
- Consistent error filtering and MetaMetrics state checking
- Uniform event structure and properties across all tracking points
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
---
**Technical Implementation Details:**
**Files Modified:**
- `app/components/Views/Login/index.tsx` - Replaced 3 direct `track()`
calls with `trackVaultCorruption()` calls
- `app/components/Views/LockScreen/index.js` - Added
`trackVaultCorruption()` for lockscreen authentication failures
- `app/components/Nav/App/App.tsx` - Added `trackVaultCorruption()` for
app startup authentication failures
- `app/core/Authentication/Authentication.ts` - Added
`trackVaultCorruption()` for authentication service failures
- `app/core/EngineService/EngineService.ts` - Added
`trackVaultCorruption()` for engine initialization failures
- `app/store/migrations/util/index.tsx` - Added `trackVaultCorruption()`
for migration vault validation failures
- `app/core/Analytics/MetaMetrics.events.ts` - Added
`VAULT_CORRUPTION_DETECTED` event definition
- `app/util/analytics/vaultCorruptionTracking.ts` - Removed debug
`console.log` statements
**Key Changes Made:**
1. **Login Component**: Replaced direct
`track(MetaMetricsEvents.VAULT_CORRUPTION_DETECTED, ...)` calls with
`trackVaultCorruption(...)` calls
2. **LockScreen Component**: Added new tracking for authentication
failures during unlock
3. **App Component**: Added new tracking for app startup authentication
failures
4. **Authentication Service**: Added new tracking for authentication
service failures
5. **EngineService**: Added new tracking for engine initialization
failures
6. **Migration Utility**: Added new tracking for existing users missing
vault during migrations
**Benefits:**
- **Comprehensive Coverage**: All major vault corruption scenarios now
tracked consistently
- **Standardized Implementation**: Single utility function used across
all components
- **Proper State Checking**: MetaMetrics enabled state checked before
all tracking
- **Error Filtering**: All tracking benefits from
`isVaultRelatedError()` filtering
- **Maintainability**: Centralized tracking logic easier to maintain and
update
- **Analytics Consistency**: Uniform event structure across all tracking
points
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds centralized vault corruption tracking utility and integrates it
across login, lock screen, app startup, engine init, auth service, and
migrations, plus defines event and tests.
>
> - **Analytics**:
> - Add `trackVaultCorruption` utility with `isVaultRelatedError` in
`app/util/analytics/vaultCorruptionTracking.ts` and comprehensive tests.
> - Define new event `VAULT_CORRUPTION_DETECTED` in
`app/core/Analytics/MetaMetrics.events.ts`.
> - **UI/Flows**:
> - `Login`: Track vault corruption on detection, handling attempts, and
failures using `trackVaultCorruption`.
> - `LockScreen`: Track auth failures during unlock.
> - `Nav/App`: Track auth failures on app startup.
> - **Core Services**:
> - `Authentication.appTriggeredAuth`: Track authentication failures
suggesting vault/keychain issues.
> - `EngineService.start`: Track engine initialization failures and
route to vault recovery.
> - **Migrations**:
> - Log and track when existing users are missing
`KeyringController.vault` in migration validation.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b2a9cc6. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 22dcd90 commit f91e609
9 files changed
Lines changed: 601 additions & 3 deletions
File tree
- app
- components
- Views
- LockScreen
- Login
- core
- Analytics
- Authentication
- EngineService
- store/migrations/util
- util/analytics
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| |||
1125 | 1126 | | |
1126 | 1127 | | |
1127 | 1128 | | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1128 | 1135 | | |
1129 | 1136 | | |
1130 | 1137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | | - | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
82 | 91 | | |
83 | 92 | | |
84 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
279 | 280 | | |
280 | 281 | | |
281 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
282 | 290 | | |
283 | 291 | | |
284 | 292 | | |
| |||
314 | 322 | | |
315 | 323 | | |
316 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
317 | 332 | | |
318 | 333 | | |
| 334 | + | |
319 | 335 | | |
320 | 336 | | |
321 | 337 | | |
| |||
506 | 522 | | |
507 | 523 | | |
508 | 524 | | |
| 525 | + | |
509 | 526 | | |
510 | 527 | | |
511 | 528 | | |
| |||
550 | 567 | | |
551 | 568 | | |
552 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
553 | 579 | | |
554 | 580 | | |
555 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
| 406 | + | |
406 | 407 | | |
407 | 408 | | |
408 | 409 | | |
| |||
1039 | 1040 | | |
1040 | 1041 | | |
1041 | 1042 | | |
| 1043 | + | |
1042 | 1044 | | |
1043 | 1045 | | |
1044 | 1046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
621 | 622 | | |
622 | 623 | | |
623 | 624 | | |
624 | | - | |
625 | 625 | | |
626 | 626 | | |
627 | 627 | | |
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
661 | 669 | | |
662 | 670 | | |
663 | 671 | | |
664 | | - | |
| 672 | + | |
665 | 673 | | |
666 | 674 | | |
667 | 675 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
68 | 79 | | |
69 | 80 | | |
70 | 81 | | |
| |||
0 commit comments