mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
feat(mobile): add a diagnostics test report and test crash to Settings
Shown only in builds with a reporting destination, so whoever distributes a reporting build can confirm that reports and native crashes arrive with readable stack traces. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -52,6 +52,7 @@ A build that is given a [reporting destination](../CONTEXT.md#reporting-destinat
|
||||
- **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](https://github.com/getsentry/sentry-cocoa/blob/9.35.0/Sources/Swift/Integrations/AppHangTracking/SentryHangTrackingIntegration.swift)). 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](https://github.com/getsentry/sentry-java/blob/8.64.0/sentry-android-core/src/main/java/io/sentry/android/core/AnrIntegrationFactory.java)). 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](adr/0006-android-notifications-run-app-dart-code.md), 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.
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../shared/auth/auth.dart';
|
||||
import '../../shared/identity_transfer/nsec_export_sheet.dart';
|
||||
import '../../shared/clipboard_utils.dart';
|
||||
import '../../shared/diagnostics/diagnostic_reporter.dart';
|
||||
import '../../shared/widgets/confirmation_dialog.dart';
|
||||
import '../../shared/hosted/hosted_environment.dart';
|
||||
import '../../shared/hosted/sign_out.dart';
|
||||
import '../../shared/push/push_relay_capability_provider.dart';
|
||||
@@ -40,6 +42,7 @@ part 'settings_page/status_section.dart';
|
||||
part 'settings_page/connection_section.dart';
|
||||
part 'settings_page/notifications_section.dart';
|
||||
part 'settings_page/builderlab_account_section.dart';
|
||||
part 'settings_page/diagnostics_section.dart';
|
||||
|
||||
Widget _emptyProfileEditPage(BuildContext context) => const SizedBox.shrink();
|
||||
|
||||
@@ -245,6 +248,8 @@ class SettingsPage extends HookConsumerWidget {
|
||||
],
|
||||
if (!wide && HostedEnvironment.enabled)
|
||||
const _BuilderlabAccountSection(),
|
||||
if (ref.watch(diagnosticReporterProvider).reporting)
|
||||
const _DiagnosticsSection(),
|
||||
// Rarely needed, so it sits last.
|
||||
AppListCard(
|
||||
verticalPadding: Grid.twelve,
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
part of '../settings_page.dart';
|
||||
|
||||
/// Checks that a build's diagnostic reporting works end to end. Shown only
|
||||
/// in builds with a reporting destination, the internal dogfood builds.
|
||||
class _DiagnosticsSection extends ConsumerWidget {
|
||||
const _DiagnosticsSection();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final reporter = ref.watch(diagnosticReporterProvider);
|
||||
return AppListCard(
|
||||
verticalPadding: Grid.twelve,
|
||||
children: [
|
||||
AppListRow(
|
||||
key: const Key('settings-send-test-report'),
|
||||
title: 'Send test report',
|
||||
onTap: () {
|
||||
reporter.sendTestReport();
|
||||
ScaffoldMessenger.of(context).showFeedbackSnackBar(
|
||||
const SnackBar(content: Text('Test report sent.')),
|
||||
kind: ToastKind.success,
|
||||
);
|
||||
},
|
||||
),
|
||||
AppListRow(
|
||||
key: const Key('settings-test-crash'),
|
||||
title: 'Test crash',
|
||||
titleColor: context.colors.error,
|
||||
onTap: () async {
|
||||
final confirmed = await showDestructiveConfirmation(
|
||||
context: context,
|
||||
title: 'Crash Buzz?',
|
||||
message:
|
||||
'Buzz closes at once. The crash report is sent the next '
|
||||
'time you open it.',
|
||||
confirmLabel: 'Crash',
|
||||
);
|
||||
if (confirmed) reporter.crashForTest();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,24 @@ abstract interface class DiagnosticReporter {
|
||||
|
||||
/// Attributes later reports and counts to [pubkey], or to no one.
|
||||
void setMember(String? pubkey);
|
||||
|
||||
/// Whether this build has a reporting destination. Only then does Settings
|
||||
/// offer the checks below.
|
||||
bool get reporting;
|
||||
|
||||
/// Sends a [DiagnosticTestError], to check a build's reporting end to end.
|
||||
void sendTestReport();
|
||||
|
||||
/// Crashes the app in native code, to check native crash reports.
|
||||
void crashForTest();
|
||||
}
|
||||
|
||||
/// The error a test report carries, so it is easy to tell apart.
|
||||
class DiagnosticTestError implements Exception {
|
||||
const DiagnosticTestError();
|
||||
|
||||
@override
|
||||
String toString() => 'DiagnosticTestError';
|
||||
}
|
||||
|
||||
/// Where an explicit error report comes from.
|
||||
@@ -33,6 +51,7 @@ enum DiagnosticOperation {
|
||||
pushGatewayResponse,
|
||||
storedData,
|
||||
eventSubscriber,
|
||||
testReport,
|
||||
}
|
||||
|
||||
/// The operation a networking event belongs to.
|
||||
@@ -99,6 +118,15 @@ class NoopDiagnosticReporter implements DiagnosticReporter {
|
||||
|
||||
@override
|
||||
void setMember(String? pubkey) {}
|
||||
|
||||
@override
|
||||
bool get reporting => false;
|
||||
|
||||
@override
|
||||
void sendTestReport() {}
|
||||
|
||||
@override
|
||||
void crashForTest() {}
|
||||
}
|
||||
|
||||
/// The reporter chosen at startup. The root scope overrides it; tests
|
||||
|
||||
@@ -73,6 +73,19 @@ class SentryDiagnosticReporter implements DiagnosticReporter {
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
bool get reporting => true;
|
||||
|
||||
@override
|
||||
void sendTestReport() => reportError(
|
||||
const DiagnosticTestError(),
|
||||
StackTrace.current,
|
||||
operation: DiagnosticOperation.testReport,
|
||||
);
|
||||
|
||||
@override
|
||||
void crashForTest() => _drop(SentryFlutter.nativeCrash);
|
||||
|
||||
static Map<String, SentryAttribute> _attributes(NetworkEvent event) => {
|
||||
'backend': SentryAttribute.string(event.backend),
|
||||
'endpoint': SentryAttribute.string(event.endpoint.name),
|
||||
|
||||
101
mobile/test/features/settings/settings_diagnostics_test.dart
Normal file
101
mobile/test/features/settings/settings_diagnostics_test.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'package:buzz/features/settings/settings_page.dart';
|
||||
import 'package:buzz/shared/community/community_membership_provider.dart';
|
||||
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
|
||||
import 'package:buzz/shared/theme/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> pumpSettings(
|
||||
WidgetTester tester,
|
||||
DiagnosticReporter reporter,
|
||||
) async {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.physicalSize = const Size(390, 1400);
|
||||
addTearDown(tester.view.reset);
|
||||
PackageInfo.setMockInitialValues(
|
||||
appName: 'Buzz',
|
||||
packageName: 'xyz.block.buzz',
|
||||
version: '0.16.0',
|
||||
buildNumber: '432',
|
||||
buildSignature: '',
|
||||
);
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
savedPrefsProvider.overrideWithValue(prefs),
|
||||
currentCommunityRoleProvider.overrideWithValue(
|
||||
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.member),
|
||||
),
|
||||
diagnosticReporterProvider.overrideWithValue(reporter),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: AppTheme.light(),
|
||||
home: SettingsPage(
|
||||
profileHeader: const SizedBox.shrink(),
|
||||
identityRecoveryPageBuilder: (_) => const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
final sendRow = find.byKey(const Key('settings-send-test-report'));
|
||||
final crashRow = find.byKey(const Key('settings-test-crash'));
|
||||
|
||||
testWidgets('a build without reporting offers no checks', (tester) async {
|
||||
await pumpSettings(tester, const NoopDiagnosticReporter());
|
||||
|
||||
expect(sendRow, findsNothing);
|
||||
expect(crashRow, findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a reporting build sends a test report', (tester) async {
|
||||
final reporter = _RecordingReporter();
|
||||
await pumpSettings(tester, reporter);
|
||||
|
||||
await tester.ensureVisible(sendRow);
|
||||
await tester.tap(sendRow);
|
||||
await tester.pump();
|
||||
|
||||
expect(reporter.calls, ['sendTestReport']);
|
||||
expect(find.text('Test report sent.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a test crash happens only once confirmed', (tester) async {
|
||||
final reporter = _RecordingReporter();
|
||||
await pumpSettings(tester, reporter);
|
||||
|
||||
await tester.ensureVisible(crashRow);
|
||||
await tester.tap(crashRow);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(reporter.calls, isEmpty);
|
||||
|
||||
await tester.tap(crashRow);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Crash'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(reporter.calls, ['crashForTest']);
|
||||
});
|
||||
}
|
||||
|
||||
class _RecordingReporter extends NoopDiagnosticReporter {
|
||||
final calls = <String>[];
|
||||
|
||||
@override
|
||||
bool get reporting => true;
|
||||
|
||||
@override
|
||||
void sendTestReport() => calls.add('sendTestReport');
|
||||
|
||||
@override
|
||||
void crashForTest() => calls.add('crashForTest');
|
||||
}
|
||||
@@ -206,6 +206,17 @@ void main() {
|
||||
expect(transport.events.single['user']['id'], 'a' * 64);
|
||||
});
|
||||
|
||||
test('a test report is a test error from the test operation', () async {
|
||||
SentryDiagnosticReporter(hub: hub).sendTestReport();
|
||||
await transport.first();
|
||||
|
||||
final sent = transport.events.single;
|
||||
final exception = (sent['exception']['values'] as List).last as Map;
|
||||
expect(exception['type'], 'DiagnosticTestError');
|
||||
expect(exception['stacktrace'], isNotNull);
|
||||
expect(sent['tags']['operation'], 'testReport');
|
||||
});
|
||||
|
||||
testWidgets('sends only the allowed contexts', (tester) async {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(accessibleNavigation: true);
|
||||
|
||||
Reference in New Issue
Block a user