@@ -49,9 +49,9 @@ class SentryTracer extends ISentrySpan {
49
49
/// highest timestamp of child spans, trimming the duration of the
50
50
/// transaction. This is useful to discard extra time in the transaction that
51
51
/// is not accounted for in child spans, like what happens in the
52
- /// [SentryNavigatorObserver] (https://pub.dev/documentation/sentry_flutter/latest/sentry_flutter/SentryNavigatorObserver-class.html)
53
- /// idle transactions, where we finish the transaction after a given
54
- /// "idle time" and we don't want this "idle time" to be part of the transaction.
52
+ /// [SentryNavigatorObserver] idle transactions, where we finish the
53
+ /// transaction after a given " idle time" and we don't want this "idle time"
54
+ /// to be part of the transaction.
55
55
SentryTracer (
56
56
SentryTransactionContext transactionContext,
57
57
this ._hub, {
@@ -109,18 +109,24 @@ class SentryTracer extends ISentrySpan {
109
109
}
110
110
111
111
var _rootEndTimestamp = commonEndTimestamp;
112
+
113
+ // Trim the end timestamp of the transaction to the very last timestamp of child spans
112
114
if (_trimEnd && children.isNotEmpty) {
113
- final childEndTimestamps = children
114
- . where ((child) => child.endTimestamp != null )
115
- . map (( child) => child.endTimestamp ! );
116
-
117
- if (childEndTimestamps.isNotEmpty ) {
118
- final oldestChildEndTimestamp =
119
- childEndTimestamps. reduce ((a, b) => a .isAfter (b) ? a : b);
120
- if (_rootEndTimestamp. isAfter (oldestChildEndTimestamp)) {
121
- _rootEndTimestamp = oldestChildEndTimestamp;
115
+ DateTime ? latestEndTime;
116
+
117
+ for ( var child in children) {
118
+ final childEndTimestamp = child.endTimestamp;
119
+ if (childEndTimestamp != null ) {
120
+ if (latestEndTime == null ||
121
+ childEndTimestamp .isAfter (latestEndTime)) {
122
+ latestEndTime = child.endTimestamp;
123
+ }
122
124
}
123
125
}
126
+
127
+ if (latestEndTime != null ) {
128
+ _rootEndTimestamp = latestEndTime;
129
+ }
124
130
}
125
131
126
132
// the callback should run before because if the span is finished,
@@ -362,7 +368,8 @@ class SentryTracer extends ISentrySpan {
362
368
Dsn .parse (_hub.options.dsn! ).publicKey,
363
369
release: _hub.options.release,
364
370
environment: _hub.options.environment,
365
- userId: null , // because of PII not sending it for now
371
+ userId: null ,
372
+ // because of PII not sending it for now
366
373
userSegment: user? .segment,
367
374
transaction:
368
375
_isHighQualityTransactionName (transactionNameSource) ? name : null ,
0 commit comments