Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App start: Create transaction when no SentryNavigatorObserver is present #2017

Merged
merged 45 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5ad308b
commit
buenaflor Apr 18, 2024
7bc756b
Merge branch 'main' into feat/app-start-improve
buenaflor Apr 23, 2024
3e0790a
Update
buenaflor Apr 23, 2024
d0eb540
Remove print
buenaflor Apr 23, 2024
05c208c
Remove comments
buenaflor Apr 23, 2024
c796b71
Update
buenaflor Apr 24, 2024
da8297e
Merge branch 'main' into feat/app-start-improve
buenaflor Apr 24, 2024
bdc8588
Add linting
buenaflor Apr 24, 2024
d1b37cd
Update CHANGELOG
buenaflor Apr 24, 2024
6f44478
Update CHANGELOG.md
buenaflor Apr 24, 2024
8051972
Update naming
buenaflor Apr 24, 2024
29671ff
Merge branch 'main' into feat/app-start-improve
buenaflor Apr 24, 2024
b401ed0
Update naming
buenaflor Apr 24, 2024
c06973c
Update naming
buenaflor Apr 24, 2024
8b9c0c0
Create transaction
buenaflor Apr 24, 2024
2bb3887
Update description from first frame render to initial frame render
buenaflor Apr 24, 2024
85e851b
Merge branch 'feat/app-start-improve' into feat/app-start-improve-2
buenaflor Apr 24, 2024
58f2585
Update
buenaflor Apr 24, 2024
801483e
update
buenaflor Apr 26, 2024
d28af71
dart format
buenaflor Apr 26, 2024
21c61a6
Update comments
buenaflor Apr 26, 2024
88a8819
Update
buenaflor Apr 26, 2024
0d73052
Update
buenaflor Apr 26, 2024
1e05ae5
Update
buenaflor Apr 26, 2024
73d830a
Update
buenaflor Apr 26, 2024
62cb2be
Update
buenaflor Apr 26, 2024
111125c
Fix tests
buenaflor Apr 29, 2024
04ad023
Fix test
buenaflor Apr 29, 2024
e9e95c4
Add unused import
buenaflor Apr 29, 2024
ce7af57
Merge branch 'feat/app-start-improve' into feat/app-start-improve-2
buenaflor Apr 29, 2024
615782e
Update
buenaflor Apr 29, 2024
04724d5
Update
buenaflor Apr 29, 2024
263c020
Updat
buenaflor Apr 29, 2024
f7573f1
Fix tests
buenaflor Apr 29, 2024
3a9cca9
Fix tests
buenaflor Apr 29, 2024
5fff0be
Merge branch 'main' into feat/app-start-improve-2
buenaflor Apr 29, 2024
26e5834
Fix analyze
buenaflor Apr 29, 2024
b0f49c5
Merge branch 'main' into feat/app-start-improve-2
buenaflor May 3, 2024
37b6771
Update
buenaflor May 3, 2024
06836a2
Update
buenaflor May 3, 2024
8984d63
Merge branch 'main' into feat/app-start-improve-2
buenaflor May 8, 2024
e294533
Updaet
buenaflor May 8, 2024
eb90496
Merge branch 'main' into feat/app-start-improve-2
buenaflor May 9, 2024
7001b46
Update
buenaflor May 9, 2024
0063429
Add additional flag and update comment
buenaflor May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Features

- Create app start transaction when no `SentryNavigatorObserver` is present ([#2017](https://github.com/getsentry/sentry-dart/pull/2017))
- Adds native spans to app start transaction ([#2027](https://github.com/getsentry/sentry-dart/pull/2027))
- Adds app start spans to first transaction ([#2009](https://github.com/getsentry/sentry-dart/pull/2009))

Expand Down
27 changes: 25 additions & 2 deletions flutter/lib/src/integrations/native_app_start_integration.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: invalid_use_of_internal_member

import 'dart:async';

import 'package:meta/meta.dart';
Expand Down Expand Up @@ -96,7 +98,6 @@ class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {

if (options.autoAppStart) {
// We only assign the current time if it's not already set - this is useful in tests
// ignore: invalid_use_of_internal_member
_native.appStartEnd ??= options.clock();
appStartEndDateTime = _native.appStartEnd;

Expand Down Expand Up @@ -129,7 +130,6 @@ class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {
description: entry.key as String,
));
} catch (e) {
// ignore: invalid_use_of_internal_member
_hub.options.logger(
SentryLevel.warning, 'Failed to parse native span times: $e');
continue;
Expand All @@ -149,6 +149,29 @@ class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {
nativeSpanTimes: nativeSpanTimes);

setAppStartInfo(appStartInfo);

// When we don't have a SentryNavigatorObserver, a TTID transaction
// 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 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,
startTimestamp: appStartInfo.start);
final ttidSpan = transaction.startChild(
SentrySpanOperations.uiTimeToInitialDisplay,
description: '$screenName initial display',
startTimestamp: appStartInfo.start);
await ttidSpan.finish(endTimestamp: appStartInfo.end);
await transaction.finish(endTimestamp: appStartInfo.end);
}
});

options.addEventProcessor(NativeAppStartEventProcessor(_native, hub: hub));
Expand Down
11 changes: 10 additions & 1 deletion flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
_routeNameExtractor = routeNameExtractor,
_additionalInfoProvider = additionalInfoProvider,
_native = SentryFlutter.native {
_isCreated = true;
if (enableAutoTransactions) {
_hub.options.sdk.addIntegration('UINavigationTracing');
}
Expand Down Expand Up @@ -121,6 +122,11 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {

static String? _currentRouteName;

static bool _isCreated = false;

@internal
static bool get isCreated => _isCreated;

@internal
static String? get currentRouteName => _currentRouteName;

Expand Down Expand Up @@ -224,7 +230,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
}

if (name == '/') {
name = 'root /';
name = rootScreenName;
}
final transactionContext = SentryTransactionContext(
name,
Expand Down Expand Up @@ -366,6 +372,9 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
_completedDisplayTracking = Completer();
_timeToDisplayTracker?.clear();
}

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

/// This class makes it easier to record breadcrumbs for events of Flutters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@ import '../mocks.dart';
import '../mocks.mocks.dart';

void main() {
void setupMocks(Fixture fixture) {
when(fixture.hub.startTransaction('root /', 'ui.load',
description: null, startTimestamp: anyNamed('startTimestamp')))
.thenReturn(fixture.createTracer());
when(fixture.hub.configureScope(captureAny)).thenAnswer((_) {});
when(fixture.hub
.captureTransaction(any, traceContext: anyNamed('traceContext')))
.thenAnswer((_) async => SentryId.empty());
}

group('$NativeAppStartIntegration', () {
late Fixture fixture;

setUp(() {
TestWidgetsFlutterBinding.ensureInitialized();

fixture = Fixture();
setupMocks(fixture);

NativeAppStartIntegration.clearAppStartInfo();
});

Expand Down Expand Up @@ -257,6 +269,7 @@ void main() {
SentryFlutter.sentrySetupStartTime =
DateTime.fromMillisecondsSinceEpoch(15);

setupMocks(fixture);
fixture.getNativeAppStartIntegration().call(fixture.hub, fixture.options);

final processor = fixture.options.eventProcessors.first;
Expand Down
Loading