File tree 3 files changed +42
-9
lines changed
3 files changed +42
-9
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
+ ### Fixes
6
+
7
+ - Fix transaction end timestamp trimming ([ #1916 ] ( https://github.com/getsentry/sentry-dart/pull/1916 ) )
8
+ - Transaction end timestamps are now correctly trimmed to the latest child span end timestamp
9
+
5
10
### Features
6
11
7
12
- Use ` recordHttpBreadcrumbs ` to set iOS ` enableNetworkBreadcrumbs ` ([ #1884 ] ( https://github.com/getsentry/sentry-dart/pull/1884 ) )
Original file line number Diff line number Diff line change @@ -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 ( final 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,
Original file line number Diff line number Diff line change @@ -386,6 +386,28 @@ void main() {
386
386
expect (sut.endTimestamp, endTimestamp);
387
387
});
388
388
389
+ test ('end trimmed to latest child end timestamp' , () async {
390
+ final sut = fixture.getSut (trimEnd: true );
391
+ final rootEndInitial = getUtcDateTime ();
392
+ final childAEnd = rootEndInitial;
393
+ final childBEnd = rootEndInitial.add (Duration (seconds: 1 ));
394
+ final childCEnd = rootEndInitial;
395
+
396
+ final childA = sut.startChild ('operation-a' , description: 'description' );
397
+ final childB = sut.startChild ('operation-b' , description: 'description' );
398
+ final childC = sut.startChild ('operation-c' , description: 'description' );
399
+
400
+ await childA.finish (endTimestamp: childAEnd);
401
+ await childB.finish (endTimestamp: childBEnd);
402
+ await childC.finish (endTimestamp: childCEnd);
403
+
404
+ await sut.finish (endTimestamp: rootEndInitial);
405
+
406
+ expect (sut.endTimestamp, equals (childB.endTimestamp),
407
+ reason:
408
+ 'The root end timestamp should be updated to match the latest child end timestamp.' );
409
+ });
410
+
389
411
test ('does not add more spans than configured in options' , () async {
390
412
fixture.hub.options.maxSpans = 2 ;
391
413
final sut = fixture.getSut ();
You can’t perform that action at this time.
0 commit comments