Skip to content

Commit

Permalink
use timeToDisplayTracker from options, remove timeToDisplayTracker fr…
Browse files Browse the repository at this point in the history
…om navigator ctor
  • Loading branch information
denrase committed Oct 8, 2024
1 parent c12cab3 commit 7d08c83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
10 changes: 2 additions & 8 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
bool setRouteNameAsTransaction = false,
RouteNameExtractor? routeNameExtractor,
AdditionalInfoExtractor? additionalInfoProvider,
@visibleForTesting TimeToDisplayTracker? timeToDisplayTracker,
List<String>? ignoreRoutes,
}) : _hub = hub ?? HubAdapter(),
_enableAutoTransactions = enableAutoTransactions,
Expand All @@ -92,8 +91,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
if (enableAutoTransactions) {
_hub.options.sdk.addIntegration('UINavigationTracing');
}
_timeToDisplayTracker =
timeToDisplayTracker ?? _initializeTimeToDisplayTracker();
_timeToDisplayTracker = _initializeTimeToDisplayTracker();
}

/// Initializes the TimeToDisplayTracker with the option to enable time to full display tracing.
Expand All @@ -114,11 +112,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
final AdditionalInfoExtractor? _additionalInfoProvider;
final SentryNativeBinding? _native;
final List<String> _ignoreRoutes;
static TimeToDisplayTracker? _timeToDisplayTracker;

@internal
static TimeToDisplayTracker? get timeToDisplayTracker =>
_timeToDisplayTracker;
TimeToDisplayTracker? _timeToDisplayTracker;

ISentrySpan? _transaction;

Expand Down
8 changes: 7 additions & 1 deletion flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,13 @@ mixin SentryFlutter {
/// Reports the time it took for the screen to be fully displayed.
/// This requires the [SentryFlutterOptions.enableTimeToFullDisplayTracing] option to be set to `true`.
static Future<void> reportFullyDisplayed() async {
return SentryNavigatorObserver.timeToDisplayTracker?.reportFullyDisplayed();
// ignore: invalid_use_of_internal_member
final options = Sentry.currentHub.options;
if (options is SentryFlutterOptions) {
return options.timeToDisplayTracker.reportFullyDisplayed();

Check warning on line 248 in flutter/lib/src/sentry_flutter.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/sentry_flutter.dart#L246-L248

Added lines #L246 - L248 were not covered by tests
} else {
return;
}
}

/// Pauses the app hang tracking.
Expand Down
16 changes: 9 additions & 7 deletions flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1044,24 +1044,26 @@ class Fixture {
bool setRouteNameAsTransaction = false,
RouteNameExtractor? routeNameExtractor,
AdditionalInfoExtractor? additionalInfoProvider,
bool enableTimeToFullDisplayTracing = false,
List<String>? ignoreRoutes,
}) {
final frameCallbackHandler = FakeFrameCallbackHandler();
final timeToInitialDisplayTracker =
TimeToInitialDisplayTracker(frameCallbackHandler: frameCallbackHandler);
final timeToDisplayTracker = TimeToDisplayTracker(
ttidTracker: timeToInitialDisplayTracker,
options: hub.options as SentryFlutterOptions,
final timeToInitialDisplayTracker = TimeToInitialDisplayTracker(
frameCallbackHandler: frameCallbackHandler,
);
final options = hub.options;
if (options is SentryFlutterOptions) {
options.timeToDisplayTracker = TimeToDisplayTracker(
ttidTracker: timeToInitialDisplayTracker,
options: hub.options as SentryFlutterOptions,
);
}
return SentryNavigatorObserver(
hub: hub,
enableAutoTransactions: enableAutoTransactions,
autoFinishAfter: autoFinishAfter,
setRouteNameAsTransaction: setRouteNameAsTransaction,
routeNameExtractor: routeNameExtractor,
additionalInfoProvider: additionalInfoProvider,
timeToDisplayTracker: timeToDisplayTracker,
ignoreRoutes: ignoreRoutes,
);
}
Expand Down

0 comments on commit 7d08c83

Please sign in to comment.