Skip to content

Commit 22833ce

Browse files
committed
add ignoreRoutes parameter to SentryNavigatorObserver
1 parent 384a55c commit 22833ce

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

flutter/lib/src/navigation/sentry_navigator_observer.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
8080
RouteNameExtractor? routeNameExtractor,
8181
AdditionalInfoExtractor? additionalInfoProvider,
8282
@visibleForTesting TimeToDisplayTracker? timeToDisplayTracker,
83+
List<String>? ignoreRoutes,
8384
}) : _hub = hub ?? HubAdapter(),
8485
_enableAutoTransactions = enableAutoTransactions,
8586
_autoFinishAfter = autoFinishAfter,
8687
_setRouteNameAsTransaction = setRouteNameAsTransaction,
8788
_routeNameExtractor = routeNameExtractor,
8889
_additionalInfoProvider = additionalInfoProvider,
90+
_ignoreRoutes = ignoreRoutes ?? [],
8991
_native = SentryFlutter.native {
9092
_isCreated = true;
9193
if (enableAutoTransactions) {
@@ -113,6 +115,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
113115
final RouteNameExtractor? _routeNameExtractor;
114116
final AdditionalInfoExtractor? _additionalInfoProvider;
115117
final SentryNativeBinding? _native;
118+
final List<String> _ignoreRoutes;
116119
static TimeToDisplayTracker? _timeToDisplayTracker;
117120

118121
@internal
@@ -141,6 +144,11 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
141144
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
142145
super.didPush(route, previousRoute);
143146

147+
if (_isRouteIgnored(route) ||
148+
previousRoute != null && _isRouteIgnored(previousRoute)) {
149+
return;
150+
}
151+
144152
_setCurrentRouteName(route);
145153
_setCurrentRouteNameAsTransaction(route);
146154

@@ -160,6 +168,11 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
160168
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
161169
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
162170

171+
if (newRoute != null && _isRouteIgnored(newRoute) ||
172+
oldRoute != null && _isRouteIgnored(oldRoute)) {
173+
return;
174+
}
175+
163176
_setCurrentRouteName(newRoute);
164177
_setCurrentRouteNameAsTransaction(newRoute);
165178

@@ -174,6 +187,11 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
174187
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
175188
super.didPop(route, previousRoute);
176189

190+
if (_isRouteIgnored(route) ||
191+
previousRoute != null && _isRouteIgnored(previousRoute)) {
192+
return;
193+
}
194+
177195
_setCurrentRouteName(previousRoute);
178196
_setCurrentRouteNameAsTransaction(previousRoute);
179197

@@ -376,6 +394,11 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
376394

377395
@internal
378396
static const String rootScreenName = 'root /';
397+
398+
bool _isRouteIgnored(Route<dynamic> route) {
399+
return _ignoreRoutes.isNotEmpty &&
400+
_ignoreRoutes.contains(_getRouteName(route));
401+
}
379402
}
380403

381404
/// This class makes it easier to record breadcrumbs for events of Flutters

0 commit comments

Comments
 (0)