Skip to content

Commit 3bfd365

Browse files
authored
Filter out app starts with more than 60s (#895)
1 parent 1f0b11b commit 3bfd365

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
* Filter out app starts with more than 60s (#895)
8+
39
## 6.6.0
410

511
### Fixes

flutter/lib/src/event_processor/native_app_start_event_processor.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import '../sentry_native_channel.dart';
88
/// EventProcessor that enriches [SentryTransaction] objects with app start
99
/// measurement.
1010
class NativeAppStartEventProcessor extends EventProcessor {
11+
/// We filter out App starts more than 60s
12+
static const _maxAppStartMillis = 60000;
13+
1114
NativeAppStartEventProcessor(
1215
this._native,
1316
);
@@ -22,9 +25,22 @@ class NativeAppStartEventProcessor extends EventProcessor {
2225
event is SentryTransaction &&
2326
!_native.didFetchAppStart) {
2427
final nativeAppStart = await _native.fetchNativeAppStart();
25-
if (nativeAppStart != null) {
26-
event.measurements.add(nativeAppStart.toMeasurement(appStartEnd));
28+
if (nativeAppStart == null) {
29+
return event;
30+
}
31+
final measurement = nativeAppStart.toMeasurement(appStartEnd);
32+
// We filter out app start more than 60s.
33+
// This could be due to many different reasons.
34+
// If you do the manual init and init the SDK too late and it does not
35+
// compute the app start end in the very first Screen.
36+
// If the process starts but the App isn't in the foreground.
37+
// If the system forked the process earlier to accelerate the app start.
38+
// And some unknown reasons that could not be reproduced.
39+
// We've seen app starts with hours, days and even months.
40+
if (measurement.value >= _maxAppStartMillis) {
41+
return event;
2742
}
43+
event.measurements.add(measurement);
2844
}
2945
return event;
3046
}

flutter/test/integrations/native_app_start_integration_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ void main() {
7979
expect(secondEnriched.measurements.length, 2);
8080
expect(secondEnriched.measurements.contains(measurement), true);
8181
});
82+
83+
test('native app start measurement not added if more than 60s', () async {
84+
fixture.options.autoAppStart = false;
85+
fixture.native.appStartEnd = DateTime.fromMillisecondsSinceEpoch(60001);
86+
fixture.wrapper.nativeAppStart = NativeAppStart(0, true);
87+
88+
fixture.getNativeAppStartIntegration().call(MockHub(), fixture.options);
89+
90+
final tracer = fixture.createTracer();
91+
final transaction = SentryTransaction(tracer);
92+
93+
final processor = fixture.options.eventProcessors.first;
94+
final enriched = await processor.apply(transaction) as SentryTransaction;
95+
96+
expect(enriched.measurements.isEmpty, true);
97+
});
8298
});
8399
}
84100

0 commit comments

Comments
 (0)