From 0063429a3dca962bb6c7c7539bc1d7354aaa70e1 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 10 May 2024 12:03:20 +0200 Subject: [PATCH] Add additional flag and update comment --- .../src/integrations/native_app_start_integration.dart | 10 +++++++--- .../lib/src/navigation/sentry_navigator_observer.dart | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/flutter/lib/src/integrations/native_app_start_integration.dart b/flutter/lib/src/integrations/native_app_start_integration.dart index c4c977d0a6..616042406a 100644 --- a/flutter/lib/src/integrations/native_app_start_integration.dart +++ b/flutter/lib/src/integrations/native_app_start_integration.dart @@ -154,9 +154,13 @@ class NativeAppStartIntegration extends Integration { // is not created therefore we need to create a transaction ourselves. // We detect this by checking if the currentRouteName is null. // This is a workaround since there is no api that tells us if - // the navigator observer exists or not. The currentRouteName is always - // set during a didPush triggered by the navigator observer. - if (SentryNavigatorObserver.currentRouteName == null) { + // the navigator observer exists and has been attached. + // The navigator observer also triggers much earlier so if it was attached + // it would have already set the routeName and the isCreated flag. + // The currentRouteName is always set during a didPush triggered + // by the navigator observer. + if (!SentryNavigatorObserver.isCreated && + SentryNavigatorObserver.currentRouteName == null) { const screenName = SentryNavigatorObserver.rootScreenName; final transaction = hub.startTransaction( screenName, SentrySpanOperations.uiLoad, diff --git a/flutter/lib/src/navigation/sentry_navigator_observer.dart b/flutter/lib/src/navigation/sentry_navigator_observer.dart index 38d2617b67..fbfc12b6ee 100644 --- a/flutter/lib/src/navigation/sentry_navigator_observer.dart +++ b/flutter/lib/src/navigation/sentry_navigator_observer.dart @@ -86,6 +86,7 @@ class SentryNavigatorObserver extends RouteObserver> { _routeNameExtractor = routeNameExtractor, _additionalInfoProvider = additionalInfoProvider, _native = SentryFlutter.native { + _isCreated = true; if (enableAutoTransactions) { _hub.options.sdk.addIntegration('UINavigationTracing'); } @@ -121,6 +122,11 @@ class SentryNavigatorObserver extends RouteObserver> { static String? _currentRouteName; + static bool _isCreated = false; + + @internal + static bool get isCreated => _isCreated; + @internal static String? get currentRouteName => _currentRouteName;