Files
buzz/docs/mobile-diagnostic-reporting.md
Tom Brow 42dc2a8c58 feat(mobile): add screen breadcrumbs to diagnostic reports (#9823)
feat(mobile): add screen breadcrumbs to diagnostic reports
Adds screen breadcrumbs to mobile diagnostic reports, so a hang or error
report shows which screens the person was on before it happened. Today
the only breadcrumbs are foreground and background changes.

## Changes

- **Observers:** one `DiagnosticScreenTrail` is shared by an observer on
the root navigator and one on each conversation pane's nested navigator,
where channels, threads, search and activity open. A breadcrumb is left
on push, replace, and when a page is shown again after a pop, a frame
later and only for the page that ends up visible.
- **The screen the person is on:** a route that hosts a pane with a page
open past its first (a phone conversation over the channel list, or a
wide conversation beside it) is named by that page. So closing a
full-screen cover, such as a huddle, over an open channel records
`channel`, not `channelList`.
- **No repeats:** a screen equal to the last one is skipped. A pane host
and its pane's empty first page both name the host, and wide Settings
sections all show Settings, so these leave one crumb. The empty first
page still gives Home its crumb after sign-in.
- **Names come from a fixed list owned by the app:**
`lib/diagnostic_screens.dart` maps page widgets to names such as
`channelList`, `channel`, `thread`, `settings` or `addCommunity`, and
reaches the observers through `diagnosticScreenClassifierProvider`,
which the root scope overrides. Any other page is `other`. Route
settings and page content are never read, so no channel name, ID or text
can reach a breadcrumb.
- **Dialogs, sheets and menus are skipped:** popup routes leave nothing,
and the Duo channel sheet, which is a page route, opts out with
`DiagnosticSheetRoute`.
- **Filter:** adds a `navigation` category to the breadcrumb list. A
navigation breadcrumb leaves with only its screen name, and it is
dropped if that name isn't on the list.
- **No destination:** a build without a reporting destination does
nothing; the observers don't even inspect routes.
- **Spec:** the breadcrumb list, user story 7, and the out-of-scope line
about behavior data.

## Regressions

- **Architecture:** the screen list lives with the app, so `shared/`
gains no imports from features. The shared conversation pane's import
closure is unchanged from main.
- **Performance:** the route walk costs well under a millisecond per
navigation (28 to 155 µs measured, against 58 to 143 ms for the push
frame). Rebuild counts are unchanged with reporting on and off, and
nothing new goes over the network.
- **Confined to reporting builds:** in a build without a destination the
observers return before touching a route.

## Validation

New tests in
[`diagnostic_navigation_test.dart`](https://github.com/block/buzz/blob/tomb/mobile-diag-screen-breadcrumbs/mobile/test/shared/diagnostics/diagnostic_navigation_test.dart):
- the app's list, including `addCommunity` for adding a community and an
unlisted page;
- a root journey: a route whose settings carry an ID records only the
plain name, a dialog and a sheet route leave nothing, and two pops at
once leave only where they end;
- a phone journey with the real pane: Home once, channel, thread and
back, a cover closing back onto the open channel, closing the channel,
and a page with its own pane named once;
- a wide Settings pane where changing sections adds nothing;
- a build with no reporting destination.

Plus filter rows for nameless, unlisted and valid navigation
breadcrumbs.


Full-app run on an iOS simulator at 85a72de, signed in to a test
community: channel list, a channel and its details page, a message's
actions sheet, a thread and back, Search, Activity, Agents, Settings and
its status sheet, the identity-to-desktop confirmation, and the
community switcher's Add Community page. Every flow opened and closed
normally with no Flutter exceptions or error screens.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
2026-11-22 09:10:13 -08:00

18 KiB

Mobile diagnostic reporting

Status: step one in progress. Implemented: the reporting module, explicit error reports (for push, the relay's capability descriptor and the push gateway's replies) and networking counts.

Terminology is defined in CONTEXT.md. The decisions behind this spec are in ADR 0007 and ADR 0008.

Problem statement

When the mobile app crashes or misbehaves, nobody who can fix it finds out. Uncaught errors are dropped, failures are caught and shown as a generic message or nothing, and there is no record of how often the app's connections to its backends fail. A member who reports "it was slow" or "it crashed" cannot be helped without their phone in hand, and a backend problem that affects many members at once is invisible from the client side.

Solution

A build that is given a reporting destination does diagnostic reporting: it sends crashes, unexpected errors and networking measurements to that destination, tagged with the member who hit them. A build without a reporting destination sends nothing and behaves exactly as today. Reports never contain what people write or the names of the places they write it.

User stories

  1. As a developer, I want every crash of the app reported with a readable stack trace, so that I can fix crashes I never saw myself.
  2. As a developer, I want every uncaught Dart and Flutter error reported, so that errors the app currently drops become visible.
  3. As a developer, I want a report when the relay sends something the app cannot decode, so that protocol mismatches are found quickly.
  4. As a developer, I want a report when the relay rejects something the app sent as invalid, so that client bugs in what we send are found.
  5. As a developer, I want a report when a Builderlab or push gateway response cannot be understood, so that contract drift is caught.
  6. As a developer, I want a report when data saved on the device cannot be read back, so that storage corruption and migration bugs surface.
  7. As a developer, I want each report to carry the trail of recent networking events and the screens the person was on, so that I can see what the connection was doing and where the person was before the fault.
  8. As a developer, I want each report to carry the member's public key, so that I can follow up with the person who hit it.
  9. As a developer, I want timeouts, disconnects, being offline, rate limits and refused sign-ins counted and not reported as errors, so that the error list contains only bugs someone can fix.
  10. As a developer, I want every network request and relay connection event counted with its backend, endpoint, outcome and kind of failure, so that I can see which backend and which operation is failing.
  11. As a developer, I want request durations measured per backend and endpoint, so that slowness shows up as well as failure.
  12. As a developer, I want those counts to carry the member, so that I can answer "who hit this failure, and when" without a separate log.
  13. As a person on call, I want to be alerted when the failure rate for a backend or endpoint spikes, so that an outage seen only by clients is noticed.
  14. As a distributor of an internal build, I want to turn reporting on by supplying one build-time setting, so that my organization's reports go to my own destination.
  15. As a distributor, I want stack traces from my release builds to be readable, so that reports are usable.
  16. As someone building the app from source, I want a build with no reporting destination to send nothing and start no reporting code, so that the open-source app reports to no one by default.
  17. As a member, I want reports to never include message content, channel or community names, private keys or other secrets, so that diagnosing faults does not expose what I write.
  18. As a member, I want reporting to never slow the app or block what I am doing, so that diagnosis does not cost me anything.
  19. As a developer, I want signing out or switching accounts to change who later reports are attributed to, so that reports are never tagged with the wrong member.
  20. As a reviewer, I want all reporting to go through one small interface, so that I can check what leaves the device in one place.
  21. As a developer, I want freezes of the main thread reported with their stack (on iOS when the app is blocked for long enough, and on both platforms when the system ends the app for not responding), so that I can fix freezes that never show up as crashes.

Implementation decisions

  • One reporting module. All app code reports through a single interface with three operations: report an error, count a networking event (with an optional duration), and leave a breadcrumb. It has two implementations: one backed by the Sentry Flutter SDK and one that does nothing. Nothing outside this module imports the SDK.
  • The reporting destination is a build-time setting, named with the implementation to match the existing BUZZ_ build settings. When it is absent, the app uses the do-nothing implementation and never initializes the SDK. There is no check on the kind of build, no in-app switch and no notice (ADR 0007).
  • Crashes and uncaught errors are captured by the SDK's own handlers for native crashes, Flutter framework errors and uncaught asynchronous Dart errors, installed at startup around the app.
  • Explicit error reports are added at the places where the app meets something that should never happen: a relay frame or query response that cannot be decoded, a relay rejection whose reason says the app sent something invalid (except a refusal the app already handles as an expected outcome, such as an archived channel, an Unarchive of a channel that is no longer archived, a channel name that is taken, an agent whose policy refuses the addition, a guest adding people, a sole owner leaving or an event whose timestamp is outside the relay's window, which is counted; that last one is left out for every event, so a device with a wrong clock does not report every publish, at the cost of hiding a signed event retried after the window has passed), an account or push gateway response that cannot be understood, saved data that cannot be read back, and an event subscriber that throws while handling an event.
  • Routine failures are counted, never reported. Timeouts, disconnects, unreachable or insecure hosts, rate limits, refused or expired sign-ins and server errors increment a count. That includes the relay's own errors, such as a query that timed out or too many subscriptions. Of the reasons a relay gives for a rejection, only the one that marks the request as invalid is reported, with the exception above; every other reason is counted.
  • Networking measurements. Every request through the app's shared HTTP client and every relay connection event (connected, disconnected, reconnect attempt, request timed out, subscription closed by the relay) is counted with four attributes: backend, endpoint, outcome and kind of failure. The backend is the host name of the server the app was talking to when it is one of the app's own (a relay the app has used this run, the build's Builderlab and push gateway); any other host, such as a remote image's, is counted as external, so a host that names a person never leaves the phone. Endpoints are names from a fixed list, never raw paths. Durations are recorded for requests (to response headers) and for time to connect. A request the app gives up on at its own deadline is a timeout, including one whose successful response body is still arriving; one the app cancels (a view closing, an image scrolled away) is not counted. A request still in flight when the member signs out or switches is not counted for anyone. HTTP is measured where the app's shared HTTP client already classifies transport failures; relay connections are measured by hand in the relay session, since the SDK documents no WebSocket instrumentation.
  • Counts are handed to the SDK as they happen, including while the network is down. The app does no buffering of its own, and the SDK's default limit on unsent data is kept. Accepted consequence: in a long outage the oldest unsent reports can be dropped.
  • No log lines in step one. The counts carry the member and the time, and the destination can filter them by member (see Further notes), so the fallback of one log line per outage is not needed.
  • Breadcrumbs come from a fixed list: networking events and screen names, written by the app, and the app moving to the foreground or background, written by the SDK. A screen name comes from the app's own list of screens (such as the channel list, a channel, a thread or settings), with any other page called "other". A screen whose name alone would say something about the person, such as the age restriction, is also called "other". It is never a channel or community name, an ID, a route's settings or anything a screen shows, so a report shows which screens the person was on and not what they were looking at. A breadcrumb is left when the person moves to a page or back to one, unless it names the same screen as the one before. Dialogs, sheets and menus leave none. The SDK's other automatic breadcrumbs, which could carry content or addresses, are turned off or filtered. Leaving a member (switching or signing out) clears the trail, so one member's networking events never reach another member's reports.
  • Who a report is about. The member's public key is set as the report's user when a session starts and cleared when it ends. When the session is a Builderlab account, the Builderlab's origin and the account's subject identifier are added, never its email address. Every report also carries the app's own random per-install identifier, created on first launch and kept in a file that device backups and transfers skip, so a phone restored from another gets its own, as a separate field, signed in or not, so reports from one device can be matched to the members who used it, and a member's reports to the devices they used. With no member set, for example before sign-in, the SDK fills the report's user with its own random per-install identifier, on Dart and native reports alike. On iOS, native crash and hang reports also carry the SDK's device app hash: a hash of the identifier iOS gives the app's vendor, the hardware model and the bundle identifier, stable across launches and across a reinstall while another app from the same vendor stays installed. The Dart filter drops it, so Dart reports don't carry it. The SDK also sends session records, so the destination can show a crash-free rate. A session begins each time the app starts or returns after 30 seconds or more in the background. The SDK sends a record when it begins, an update each time an error is counted, and a last record when it ends. Together they carry when the session started, how many errors it had, how it ended (normally, crashed or abnormally), the time from start to end (not time in active use), the release, the environment and the SDK's identifier.
  • One filter before anything leaves. Errors, breadcrumbs and counts from Dart all pass through a single filter that removes URL query strings and fragments, drops any attribute not on the allowed list, replaces every error's own text with fixed wording, drops what the SDK adds about the failing widget or platform call, and keeps only the app, operating system, device and runtime details among the report's contexts, so the SDK's accessibility settings, locale and the device's own name stay on the device. An error keeps its type and stack trace. The SDK's options for sending personal data, screenshots, view hierarchies and session recordings stay off.
  • Main-thread hangs are captured by the SDK's own hang detection, at the SDK's default thresholds. The app's Dart code runs on the platform's main thread, so Dart work that blocks it shows up here. On iOS, the SDK reports the main thread being blocked, fully or mostly, for 2 seconds or more while the app is active, with the main thread's stack taken during the hang, including freezes the app recovers from. A hang that is still going when the app is killed, for example by the system watchdog, is sent on the next launch as a fatal hang. The SDK's separate watchdog-termination tracking also reports, on the next launch, a run that ended while the app was in the foreground with nothing else to explain it; it never reports on simulators or for kills in the background. App hang detection is off while a debugger is attached (sentry-cocoa 9.35.0). On Android the SDK reports only freezes the system itself declared "app not responding". On Android 11 and later it reports only one that ended the process, read from the system's exit records on the next launch: the most recent unreported one, and only when the system kept a usable thread dump. Before Android 11 it reports when the main thread has been blocked for 5 seconds and the system has marked the app not responding, never with a debugger attached (sentry-java 8.64.0). So with these defaults, a freeze the app recovers from is reported on iOS, and on Android only before Android 11 and only once the system has marked the app not responding. Dart frames in a hang's stack are readable only with the Dart code's debug symbols at the destination, the same as for crashes.
  • Native reports skip that filter. Native crashes and app hangs are captured and sent by the native SDKs, which never call the Dart filter. They carry stack traces and, for a native exception, its reason text. No app code puts content in a native exception today, and the SDK's native network breadcrumbs, which would carry request addresses, are off.
  • Readable stack traces need the build's debug symbols at the destination. Uploading them belongs to the release process of whoever distributes the build; this repository documents the requirement and adds nothing organization-specific.
  • A way to check a build. A build that reports shows a Diagnostics card in Settings with two actions: send a test report (a fixed test error with its own operation, through the same filter as every report) and a test crash in native code, behind a confirmation. A build without a destination never shows it. Whoever distributes a reporting build can then confirm, before relying on it, that reports arrive with readable stack traces.
  • Both platforms. Step one covers the main app on iOS and Android. Background work that runs the app's Dart code in its own engine, as decided for Android push handling in ADR 0006, starts the reporting module the same way once it exists. Dart errors are captured in the main app's Flutter engine only: the iOS sheets that start their own engine (channel settings and the profile photo editor) are not covered, though native crashes while they are open still are.
  • Reporting never blocks the app. A call into the reporting module returns at once and nothing waits on the destination. A failure inside reporting is dropped and never reaches the code that made the call.

Testing decisions

  • A good test here asserts what would be reported for something the user or the network does, never how the reporting module is called internally.
  • Tests replace the reporting interface with a fake that records what it was given. This is the only new seam.
  • Journey tests extend the existing relay and account journeys with steps such as: a malformed relay frame produces exactly one error report; a timeout or disconnect is counted with the right backend, endpoint and failure kind and produces no report; signing out changes who later reports are about.
  • One table-driven test covers the filter: each row is an input (a URL with a query string, an attribute not on the list, a free-text relay message) and what must come out.
  • One test checks that a build with no reporting destination never starts the SDK.
  • One test checks that a reporting call that fails does not fail or delay the operation that made it.
  • The SDK itself is not tested. Prior art: the existing widget tests that override boundary providers for the relay, HTTP and storage.

Out of scope

  • The iOS notification service extension and the iOS share extension.
  • Log lines, traces and spans, and joining mobile reports to relay traces.
  • Holding counts back in the app while the network is down. The SDK's own store of unsent data is the only buffer.
  • Requests that bypass the shared HTTP client, such as those made by native media players and image loaders.
  • Alert rules, dashboards and the destination's own configuration, which belong to whoever owns the destination.
  • Diagnostic reporting in a public build. Nothing prevents it, but what a report carries was chosen for internal builds. Turning it on there first needs the member's public key and the server host names removed, the rest of the list reviewed, and a way to tell people (ADR 0007). Because identity and every attribute pass through one module, that is a small code change.
  • Usage or behavior data of any kind, beyond the SDK's session records described above and the trail of screens in a report.
  • Fixing the bugs the reports will reveal, including one found while planning: a catch-all in account requests presents every error as an outage.

Further notes

  • Depends on the iOS move to Swift Package Manager, since the current Sentry SDK installs on iOS only that way (ADR 0008).
  • Verified on 2026-11-20 by sending test counts for two members to the destination: it filters and groups by user.id, endpoint and failure kind, and its samples show the member and the time, so the log-line fallback is not needed. Not yet verified: how Android's store of unsent data behaves.
  • A relay's host name can identify a community. It is reported anyway so that two relays can be told apart; an internal build talks only to its own organization's relay, so the name tells the destination's owner nothing new. Other hosts the app reaches, such as those of remote images in messages, are counted as external and never named.