π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Re-enable background Sentry behind fail-open init timeout
laurenspriem9d2eae2130e0
diff --git a/mobile/apps/photos/lib/core/error-reporting/super_logging.dart b/mobile/apps/photos/lib/core/error-reporting/super_logging.dartindex de1d8510ef..4977c5c18c 100644--- a/mobile/apps/photos/lib/core/error-reporting/super_logging.dart+++ b/mobile/apps/photos/lib/core/error-reporting/super_logging.dart@@ -88,6 +88,8 @@ class LogConfig {String? tunnel;+ Duration? sentryInitTimeout;+Duration sentryRetryDelay;// Null disables file logging; empty uses the default directory.@@ -106,6 +108,7 @@ class LogConfig {LogConfig({this.sentryDsn,this.tunnel,+ this.sentryInitTimeout,this.sentryRetryDelay = const Duration(seconds: 30),this.logDirPath,this.maxLogFiles = 10,@@ -206,30 +209,31 @@ class SuperLogging {if (appConfig.body == null) return;if (enable && sentryIsEnabled) {- await SentryFlutter.init(- (options) {- options.dsn = appConfig!.sentryDsn;- options.anrEnabled = true;- options.anrTimeoutInterval = const Duration(seconds: 5);- options.httpClient = http.Client();- if (appConfig.tunnel != null) {- options.transport = TunneledTransport(- Uri.parse(appConfig.tunnel!),- options,- );- }- options.beforeSend = (SentryEvent event, Hint hint) async {- final dynamic error = event.throwable;- if (error != null && _shouldSkipSentry(error)) {- return null;- }- return event;- };- },- appRunner: () => kDebugMode- ? _runWithUnhandledErrorLogging(appConfig!.body!)- : appConfig!.body!(),- );+ final sentryInitTimeout = appConfig.sentryInitTimeout;+ if (sentryInitTimeout == null) {+ await SentryFlutter.init(+ _configureSentryOptions,+ appRunner: () => kDebugMode+ ? _runWithUnhandledErrorLogging(appConfig!.body!)+ : appConfig!.body!(),+ );+ } else {+ try {+ await SentryFlutter.init(+ _configureSentryOptions,+ ).timeout(sentryInitTimeout);+ } catch (e) {+ sentryIsEnabled = false;+ $.warning(+ "Sentry init did not complete, running body without it: $e",+ );+ }+ if (kDebugMode) {+ await _runWithUnhandledErrorLogging(appConfig.body!);+ } else {+ await appConfig.body!();+ }+ }} else {if (kDebugMode) {// Keep debug-only until we're sure this doesn't cause regressions.@@ -240,6 +244,24 @@ class SuperLogging {}}+ static void _configureSentryOptions(SentryFlutterOptions options) {+ options.dsn = config.sentryDsn;+ options.anrEnabled = true;+ options.anrTimeoutInterval = const Duration(seconds: 5);+ options.httpClient = http.Client();+ final tunnel = config.tunnel;+ if (tunnel != null) {+ options.transport = TunneledTransport(Uri.parse(tunnel), options);+ }+ options.beforeSend = (SentryEvent event, Hint hint) async {+ final dynamic error = event.throwable;+ if (error != null && _shouldSkipSentry(error)) {+ return null;+ }+ return event;+ };+ }+static Future<void> _runWithUnhandledErrorLogging(FutureOrVoidCallback body,) async {diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dartindex 323065f1fe..4aef6ed774 100644--- a/mobile/apps/photos/lib/main.dart+++ b/mobile/apps/photos/lib/main.dart@@ -644,17 +644,16 @@ Future<void> _sync(String caller) async {Future runWithLogs(Function() function, {String prefix = "",- bool enableSentry = true,+ Duration? sentryInitTimeout,}) async {await SuperLogging.main(LogConfig(body: function,logDirPath: (await getApplicationSupportDirectory()).path + "/logs",maxLogFiles: 5,- sentryDsn: enableSentry- ? (kDebugMode ? sentryDebugDSN : sentryDSN)- : null,- tunnel: enableSentry ? sentryTunnel : null,+ sentryDsn: kDebugMode ? sentryDebugDSN : sentryDSN,+ tunnel: sentryTunnel,+ sentryInitTimeout: sentryInitTimeout,enableInDebugMode: true,prefix: prefix,),diff --git a/mobile/apps/photos/lib/utils/bg_task_utils.dart b/mobile/apps/photos/lib/utils/bg_task_utils.dartindex 026133c443..09db1d83a2 100644--- a/mobile/apps/photos/lib/utils/bg_task_utils.dart+++ b/mobile/apps/photos/lib/utils/bg_task_utils.dart@@ -42,7 +42,7 @@ void callbackDispatcher() {}},prefix: "[bg]",- enableSentry: !Platform.isAndroid,+ sentryInitTimeout: const Duration(seconds: 5),).onError((_, _) {failure = "Didn't finished correctly!";return;