Skip to content

Commit

Permalink
Merge branch 'main' into feat/support-allow-urls-deny-urls
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhaintz authored Aug 13, 2024
2 parents c0ffc67 + ba56a96 commit 5598f4c
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

### Features

- Support allowUrls and denyUrls for Flutter Web ([#2227](https://github.com/getsentry/sentry-dart/pull/2227))
```dart
await SentryFlutter.init(
Expand All @@ -14,6 +16,18 @@
appRunner: () => runApp(MyApp()),
);
```
- Add `ignoreRoutes` parameter to `SentryNavigatorObserver`. ([#2218](https://github.com/getsentry/sentry-dart/pull/2218))
- This will ignore the Routes and prevent the Route from being pushed to the Sentry server.
- Ignored routes will also create no TTID and TTFD spans.
```dart
SentryNavigatorObserver(ignoreRoutes: ["/ignoreThisRoute"]),
```

### Dependencies

- Bump Android SDK from v7.13.0 to v7.14.0 ([#2228](https://github.com/getsentry/sentry-dart/pull/2228))
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#7140)
- [diff](https://github.com/getsentry/sentry-java/compare/7.13.0...7.14.0)

## 8.7.0

Expand Down
2 changes: 1 addition & 1 deletion flutter/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ android {
}

dependencies {
api 'io.sentry:sentry-android:7.13.0'
api 'io.sentry:sentry-android:7.14.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

// Required -- JUnit 4 framework
Expand Down
23 changes: 23 additions & 0 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
RouteNameExtractor? routeNameExtractor,
AdditionalInfoExtractor? additionalInfoProvider,
@visibleForTesting TimeToDisplayTracker? timeToDisplayTracker,
List<String>? ignoreRoutes,
}) : _hub = hub ?? HubAdapter(),
_enableAutoTransactions = enableAutoTransactions,
_autoFinishAfter = autoFinishAfter,
_setRouteNameAsTransaction = setRouteNameAsTransaction,
_routeNameExtractor = routeNameExtractor,
_additionalInfoProvider = additionalInfoProvider,
_ignoreRoutes = ignoreRoutes ?? [],
_native = SentryFlutter.native {
_isCreated = true;
if (enableAutoTransactions) {
Expand Down Expand Up @@ -113,6 +115,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
final RouteNameExtractor? _routeNameExtractor;
final AdditionalInfoExtractor? _additionalInfoProvider;
final SentryNativeBinding? _native;
final List<String> _ignoreRoutes;
static TimeToDisplayTracker? _timeToDisplayTracker;

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

if (_isRouteIgnored(route) ||
previousRoute != null && _isRouteIgnored(previousRoute)) {
return;
}

_setCurrentRouteName(route);
_setCurrentRouteNameAsTransaction(route);

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

if (newRoute != null && _isRouteIgnored(newRoute) ||
oldRoute != null && _isRouteIgnored(oldRoute)) {
return;
}

_setCurrentRouteName(newRoute);
_setCurrentRouteNameAsTransaction(newRoute);

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

if (_isRouteIgnored(route) ||
previousRoute != null && _isRouteIgnored(previousRoute)) {
return;
}

_setCurrentRouteName(previousRoute);
_setCurrentRouteNameAsTransaction(previousRoute);

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

@internal
static const String rootScreenName = 'root /';

bool _isRouteIgnored(Route<dynamic> route) {
return _ignoreRoutes.isNotEmpty &&
_ignoreRoutes.contains(_getRouteName(route));
}
}

/// This class makes it easier to record breadcrumbs for events of Flutters
Expand Down
62 changes: 62 additions & 0 deletions flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,66 @@ void main() {
observer.didReplace(newRoute: route(to), oldRoute: route(previous));
expect(hub.scope.transaction, 'to_test');
});

test('ignores Route and prevents recognition of this route for didPush',
() async {
final firstRoute = route(RouteSettings(name: 'default'));
final secondRoute = route(RouteSettings(name: 'testRoute'));

final hub = _MockHub();

final sut = fixture.getSut(hub: hub, ignoreRoutes: ["testRoute"]);

sut.didPush(firstRoute, null);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
sut.didPush(secondRoute, firstRoute);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
sut.didPush(firstRoute, secondRoute);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
});

test('ignores Route and prevents recognition of this route for didPop',
() async {
final firstRoute = route(RouteSettings(name: 'default'));
final secondRoute = route(RouteSettings(name: 'testRoute'));

final hub = _MockHub();

final sut = fixture.getSut(hub: hub, ignoreRoutes: ["testRoute"]);

sut.didPush(firstRoute, null);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
sut.didPush(secondRoute, firstRoute);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
sut.didPop(firstRoute, secondRoute);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
});

test('ignores Route and prevents recognition of this route for didReplace',
() async {
final firstRoute = route(RouteSettings(name: 'default'));
final secondRoute = route(RouteSettings(name: 'testRoute'));

final hub = _MockHub();

final sut = fixture.getSut(hub: hub, ignoreRoutes: ["testRoute"]);

sut.didReplace(newRoute: firstRoute);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
sut.didReplace(newRoute: secondRoute, oldRoute: firstRoute);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
sut.didReplace(newRoute: firstRoute, oldRoute: secondRoute);
expect(
SentryNavigatorObserver.currentRouteName, firstRoute.settings.name);
});
});
}

Expand All @@ -987,6 +1047,7 @@ class Fixture {
RouteNameExtractor? routeNameExtractor,
AdditionalInfoExtractor? additionalInfoProvider,
bool enableTimeToFullDisplayTracing = false,
List<String>? ignoreRoutes,
}) {
final frameCallbackHandler = FakeFrameCallbackHandler();
final timeToInitialDisplayTracker =
Expand All @@ -1003,6 +1064,7 @@ class Fixture {
routeNameExtractor: routeNameExtractor,
additionalInfoProvider: additionalInfoProvider,
timeToDisplayTracker: timeToDisplayTracker,
ignoreRoutes: ignoreRoutes,
);
}

Expand Down
2 changes: 1 addition & 1 deletion metrics/flutter.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 3.22.3
version = 3.24.0
repo = https://github.com/flutter/flutter

0 comments on commit 5598f4c

Please sign in to comment.