Skip to content

Commit 4dedf37

Browse files
committed
Update sentry tracer
1 parent 87d2755 commit 4dedf37

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

dart/lib/src/sentry_tracer.dart

+15-9
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,24 @@ class SentryTracer extends ISentrySpan {
109109
}
110110

111111
var _rootEndTimestamp = commonEndTimestamp;
112+
113+
// Trim the end timestamp of the transaction to the very last timestamp of child spans
112114
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+
}
122124
}
123125
}
126+
127+
if (latestEndTime != null) {
128+
_rootEndTimestamp = latestEndTime;
129+
}
124130
}
125131

126132
// the callback should run before because if the span is finished,

0 commit comments

Comments
 (0)