Skip to content

Commit

Permalink
Fix issue where TTD was not recording every transacion
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Oct 1, 2024
1 parent 9e6147d commit c4af7e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 12 additions & 11 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {

// 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<void> _finishAndStartTTIDTracking(Route<dynamic>? route) async {
await _finishTimeToDisplayTracking();
await _startTimeToDisplayTracking(route);
Future<void> _finishAndStartTTIDTracking(Route<dynamic>? route, DateTime timestamp) async {
await _finishTimeToDisplayTracking(endTimestamp: timestamp);
await _startTimeToDisplayTracking(route, timestamp);
}

@override
Expand Down Expand Up @@ -204,7 +206,8 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
to: previousRoute?.settings,
);

_finishTimeToDisplayTracking(clearAfter: true);
final timestamp = _hub.options.clock();
_finishTimeToDisplayTracking(endTimestamp: timestamp, clearAfter: true);
}

void _addBreadcrumb({
Expand Down Expand Up @@ -299,7 +302,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
await _native?.beginNativeFrames();
}

Future<void> _finishTimeToDisplayTracking({bool clearAfter = false}) async {
Future<void> _finishTimeToDisplayTracking({required DateTime endTimestamp, bool clearAfter = false}) async {
final transaction = _transaction;
_transaction = null;
try {
Expand All @@ -321,7 +324,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
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) {
Expand All @@ -335,23 +338,21 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
rethrow;
}
} finally {
await transaction?.finish();
await transaction?.finish(endTimestamp: endTimestamp);
if (clearAfter) {
_clear();
}
}
}

Future<void> _startTimeToDisplayTracking(Route<dynamic>? route) async {
Future<void> _startTimeToDisplayTracking(Route<dynamic>? route, DateTime startTimestamp) async {
try {
final routeName = _getRouteName(route) ?? _currentRouteName;
if (!_enableAutoTransactions || routeName == null) {
return;
}

bool isAppStart = routeName == '/';
DateTime startTimestamp = _hub.options.clock();

await _startTransaction(route, startTimestamp);

final transaction = _transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class TimeToInitialDisplayTracker {
}

void markAsManual() {
_isManual = true;
if (_trackingCompleter != null && !_trackingCompleter!.isCompleted) {
_isManual = true;
}
}

void completeTracking() {
Expand Down

0 comments on commit c4af7e4

Please sign in to comment.