docs: define mobile diagnostic reporting (#9600)

## Summary

Records the vocabulary, the two hard-to-reverse decisions and the spec
for diagnostic reporting in the mobile app, before any code is written.
Nothing here changes behavior.

- `CONTEXT.md`: two new terms. **Diagnostic reporting** is sending
crash, error and performance data from a mobile installation to a
reporting destination. A **reporting destination** is where a build
sends it, chosen at build time by whoever distributes the build.
- [ADR
0007](https://github.com/block/buzz/blob/tomb/mobile-diagnostic-reporting-docs/docs/adr/0007-diagnostic-reporting-follows-the-destination.md):
a build reports if, and only if, it was given a reporting destination,
whatever kind of build it is. It also lists what a report may and may
never carry.
- [ADR
0008](https://github.com/block/buzz/blob/tomb/mobile-diagnostic-reporting-docs/docs/adr/0008-sentry-for-mobile-diagnostic-reporting.md):
the app reports through the Sentry Flutter SDK, with the comparison
against Datadog and Bugsnag.
-
[`docs/mobile-diagnostic-reporting.md`](https://github.com/block/buzz/blob/tomb/mobile-diagnostic-reporting-docs/docs/mobile-diagnostic-reporting.md):
the spec for step one. It covers crashes, uncaught errors, error reports
for unexpected protocol and decoding failures, and networking
measurements by backend and endpoint, all through one reporting module.
It sits beside the existing mobile push suppression spec.

The term avoids "telemetry" because the repository already uses that
word for agent session streams and relay rollout signals.

### Related issue

N/A. The Swift Package Manager move that ADR 0008 depends on is #9597.

### Regressions

Documentation only. No code, configuration or build changes.

### Validation

Checked that every link in the four files resolves within the branch,
and that the new glossary anchors match the links that point to them.

---------

Signed-off-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: judge <7615ec4b7ddf99f0bb48e913297f99f8f772d289a1c9ef54e1d906dd55a93ba8@buzz.block.builderlab.xyz>
This commit is contained in:
Tom Brow
2026-11-17 09:40:06 -08:00
committed by GitHub
parent 148585c804
commit 026b203c64
4 changed files with 135 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
# Buzz domain language
Shared terminology for Buzz product behavior. This glossary currently covers mobile [push suppression](#push-suppression), the [notification body](#notification-body), [mobile builds](#mobile-builds), [sharing](#sharing), [quick send](#quick-send) and the [open-channel directory](#open-channel-directory); it is not a complete model of Buzz.
Shared terminology for Buzz product behavior. This glossary currently covers mobile [push suppression](#push-suppression), the [notification body](#notification-body), [mobile builds](#mobile-builds), [diagnostic reporting](#diagnostic-reporting), [sharing](#sharing), [quick send](#quick-send) and the [open-channel directory](#open-channel-directory); it is not a complete model of Buzz.
## Notifications
@@ -82,6 +82,18 @@ The mobile app distributed through the App Store and TestFlight. It uses only th
_Avoid_: App Store build, external build
### Diagnostic reporting
Sending crash, error and performance data from a mobile installation to a [reporting destination](#reporting-destination). It exists to diagnose faults: it is not a record of how people use the app, and it never includes what they write. See [ADR 0007](docs/adr/0007-diagnostic-reporting-follows-the-destination.md).
_Avoid_: Telemetry, analytics, tracking, observability
### Reporting destination
Where a mobile build's [diagnostic reporting](#diagnostic-reporting) is sent, chosen at build time by whoever distributes the build. A build with no reporting destination reports nothing.
_Avoid_: DSN, Sentry project
## Sharing
### Share

View File

@@ -0,0 +1,26 @@
# Diagnostic reporting follows the reporting destination
A mobile build does [diagnostic reporting](../../CONTEXT.md#diagnostic-reporting) if, and only if, it was built with a [reporting destination](../../CONTEXT.md#reporting-destination). The kind of build does not matter: an [internal build](../../CONTEXT.md#internal-build), a [public build](../../CONTEXT.md#public-build) or a development build reports when given a destination and is silent without one. This repository supplies none, so builds made from it alone report nothing. The app has no setting to turn reporting off and does not tell the person that it reports.
We chose this so that the open-source app carries no organization's destination and no rule about which organizations may collect reports, the same reasoning that keeps organization hosts out of the code in [ADR 0001](0001-internal-and-public-mobile-builds.md). The first use is an organization's internal build, where everyone who has the app is a member of the organization that reads the reports.
A report may carry the stack trace and error type, app, operating system and device details, a trail of recent events written from a fixed list, the host names of the servers the app talks to, the signed-in member's public key and, when the person is signed in to a Builderlab account, that Builderlab's origin and the account's subject identifier, never its email address. Networking measurements also carry the operation's name from a fixed list, its outcome, the kind of failure and how long it took. A report never carries message content, channel or community names, private keys or other secrets, or a URL's query string or fragment.
## Considered options
- **Tie reporting to the internal build.** Rejected because the kind of build would then carry a second meaning, and a public or development build could never be diagnosed the same way.
- **Refuse to start a public build that has a reporting destination.** This would have guaranteed that people outside the distributing organization are never reported on. Rejected in favor of one rule with no exceptions; whoever supplies the destination decides where the build goes.
- **A random identifier per installation in place of the public key.** Rejected because the reports exist so that someone can follow up with the person who hit the fault.
- **A switch or a notice in Settings.** Rejected for the first use, where the people reported on are the organization's own members.
## Consequences
Because the app says nothing about reporting, any notice or consent owed to the people who receive a build is the responsibility of whoever gives that build a reporting destination. Giving a destination to a build that reaches the general public would report on those people without telling them.
What a report may carry was chosen for an internal build. Before a public build is given a reporting destination, that list has to be revisited: at the least the member's public key and the server host names would come out, and the people using the build would need to be told. Nothing in the app enforces this.
A build without a reporting destination must not start the reporting code at all, since a reporting library given an empty destination can still install its hooks.
A relay's host name can identify a community even though the community's name is never sent. We accepted this so that a failing relay can be told apart from a healthy one; an internal build talks only to its own organization's relay.
The public key ties a report to a member. Anyone with access to the reporting destination can therefore see which member hit which fault and when.

View File

@@ -0,0 +1,16 @@
# Sentry for mobile diagnostic reporting
The mobile app sends its [diagnostic reporting](../../CONTEXT.md#diagnostic-reporting) with the Sentry Flutter SDK, so a [reporting destination](../../CONTEXT.md#reporting-destination) is a Sentry project. We chose Sentry because, of the Flutter SDKs compared in November 2026, it was the only one with crashes (Dart and native), non-fatal errors, logs and custom metrics in a single SDK, and it had by far the most frequent releases.
## Considered options
- **Datadog.** The relay exports OpenTelemetry traces and Prometheus metrics, which a deployment can collect in Datadog, so client and server data could sit together there. Its Flutter SDK documents no custom metrics from the client, and its native crash reporting is off by default.
- **Bugsnag.** Comparable crash and error coverage, but no logs, no custom metrics, and three releases of its Flutter SDK in the year before the comparison.
## Consequences
The current Sentry Flutter SDK installs on iOS only through Swift Package Manager, so the iOS app's plugins move to Swift Package Manager first.
None of the three SDKs documents any WebSocket instrumentation. Everything reported about relay connections is written by hand in the app, whichever vendor is used.
Mobile reports are not joined to the relay's traces. Correlating a mobile fault with relay behavior is done by time and member until a link between the two is built.

View File

@@ -0,0 +1,80 @@
# Mobile diagnostic reporting
Status: step one agreed, not yet implemented.
Terminology is defined in [CONTEXT.md](../CONTEXT.md#mobile-builds). The decisions behind this spec are in [ADR 0007](adr/0007-diagnostic-reporting-follows-the-destination.md) and [ADR 0008](adr/0008-sentry-for-mobile-diagnostic-reporting.md).
## 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](../CONTEXT.md#reporting-destination) does [diagnostic reporting](../CONTEXT.md#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, so that I can see what the connection was doing 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](../CONTEXT.md#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.
## 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](adr/0007-diagnostic-reporting-follows-the-destination.md)).
- **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 or a channel name that is taken, which is counted), 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. Endpoints are names from a fixed list, never raw paths. Durations are recorded for requests and for time to connect. 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. The first implementation task confirms that the destination can filter counts by member; if it cannot, the fallback is one log line per outage, sent after it ends.
- **Breadcrumbs come from a fixed list** written by the app: networking events and the app moving to the foreground or background. The SDK's automatic breadcrumbs that could carry content or addresses are turned off or filtered.
- **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.
- **One filter before anything leaves.** Errors, breadcrumbs and counts all pass through a single filter that removes URL query strings and fragments, drops any attribute not on the allowed list, and replaces free-text failure messages with fixed wording. The SDK's options for sending personal data, screenshots, view hierarchies and session recordings stay 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.
- **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](adr/0006-android-notifications-run-app-dart-code.md), starts the reporting module the same way once it exists.
- **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](../CONTEXT.md#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](adr/0007-diagnostic-reporting-follows-the-destination.md)). Because identity and every attribute pass through one module, that is a small code change.
- Usage or behavior data of any kind.
- Fixing the bugs the reports will reveal, including two found while planning: one subscriber that throws can lose the rest of a batch of events, and 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](adr/0008-sentry-for-mobile-diagnostic-reporting.md)).
- Not yet verified: whether the destination can filter counts by member, and 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.