From 7d08c83162eefc292754a1d9bb013cbe6230e79b Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 8 Oct 2024 10:44:39 +0200 Subject: [PATCH] use timeToDisplayTracker from options, remove timeToDisplayTracker from navigator ctor --- .../navigation/sentry_navigator_observer.dart | 10 ++-------- flutter/lib/src/sentry_flutter.dart | 8 +++++++- flutter/test/sentry_navigator_observer_test.dart | 16 +++++++++------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/flutter/lib/src/navigation/sentry_navigator_observer.dart b/flutter/lib/src/navigation/sentry_navigator_observer.dart index 3be296ddc1..2279d6e434 100644 --- a/flutter/lib/src/navigation/sentry_navigator_observer.dart +++ b/flutter/lib/src/navigation/sentry_navigator_observer.dart @@ -78,7 +78,6 @@ class SentryNavigatorObserver extends RouteObserver> { bool setRouteNameAsTransaction = false, RouteNameExtractor? routeNameExtractor, AdditionalInfoExtractor? additionalInfoProvider, - @visibleForTesting TimeToDisplayTracker? timeToDisplayTracker, List? ignoreRoutes, }) : _hub = hub ?? HubAdapter(), _enableAutoTransactions = enableAutoTransactions, @@ -92,8 +91,7 @@ class SentryNavigatorObserver extends RouteObserver> { 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. @@ -114,11 +112,7 @@ class SentryNavigatorObserver extends RouteObserver> { final AdditionalInfoExtractor? _additionalInfoProvider; final SentryNativeBinding? _native; final List _ignoreRoutes; - static TimeToDisplayTracker? _timeToDisplayTracker; - - @internal - static TimeToDisplayTracker? get timeToDisplayTracker => - _timeToDisplayTracker; + TimeToDisplayTracker? _timeToDisplayTracker; ISentrySpan? _transaction; diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index e190115149..ee68d01f9f 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -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 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(); + } else { + return; + } } /// Pauses the app hang tracking. diff --git a/flutter/test/sentry_navigator_observer_test.dart b/flutter/test/sentry_navigator_observer_test.dart index 407bed316f..407496874a 100644 --- a/flutter/test/sentry_navigator_observer_test.dart +++ b/flutter/test/sentry_navigator_observer_test.dart @@ -1044,16 +1044,19 @@ class Fixture { bool setRouteNameAsTransaction = false, RouteNameExtractor? routeNameExtractor, AdditionalInfoExtractor? additionalInfoProvider, - bool enableTimeToFullDisplayTracing = false, List? 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, @@ -1061,7 +1064,6 @@ class Fixture { setRouteNameAsTransaction: setRouteNameAsTransaction, routeNameExtractor: routeNameExtractor, additionalInfoProvider: additionalInfoProvider, - timeToDisplayTracker: timeToDisplayTracker, ignoreRoutes: ignoreRoutes, ); }