@@ -71,7 +71,7 @@ class TimeToFullDisplayTracker {
7171 final endTimestamp = timestamp ?? _endTimestampProvider ();
7272
7373 if (ttfdSpan == null ||
74- ttfdSpan.finished == true ||
74+ ttfdSpan.finished ||
7575 startTimestamp == null ||
7676 endTimestamp == null ) {
7777 options.logger (
@@ -83,14 +83,29 @@ class TimeToFullDisplayTracker {
8383 return ;
8484 }
8585
86- _setTTFDMeasurement (startTimestamp, endTimestamp);
87- await ttfdSpan.finish (
88- status:
89- timestamp != null ? SpanStatus .ok () : SpanStatus .deadlineExceeded (),
90- endTimestamp: endTimestamp,
91- );
92- _completedTTFDTracking.complete ();
93- clear ();
86+ // If a timestamp is provided, the operation was successful; otherwise, it timed out
87+ final status =
88+ timestamp != null ? SpanStatus .ok () : SpanStatus .deadlineExceeded ();
89+ try {
90+ // Should only add measurements if the span is successful
91+ if (status == SpanStatus .ok ()) {
92+ _setTTFDMeasurement (startTimestamp, endTimestamp);
93+ }
94+ await ttfdSpan.finish (
95+ status: status,
96+ endTimestamp: endTimestamp,
97+ );
98+ } catch (e, stackTrace) {
99+ options.logger (
100+ SentryLevel .error,
101+ 'Failed to finish TTFD span' ,
102+ exception: e,
103+ stackTrace: stackTrace,
104+ );
105+ } finally {
106+ _completedTTFDTracking.complete ();
107+ clear ();
108+ }
94109 }
95110
96111 void _setTTFDMeasurement (DateTime startTimestamp, DateTime endTimestamp) {
0 commit comments