@@ -21,7 +21,7 @@ class NativeAppStartHandler {
2121 static const _maxAppStartMillis = 60000 ;
2222
2323 Future <void > call (Hub hub, SentryFlutterOptions options,
24- {required DateTime ? appStartEnd}) async {
24+ {required DateTime appStartEnd}) async {
2525 _hub = hub;
2626 _options = options;
2727
@@ -42,43 +42,33 @@ class NativeAppStartHandler {
4242 SentrySpanOperations .uiLoad,
4343 startTimestamp: appStartInfo.start,
4444 );
45- final ttidSpan = transaction. startChild (
46- SentrySpanOperations .uiTimeToInitialDisplay,
47- description : '$ screenName initial display' ,
45+
46+ await options.timeToDisplayTracker. track (
47+ transaction ,
4848 startTimestamp: appStartInfo.start,
49+ endTimestamp: appStartInfo.end,
50+ origin: SentryTraceOrigins .autoUiTimeToDisplay,
4951 );
5052
51- // Enrich Transaction
52-
5353 SentryTracer sentryTracer;
5454 if (transaction is SentryTracer ) {
5555 sentryTracer = transaction;
5656 } else {
5757 return ;
5858 }
5959
60- SentryMeasurement ? measurement;
61- if (options.autoAppStart) {
62- measurement = appStartInfo.toMeasurement ();
63- } else if (appStartEnd != null ) {
64- appStartInfo.end = appStartEnd;
65- measurement = appStartInfo.toMeasurement ();
66- }
67-
68- if (measurement != null ) {
69- sentryTracer.measurements[measurement.name] = measurement;
70- await _attachAppStartSpans (appStartInfo, sentryTracer);
71- }
72-
73- // Finish Transaction & Span
60+ // Enrich Transaction
61+ SentryMeasurement ? measurement = appStartInfo.toMeasurement ();
62+ sentryTracer.measurements[measurement.name] = appStartInfo.toMeasurement ();
63+ await _attachAppStartSpans (appStartInfo, sentryTracer);
7464
75- await ttidSpan. finish (endTimestamp : appStartInfo.end);
65+ // Finish Transaction
7666 await transaction.finish (endTimestamp: appStartInfo.end);
7767 }
7868
7969 _AppStartInfo ? _infoNativeAppStart (
8070 NativeAppStart nativeAppStart,
81- DateTime ? appStartEnd,
71+ DateTime appStartEnd,
8272 ) {
8373 final sentrySetupStartDateTime = SentryFlutter .sentrySetupStartTime;
8474 if (sentrySetupStartDateTime == null ) {
@@ -90,23 +80,18 @@ class NativeAppStartHandler {
9080 final pluginRegistrationDateTime = DateTime .fromMillisecondsSinceEpoch (
9181 nativeAppStart.pluginRegistrationTime);
9282
93- if (_options.autoAppStart) {
94- // We only assign the current time if it's not already set - this is useful in tests
95- appStartEnd ?? = _options.clock ();
96-
97- final duration = appStartEnd.difference (appStartDateTime);
98-
99- // We filter out app start more than 60s.
100- // This could be due to many different reasons.
101- // If you do the manual init and init the SDK too late and it does not
102- // compute the app start end in the very first Screen.
103- // If the process starts but the App isn't in the foreground.
104- // If the system forked the process earlier to accelerate the app start.
105- // And some unknown reasons that could not be reproduced.
106- // We've seen app starts with hours, days and even months.
107- if (duration.inMilliseconds > _maxAppStartMillis) {
108- return null ;
109- }
83+ final duration = appStartEnd.difference (appStartDateTime);
84+
85+ // We filter out app start more than 60s.
86+ // This could be due to many different reasons.
87+ // If you do the manual init and init the SDK too late and it does not
88+ // compute the app start end in the very first Screen.
89+ // If the process starts but the App isn't in the foreground.
90+ // If the system forked the process earlier to accelerate the app start.
91+ // And some unknown reasons that could not be reproduced.
92+ // We've seen app starts with hours, days and even months.
93+ if (duration.inMilliseconds > _maxAppStartMillis) {
94+ return null ;
11095 }
11196
11297 List <_TimeSpan > nativeSpanTimes = [];
@@ -145,9 +130,6 @@ class NativeAppStartHandler {
145130 _AppStartInfo appStartInfo, SentryTracer transaction) async {
146131 final transactionTraceId = transaction.context.traceId;
147132 final appStartEnd = appStartInfo.end;
148- if (appStartEnd == null ) {
149- return ;
150- }
151133
152134 final appStartSpan = await _createAndFinishSpan (
153135 tracer: transaction,
@@ -256,30 +238,24 @@ class _AppStartInfo {
256238 _AppStartInfo (
257239 this .type, {
258240 required this .start,
241+ required this .end,
259242 required this .pluginRegistration,
260243 required this .sentrySetupStart,
261244 required this .nativeSpanTimes,
262- this .end,
263245 });
264246
265247 final _AppStartType type;
266248 final DateTime start;
249+ final DateTime end;
267250 final List <_TimeSpan > nativeSpanTimes;
268251
269- // We allow the end to be null, since it might be set at a later time
270- // with setAppStartEnd when autoAppStart is disabled
271- DateTime ? end;
272-
273252 final DateTime pluginRegistration;
274253 final DateTime sentrySetupStart;
275254
276- Duration ? get duration => end? .difference (start);
255+ Duration get duration => end.difference (start);
277256
278- SentryMeasurement ? toMeasurement () {
257+ SentryMeasurement toMeasurement () {
279258 final duration = this .duration;
280- if (duration == null ) {
281- return null ;
282- }
283259 return type == _AppStartType .cold
284260 ? SentryMeasurement .coldAppStart (duration)
285261 : SentryMeasurement .warmAppStart (duration);
0 commit comments