Name the connected server in the sync diagnostics

This commit is contained in:
Roland Geider
2026-08-29 14:51:27 +02:00
parent 5a8e43dec3
commit f55624090a
3 changed files with 17 additions and 7 deletions

View File

@@ -28,7 +28,6 @@ import 'package:wger/core/logs.dart';
import 'package:wger/core/misc.dart';
import 'package:wger/core/network/auth_notifier.dart';
import 'package:wger/core/network/network_provider.dart';
import 'package:wger/core/network/wger_base.dart';
import 'package:wger/core/wide_screen_wrapper.dart';
import 'package:wger/features/exercises/screens/add_exercise_screen.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
@@ -128,9 +127,7 @@ class AboutPage extends ConsumerWidget {
onTap: () async {
final url = buildGithubIssueUrl(
applicationLogs: InMemoryLogStore().getFormattedLogs(),
syncDiagnostics: await collectSyncDiagnostics(
serverUrl: ref.read(wgerBaseProvider).serverUrl,
),
syncDiagnostics: await collectSyncDiagnostics(),
appVersion: await collectAppVersion(),
serverVersion: authState?.serverVersion,
);

View File

@@ -65,6 +65,15 @@ PowerSyncDatabase? _builtInstance;
/// those paths need.
PowerSyncDatabase? get builtPowerSyncInstance => _builtInstance;
String? _connectedServerUrl;
/// The server the sync was last connected to, null before the first connect.
///
/// What the sync diagnostics name as the backend: a report has to say where
/// the rejected uploads went, and it is written from paths that have no `ref`
/// to read the auth state with.
String? get connectedServerUrl => _connectedServerUrl;
/// Watches the sync status for a stream that keeps reconnecting without ever
/// delivering data (e.g. blocked by a VPN or firewall) and flags it, see
/// [SyncStreamWatchdog]. Fed from the DB's status stream by
@@ -251,6 +260,7 @@ void connectPowerSync(
required String reason,
}) {
_logger.info('Connecting to the sync service ($reason)');
_connectedServerUrl = baseUrl;
db.connect(
connector: DjangoConnector(
baseUrl: baseUrl,

View File

@@ -21,7 +21,8 @@ import 'package:logging/logging.dart';
import 'package:powersync/powersync.dart'
show CredentialsException, PowerSyncProtocolException, SyncResponseException, SyncStatus;
import 'package:wger/core/consts.dart';
import 'package:wger/database/powersync/powersync.dart' show builtPowerSyncInstance;
import 'package:wger/database/powersync/powersync.dart'
show builtPowerSyncInstance, connectedServerUrl;
import 'package:wger/powersync/connector.dart'
show NoPowerSyncEndpointException, RetryableUploadException;
@@ -208,7 +209,7 @@ Future<LocalSyncState?> collectLocalSyncState() async {
/// Never throws: this runs on report paths where the app may already be in
/// a broken state (e.g. the DB is closing down), and a missing sync section
/// must not prevent the report itself.
Future<String?> collectSyncDiagnostics({String? serverUrl}) async {
Future<String?> collectSyncDiagnostics() async {
final db = builtPowerSyncInstance;
if (db == null) {
return null;
@@ -218,7 +219,9 @@ Future<String?> collectSyncDiagnostics({String? serverUrl}) async {
return formatSyncDiagnostics(
db.currentStatus,
pendingUploads: queue.count,
server: serverCategory(serverUrl),
// The server this sync actually runs against, rather than one the
// caller happens to know: the counters below describe that connection
server: serverCategory(connectedServerUrl),
local: await collectLocalSyncState(),
);
} catch (e, s) {