Skip to content

Commit 6a707da

Browse files
committed
use epoch
1 parent f2668bb commit 6a707da

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

flutter/lib/src/event_processor/native_app_start_event_processor.dart

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class NativeAppStartEventProcessor implements EventProcessor {
3939
if (measurement.value >= _maxAppStartMillis) {
4040
return event;
4141
}
42+
print('hello app');
4243
event.measurements[measurement.name] = measurement;
4344
}
4445
return event;

flutter/lib/src/navigation/sentry_navigator_observer.dart

+18-5
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
127127
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
128128
approximationEndTimestamp = DateTime.now();
129129
approximationDurationMillis =
130-
approximationEndTimestamp!.millisecond - startTime.millisecond;
130+
approximationEndTimestamp!.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch;
131131
});
132132

133133
SentryDisplayTracker().startTimeout(routeName ?? 'Unknown', () {
@@ -139,6 +139,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
139139
'time_to_initial_display', approximationDurationMillis!,
140140
unit: DurationSentryMeasurementUnit.milliSecond);
141141
ttidSpan?.finish(endTimestamp: approximationEndTimestamp!);
142+
print('finished already');
142143
});
143144
}
144145

@@ -276,17 +277,29 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
276277
return;
277278
}
278279

279-
startTime = DateTime.now();
280-
ttidSpan = _transaction2?.startChild('ui.load.initial_display', description: '$name initial display');
281-
ttidSpan?.origin = 'auto.ui.time_to_display';
280+
if (name == 'root ("/")') {
281+
// root ttid spans have to align with app start
282+
// so the ttid instrumentation needs to be different here.
283+
startTime = DateTime.now();
284+
ttidSpan = _transaction2?.startChild('ui.load.initial_display', description: '$name initial display', startTimestamp: startTime);
285+
ttidSpan?.origin = 'auto.ui.time_to_display';
286+
} else {
287+
startTime = DateTime.now();
288+
ttidSpan = _transaction2?.startChild('ui.load.initial_display', description: '$name initial display', startTimestamp: startTime);
289+
ttidSpan?.origin = 'auto.ui.time_to_display';
290+
}
282291

283292
// TODO: Needs to finish max within 30 seconds
284293
// If timeout exceeds then it will finish with status deadline exceeded
285294
// What to do if root also has TTFD but it's not finished yet and we start navigating to another?
286295
// How to track the time that 30 sec have passed?
296+
//
297+
// temporarily disable ttfd for root since it somehow swallows other spans
298+
// e.g the complex operation span in autoclosescreen
287299
if ((_hub.options as SentryFlutterOptions).enableTimeToFullDisplayTracing && name != 'root ("/")') {
288300
ttfdStopwatch = Stopwatch()..start();
289-
ttfdSpan = _transaction2?.startChild('ui.load.full_display', description: '$name full display');
301+
ttfdStartTime = DateTime.now();
302+
ttfdSpan = _transaction2?.startChild('ui.load.full_display', description: '$name full display', startTimestamp: ttfdStartTime);
290303
}
291304

292305
if (arguments != null) {

flutter/lib/src/sentry_flutter.dart

+7-12
Original file line numberDiff line numberDiff line change
@@ -235,25 +235,20 @@ mixin SentryFlutter {
235235
if (!SentryDisplayTracker().reportManual(routeName)) {
236236
SentryNavigatorObserver.transaction2?.setMeasurement(
237237
'time_to_initial_display',
238-
endTime.millisecond - SentryNavigatorObserver.startTime.millisecond,
238+
endTime.millisecondsSinceEpoch - SentryNavigatorObserver.startTime.millisecondsSinceEpoch,
239239
unit: DurationSentryMeasurementUnit.milliSecond);
240-
241-
SentryNavigatorObserver.ttidSpan?.setTag('measurement', 'manual');
242240
SentryNavigatorObserver.ttidSpan?.finish(endTimestamp: endTime);
243241
}
244242
}
245243

246244
/// Reports the time it took for the screen to be fully displayed.
247245
static void reportFullDisplay() {
248-
if (SentryNavigatorObserver.ttfdStopwatch?.elapsedMilliseconds != null) {
249-
SentryNavigatorObserver.ttfdStopwatch?.stop();
250-
SentryNavigatorObserver.ttfdSpan?.setMeasurement(
251-
'time_to_full_display',
252-
SentryNavigatorObserver.ttfdStopwatch!.elapsedMilliseconds,
253-
unit: DurationSentryMeasurementUnit.milliSecond);
254-
SentryNavigatorObserver.ttfdStopwatch?.reset();
255-
}
256-
SentryNavigatorObserver.ttfdSpan?.finish();
246+
final endTime = DateTime.now();
247+
SentryNavigatorObserver.ttfdSpan?.setMeasurement(
248+
'time_to_full_display',
249+
endTime.millisecondsSinceEpoch - SentryNavigatorObserver.ttfdStartTime.millisecondsSinceEpoch,
250+
unit: DurationSentryMeasurementUnit.milliSecond);
251+
SentryNavigatorObserver.ttfdSpan?.finish(endTimestamp: endTime);
257252
}
258253

259254
@internal

flutter/lib/src/sentry_flutter_options.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class SentryFlutterOptions extends SentryOptions {
223223
/// Read timeout. This will only be synced to the Android native SDK.
224224
Duration readTimeout = Duration(seconds: 5);
225225

226-
/// Enable or disable the tracing of time to full display.
226+
/// Enable or disable the tracing of time to full display (TTFD).
227227
/// This feature requires using the [Routing Instrumentation](https://docs.sentry.io/platforms/flutter/integrations/routing-instrumentation/).
228228
bool enableTimeToFullDisplayTracing = false;
229229

0 commit comments

Comments
 (0)