Skip to content

Add logging and tracking for application password login#22709

Merged
adalpari merged 18 commits intorelease/26.7from
logging/A-P-logging-and-tracking
Mar 19, 2026
Merged

Add logging and tracking for application password login#22709
adalpari merged 18 commits intorelease/26.7from
logging/A-P-logging-and-tracking

Conversation

@adalpari
Copy link
Contributor

@adalpari adalpari commented Mar 19, 2026

Description

Cherry-picks from #22694 and #22702 into release/26.7.

Adds comprehensive logging, analytics tracking, and crash reporting for the
application password login flow:

  • Diagnostic logging: Improved error logs during application password
    storing, avoiding PII exposure (site URLs) and full response object leaks
  • Analytics tracking: Added Tracks events for application password storing
    failures with error context
  • Crash reporting: Sentry reports on login failures and storeCredentials
    false-return paths
  • Error handling: Internal errors are hidden from user-facing toasts,
    non-null assertions fixed
  • Code quality: Extracted log helper and refactored long methods to fix
    detekt LongMethod violations

Files changed

  • ApplicationPasswordLoginViewModel.kt — error handling, Sentry/Tracks
    integration, refactored onSiteChanged
  • ApplicationPasswordLoginHelper.kt — Sentry reports on storeCredentials
    failures, refactored for detekt
  • ApplicationPasswordAutoAuthDialogViewModel.kt — PII-safe logging
  • SiteStore.kt — logging improvements
  • Tests updated accordingly

Testing instructions

NOTE: MORE IMPORTANT THAN THE LOGS IS THE LOGIN FLOW IS NOT BROKEN, SO PLEASE PAY ATTENTION TO THAT

Application password login success:

  1. Log in with a self-hosted site using application passwords
  • Verify login completes successfully
  • No unexpected error toasts shown
  1. Add a self-hosted site using application passwords
  • Verify login completes successfully
  • No unexpected error toasts shown
  1. For this step, be sure that the AP FF is enabled.
  2. Revoke credentials from the wp-admin and try to open a screen that users APs. E.g: Media
  • Verify login completes successfully
  • No unexpected error toasts shown

Application password login failure:

  1. Simulate a login failure (e.g., invalid credentials, network error)
  • Verify a human-friendly toast is shown
  • Verify detailed logs (Use "A_P" tag)

adalpari and others added 17 commits March 19, 2026 09:50
Add detailed field-level diagnostics to all error paths in the
application password login flow so developers can identify the
root cause from logs alone.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Log only the response class name instead of the full object, since
WpRequestResult variants could contain sensitive API response data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The createApplicationPassword function exceeded the 60-line limit
after adding detailed error logging. Extract a logCreationError
helper to keep the method concise.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The new logging in the "site not found" branch reads siteStore.sites
a second time to log available URLs. Update the test verification
to expect two calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fire APPLICATION_PASSWORD_STORING_FAILED Tracks event and a Sentry
report whenever the credential storing flow fails, so we can monitor
failure rates and reasons in production. Also replace available site
URL logging with just a count to avoid PII exposure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the full list of available site URLs with just a count in
the "site not found" error log, since site URLs may reveal personal
domains or business names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Surface detailed error messages when application password login fails,
instead of showing a generic toast or silently crashing. Catches
exceptions in SiteStore encryption/decryption paths and threads error
details through to the UI toast.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Every error path in the login flow now sends a crash report via
CrashLogging so we get visibility into failures in the wild.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lures

Re-applies the reverted changes from #22694 that add trackStoringFailed()
calls with specific reason codes (empty_raw_data, empty_fetch_params,
fetch_sites_exception, site_changed_failed, bad_data, site_not_found)
and CrashLogging reports for better debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…sertion, add tests

- Show only user-friendly message in toast, keep detailed errors in logs/crash reports
- Replace site!! with safe ?: return@launch
- Fix import ordering (com.* before org.*)
- Add TODO comments on broad catch blocks to narrow once root cause identified
- Add CrashLogging mock and 5 new tests for error branches (SiteStore error,
  no rows affected, bad credentials, DB exception, crash report verification)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Split onSiteChanged into smaller focused methods to stay under the
60-line detekt limit: handleSiteChangedError, handleSiteChangedSuccess,
validateSiteChanged, and logAndEmitSiteChangedError. Also remove TODO
comments from SiteStore catch blocks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nd error message leaks

