Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -66,6 +66,7 @@ Navigator.push(
- Start missing TTFD for root screen transaction ([#2332](https://github.com/getsentry/sentry-dart/pull/2332))
- Accessing invalid json fields from `fetchNativeAppStart` should return null ([#2340](https://github.com/getsentry/sentry-dart/pull/2340))
- Error when calling `SentryFlutter.reportFullyDisplayed()` twice ([#2339](https://github.com/getsentry/sentry-dart/pull/2339))
- TTFD measurements should only be added for successful TTFD spans ([#2348](https://github.com/getsentry/sentry-dart/pull/2348))

### Deprecate

Expand Down
33 changes: 24 additions & 9 deletions flutter/lib/src/navigation/time_to_full_display_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
final endTimestamp = timestamp ?? _endTimestampProvider();

if (ttfdSpan == null ||
ttfdSpan.finished == true ||
ttfdSpan.finished ||
startTimestamp == null ||
endTimestamp == null) {
options.logger(
Expand All @@ -83,14 +83,29 @@
return;
}

_setTTFDMeasurement(startTimestamp, endTimestamp);
await ttfdSpan.finish(
status:
timestamp != null ? SpanStatus.ok() : SpanStatus.deadlineExceeded(),
endTimestamp: endTimestamp,
);
_completedTTFDTracking.complete();
clear();
// If a timestamp is provided, the operation was successful; otherwise, it timed out
final status =
timestamp != null ? SpanStatus.ok() : SpanStatus.deadlineExceeded();
try {
// Should only add measurements if the span is successful
if (status == SpanStatus.ok()) {
_setTTFDMeasurement(startTimestamp, endTimestamp);
}
await ttfdSpan.finish(
status: status,
endTimestamp: endTimestamp,
);
} catch (e, stackTrace) {
options.logger(

Check warning on line 99 in flutter/lib/src/navigation/time_to_full_display_tracker.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/navigation/time_to_full_display_tracker.dart#L99

Added line #L99 was not covered by tests
SentryLevel.error,
'Failed to finish TTFD span',
exception: e,
stackTrace: stackTrace,
);
} finally {
_completedTTFDTracking.complete();
clear();
}
}

void _setTTFDMeasurement(DateTime startTimestamp, DateTime endTimestamp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void main() {
final differenceInSeconds =
actualEndTimestamp.difference(expectedEndTimestamp).inSeconds.abs();
expect(differenceInSeconds, lessThanOrEqualTo(1));
expect(transaction.measurements, isNotEmpty);
});

test(
Expand All @@ -66,6 +67,7 @@ void main() {
expect(ttfdSpan.status, equals(SpanStatus.deadlineExceeded()));
expect(ttfdSpan.context.description, equals('Current route full display'));
expect(ttfdSpan.origin, equals(SentryTraceOrigins.manualUiTimeToDisplay));
expect(transaction.measurements, isEmpty);
});

test('finishing ttfd twice does not throw', () async {
Expand Down
Loading