diff --git a/docs/adr/0007-diagnostic-reporting-follows-the-destination.md b/docs/adr/0007-diagnostic-reporting-follows-the-destination.md index 518869486f..4227cf3fee 100644 --- a/docs/adr/0007-diagnostic-reporting-follows-the-destination.md +++ b/docs/adr/0007-diagnostic-reporting-follows-the-destination.md @@ -4,7 +4,7 @@ A mobile build does [diagnostic reporting](../../CONTEXT.md#diagnostic-reporting 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, the first line of a Dart programmer error's message (a `StateError`, `TypeError`, `AssertionError` or `UnsupportedError`, whose text developers write) with object identity hashes removed, when it has no URL and no `?` or `#` followed by anything but closing punctuation, 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, a random identifier the app creates for its installation, a random identifier the reporting SDK creates for the installation (which stands in as the user on reports sent while no one is signed in, and appears in the SDK's session records, which also carry when a session started, its length from start to end, how it ended and its error count), on iOS native crash and hang reports only, a hash the SDK computes from the identifier iOS gives the app's vendor, the hardware model and the app's bundle identifier (it stays the same across launches, and across a reinstall while another app from the same vendor stays installed) 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. +A report may carry the stack trace and error type, the first line of a Dart programmer error's message (a `StateError`, `TypeError`, `AssertionError` or `UnsupportedError`, whose text developers write) with object identity hashes removed, when it has no URL and no `?` or `#` followed by anything but closing punctuation, 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, a random identifier the app creates for its installation, a random identifier the reporting SDK creates for the installation (which stands in as the user on reports sent while no one is signed in, and appears in the SDK's session records, which also carry when a session started, its length from start to end, how it ended and its error count), on iOS native crash and hang reports only, a hash the SDK computes from the identifier iOS gives the app's vendor, the hardware model and the app's bundle identifier (it stays the same across launches, and across a reinstall while another app from the same vendor stays installed) 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, apart from closing punctuation at the end of a word in a kept programmer-error line, where a `?` or `#` followed only by closing punctuation is read as prose (as in `String?`). ## Considered options diff --git a/mobile/lib/shared/diagnostics/diagnostic_filter.dart b/mobile/lib/shared/diagnostics/diagnostic_filter.dart index 01ce045ad1..40ed4b2f2b 100644 --- a/mobile/lib/shared/diagnostics/diagnostic_filter.dart +++ b/mobile/lib/shared/diagnostics/diagnostic_filter.dart @@ -146,11 +146,11 @@ abstract final class DiagnosticFilter { /// line, or the lines after the first, usually quote other text, such as a /// response body or a wrapped error. static String _keptText(String text) { - final lineEnd = text.indexOf(_lineBreak); - final line = (lineEnd < 0 ? text : text.substring(0, lineEnd)).replaceAll( - _identityHash, - '', - ); + final lineEnd = _lineBreak.firstMatch(text)?.start ?? text.length; + // Replaced without scanning: only a line made mostly of identity hashes + // could come under the limit after their removal. + if (lineEnd > 2 * _keptTextLimit) return removedText; + final line = text.substring(0, lineEnd).replaceAll(_identityHash, ''); return line.length > _keptTextLimit || line.contains(_mayHoldUrl) ? removedText : line; diff --git a/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart b/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart index 91eb77d582..9604194ed7 100644 --- a/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart +++ b/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart @@ -325,6 +325,7 @@ void main() { 'The provider FutureProvider#1a2b3(private-marker) was disposed', ), ('a long line', 'state ${'x' * 200} private-marker'), + ('a very long line', 'state ${'x' * 500} private-marker'), ]; for (final (name, text) in replaced) { test('replaces kept text that has $name', () async {