- Remove crashLogging from ApplicationPasswordLoginHelper.trackStoringFailed
  so only the ViewModel's emitError sends Sentry reports with full context
- Add trackStoringFailed and crashLogging.sendReportWithTag to the
  storeCredentials catch block so KeyStore failures are tracked
- Replace technical error messages in NavigationActionData.errorMessage
  with opaque error codes (e.g. site_store_error, no_rows_affected)
- Use e.message ?: e.javaClass.simpleName in SiteStore catch blocks
  as fallback for exceptions without a message

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add crashLogging.sendReportWithTag calls in storeApplicationPasswordCredentialsFrom
for the bad_data and site_not_found paths, which return false without throwing.
These are not duplicates of the ViewModel's emitError reports — they cover failures
where execution continues to fetchSites and the ViewModel never calls emitError.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TODO: Remove before merging. Uncomment the throw line to verify
that the storeCredentials error path sends analytics and Sentry reports.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract logAndReportBadData and logAndReportSiteNotFound from
storeApplicationPasswordCredentialsFrom to bring it under the
60-line detekt limit. Also extract reportStoringFailedToSentry
to deduplicate Sentry exception construction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dangermattic
Copy link
Collaborator

dangermattic commented Mar 19, 2026

2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 19, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr22709-a046bd1
Build Number1487
Application IDorg.wordpress.android.prealpha
Commita046bd1
Installation URL2mtu85c4m1qrg
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 19, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr22709-a046bd1
Build Number1487
Application IDcom.jetpack.android.prealpha
Commita046bd1
Installation URL1fghbqbl141l0
Note: Google Login is not supported on these builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 80.98160% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.78%. Comparing base (42ae4c9) to head (a046bd1).
⚠️ Report is 1 commits behind head on release/26.7.

Files with missing lines Patch % Lines
...ava/org/wordpress/android/fluxc/store/SiteStore.kt 0.00% 15 Missing ⚠️
...ationpassword/ApplicationPasswordLoginViewModel.kt 90.74% 1 Missing and 9 partials ⚠️
...i/accounts/login/ApplicationPasswordLoginHelper.kt 87.50% 0 Missing and 4 partials ⚠️
...word/ApplicationPasswordAutoAuthDialogViewModel.kt 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           release/26.7   #22709      +/-   ##
================================================
+ Coverage         37.74%   37.78%   +0.03%     
================================================
  Files              2268     2268              
  Lines            117578   117681     +103     
  Branches          16281    16298      +17     
================================================
+ Hits              44376    44461      +85     
- Misses            69565    69574       +9     
- Partials           3637     3646       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adalpari adalpari marked this pull request as ready for review March 19, 2026 10:48
@adalpari adalpari requested review from jkmassel and nbradbury March 19, 2026 10:48
@nbradbury
Copy link
Contributor

@adalpari I don't know if this indicates a problem, but logging into my self-hosted test site caused this to appear in logcat:

WordPress-DB   com.jetpack.android.prealpha         
E  A_P: Cannot save credentials - site not found: 
https://rabbit-of-caribbeans.jurassic.ninja 
(normalized: https://rabbit-of-caribbeans.jurassic.ninja) — 10 sites available

Login worked fine, though.

@nbradbury
Copy link
Contributor

@adalpari I simulated a login failure and logcat showed this:

A_P: Cannot save credentials - site not found: https://rabbit-of-caribbeans.jurassic.ninja

This is great, but the error message didn't say anything about the cause of the problem:

Screenshot_20260319_074301

I'm not sure we can do much about this but wanted to raise the issue.

Copy link
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I left one comment which you may or may not want to address, but either way I'll approve it :shipit:

@adalpari
Copy link
Contributor Author

@adalpari I simulated a login failure and logcat showed this:

A_P: Cannot save credentials - site not found: https://rabbit-of-caribbeans.jurassic.ninja

This is great, but the error message didn't say anything about the cause of the problem:

Well, I think it actually says something: the site has not been saved to the DB in the previous step. so It's "not found".
Thank you for noting it anyway!

@adalpari adalpari merged commit b7c7a3f into release/26.7 Mar 19, 2026
29 of 33 checks passed
@adalpari adalpari deleted the logging/A-P-logging-and-tracking branch March 19, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants