Skip to content

Commit ac7b98a

Browse files
authored
Merge branch 'main' into feat/apply-before-breadcrumb-on-native-crumbs
2 parents 2d279b2 + 202b83f commit ac7b98a

File tree

4 files changed

+72
-42
lines changed

4 files changed

+72
-42
lines changed

.github/workflows/analyze.yml

+30-33
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,33 @@ jobs:
5151

5252
- run: dart doc --dry-run
5353

54-
# Currently Disabled because of git error `detected dubious ownership in repository.
55-
# TODO: check if this is still an issue when git version in github runners is updated
56-
#
57-
# package-analysis:
58-
# # `axel-op/dart-package-analyzer` is using `flutter pub upgrade` instead of `get`,
59-
# # which ignores pubspec.yaml `dependency_overrides`. Because of that, all `release/*` branches are failing,
60-
# # because the package cannot find the "about to be released" version of our sentry-dart package that it depends on.
61-
# if: ${{ !startsWith(github.ref, 'refs/heads/release/') && inputs.panaThreshold > 0 }}
62-
# runs-on: ubuntu-20.04
63-
# timeout-minutes: 20
64-
# steps:
65-
# - uses: actions/checkout@v4
66-
# - name: Apply dependency override
67-
# if: ${{ inputs.package == 'flutter' }}
68-
# working-directory: ${{ inputs.package }}
69-
# run: |
70-
# sed -i.bak 's|sentry:.*|sentry:\n path: /github/workspace/dart|g' pubspec.yaml
71-
# - uses: axel-op/dart-package-analyzer@7a6c3c66bce78d82b729a1ffef2d9458fde6c8d2 # pin@v3
72-
# id: analysis
73-
# with:
74-
# githubToken: ${{ secrets.GITHUB_TOKEN }}
75-
# relativePath: ${{ inputs.package }}
76-
# - name: Check scores
77-
# env:
78-
# TOTAL: ${{ steps.analysis.outputs.total }}
79-
# TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
80-
# run: |
81-
# PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
82-
# if (( $PERCENTAGE < ${{ inputs.panaThreshold }} ))
83-
# then
84-
# echo Score too low!
85-
# exit 1
86-
# fi
54+
package-analysis:
55+
# `axel-op/dart-package-analyzer` is using `flutter pub upgrade` instead of `get`,
56+
# which ignores pubspec.yaml `dependency_overrides`. Because of that, all `release/*` branches are failing,
57+
# because the package cannot find the "about to be released" version of our sentry-dart package that it depends on.
58+
if: ${{ !startsWith(github.ref, 'refs/heads/release/') && inputs.panaThreshold > 0 }}
59+
runs-on: ubuntu-20.04
60+
timeout-minutes: 20
61+
steps:
62+
- uses: actions/checkout@v4
63+
- name: Apply dependency override
64+
if: ${{ inputs.package == 'flutter' }}
65+
working-directory: ${{ inputs.package }}
66+
run: |
67+
sed -i.bak 's|sentry:.*|sentry:\n path: /github/workspace/dart|g' pubspec.yaml
68+
- uses: axel-op/dart-package-analyzer@d9b13539ce28b8a2f85605379ce8670209d571e8 # pin@v3
69+
id: analysis
70+
with:
71+
githubToken: ${{ secrets.GITHUB_TOKEN }}
72+
relativePath: ${{ inputs.package }}
73+
- name: Check scores
74+
env:
75+
TOTAL: ${{ steps.analysis.outputs.total }}
76+
TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
77+
run: |
78+
PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
79+
if (( $PERCENTAGE < ${{ inputs.panaThreshold }} ))
80+
then
81+
echo Score too low!
82+
exit 1
83+
fi

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

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+
510
### Features
611

712
- Use `recordHttpBreadcrumbs` to set iOS `enableNetworkBreadcrumbs` ([#1884](https://github.com/getsentry/sentry-dart/pull/1884))

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 (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+
}
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,

dart/test/sentry_tracer_test.dart

+22
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,28 @@ void main() {
386386
expect(sut.endTimestamp, endTimestamp);
387387
});
388388

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+
389411
test('does not add more spans than configured in options', () async {
390412
fixture.hub.options.maxSpans = 2;
391413
final sut = fixture.getSut();

0 commit comments

Comments
 (0)