diff --git a/flutter/lib/src/navigation/sentry_navigator_observer.dart b/flutter/lib/src/navigation/sentry_navigator_observer.dart index 168254f231..454974d11e 100644 --- a/flutter/lib/src/navigation/sentry_navigator_observer.dart +++ b/flutter/lib/src/navigation/sentry_navigator_observer.dart @@ -159,12 +159,14 @@ class SentryNavigatorObserver extends RouteObserver> { // Clearing the display tracker here is safe since didPush happens before the Widget is built _timeToDisplayTracker?.clear(); - _finishAndStartTTIDTracking(route); + + DateTime timestamp = _hub.options.clock(); + _finishAndStartTTIDTracking(route, timestamp); } - Future _finishAndStartTTIDTracking(Route? route) async { - await _finishTimeToDisplayTracking(); - await _startTimeToDisplayTracking(route); + Future _finishAndStartTTIDTracking(Route? route, DateTime timestamp) async { + await _finishTimeToDisplayTracking(endTimestamp: timestamp); + await _startTimeToDisplayTracking(route, timestamp); } @override @@ -204,7 +206,8 @@ class SentryNavigatorObserver extends RouteObserver> { to: previousRoute?.settings, ); - _finishTimeToDisplayTracking(clearAfter: true); + final timestamp = _hub.options.clock(); + _finishTimeToDisplayTracking(endTimestamp: timestamp, clearAfter: true); } void _addBreadcrumb({ @@ -299,7 +302,7 @@ class SentryNavigatorObserver extends RouteObserver> { await _native?.beginNativeFrames(); } - Future _finishTimeToDisplayTracking({bool clearAfter = false}) async { + Future _finishTimeToDisplayTracking({required DateTime endTimestamp, bool clearAfter = false}) async { final transaction = _transaction; _transaction = null; try { @@ -321,7 +324,7 @@ class SentryNavigatorObserver extends RouteObserver> { final isTTFDSpan = child.context.operation == SentrySpanOperations.uiTimeToFullDisplay; if (!child.finished && (isTTIDSpan || isTTFDSpan)) { - await child.finish(status: SpanStatus.deadlineExceeded()); + await child.finish(endTimestamp: endTimestamp, status: SpanStatus.deadlineExceeded()); } } } catch (exception, stacktrace) { @@ -335,14 +338,14 @@ class SentryNavigatorObserver extends RouteObserver> { rethrow; } } finally { - await transaction?.finish(); + await transaction?.finish(endTimestamp: endTimestamp); if (clearAfter) { _clear(); } } } - Future _startTimeToDisplayTracking(Route? route) async { + Future _startTimeToDisplayTracking(Route? route, DateTime startTimestamp) async { try { final routeName = _getRouteName(route) ?? _currentRouteName; if (!_enableAutoTransactions || routeName == null) { @@ -350,8 +353,6 @@ class SentryNavigatorObserver extends RouteObserver> { } bool isAppStart = routeName == '/'; - DateTime startTimestamp = _hub.options.clock(); - await _startTransaction(route, startTimestamp); final transaction = _transaction; diff --git a/flutter/lib/src/navigation/time_to_initial_display_tracker.dart b/flutter/lib/src/navigation/time_to_initial_display_tracker.dart index 051d0602b2..d342e97769 100644 --- a/flutter/lib/src/navigation/time_to_initial_display_tracker.dart +++ b/flutter/lib/src/navigation/time_to_initial_display_tracker.dart @@ -102,7 +102,9 @@ class TimeToInitialDisplayTracker { } void markAsManual() { - _isManual = true; + if (_trackingCompleter != null && !_trackingCompleter!.isCompleted) { + _isManual = true; + } } void completeTracking() {