Skip to content

Commit

Permalink
Bind root screen transaction to scope
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Feb 26, 2025
1 parent 08aff50 commit f5a3e49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions flutter/lib/src/integrations/native_app_start_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,27 @@ class NativeAppStartHandler {
// Create Transaction & Span

const screenName = 'root /';
final transaction = _hub.startTransaction(
final rootScreenTransaction = _hub.startTransaction(
screenName,
SentrySpanOperations.uiLoad,
startTimestamp: appStartInfo.start,
);

// Bind to scope if null
await _hub.configureScope((scope) {
scope.span ??= rootScreenTransaction;

Check warning on line 48 in flutter/lib/src/integrations/native_app_start_handler.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/integrations/native_app_start_handler.dart#L48

Added line #L48 was not covered by tests
});

await options.timeToDisplayTracker.track(
transaction,
rootScreenTransaction,
startTimestamp: appStartInfo.start,
endTimestamp: appStartInfo.end,
origin: SentryTraceOrigins.autoUiTimeToDisplay,
);

SentryTracer sentryTracer;
if (transaction is SentryTracer) {
sentryTracer = transaction;
if (rootScreenTransaction is SentryTracer) {
sentryTracer = rootScreenTransaction;
} else {
return;
}
Expand All @@ -62,8 +67,15 @@ class NativeAppStartHandler {
sentryTracer.measurements[measurement.name] = appStartInfo.toMeasurement();
await _attachAppStartSpans(appStartInfo, sentryTracer);

// Remove from scope
await _hub.configureScope((scope) {
if (scope.span == rootScreenTransaction) {
scope.span = null;

Check warning on line 73 in flutter/lib/src/integrations/native_app_start_handler.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/integrations/native_app_start_handler.dart#L72-L73

Added lines #L72 - L73 were not covered by tests
}
});

// Finish Transaction
await transaction.finish(endTimestamp: appStartInfo.end);
await rootScreenTransaction.finish(endTimestamp: appStartInfo.end);
}

_AppStartInfo? _infoNativeAppStart(
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
_transaction = null;
try {
_hub.configureScope((scope) {
if (scope.span == transaction) {
if (transaction != null && scope.span == transaction) {
scope.span = null;
}
});
Expand Down

0 comments on commit f5a3e49

Please sign in to comment.