diff --git a/CHANGELOG.md b/CHANGELOG.md index 92aa7ff3fb..56aae44b59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +* Filter out app starts with more than 60s (#895) + ## 6.6.0 ### Fixes diff --git a/flutter/lib/src/event_processor/native_app_start_event_processor.dart b/flutter/lib/src/event_processor/native_app_start_event_processor.dart index abc4be6692..4affebb40e 100644 --- a/flutter/lib/src/event_processor/native_app_start_event_processor.dart +++ b/flutter/lib/src/event_processor/native_app_start_event_processor.dart @@ -8,6 +8,9 @@ import '../sentry_native_channel.dart'; /// EventProcessor that enriches [SentryTransaction] objects with app start /// measurement. class NativeAppStartEventProcessor extends EventProcessor { + /// We filter out App starts more than 60s + static const _maxAppStartMillis = 60000; + NativeAppStartEventProcessor( this._native, ); @@ -22,9 +25,22 @@ class NativeAppStartEventProcessor extends EventProcessor { event is SentryTransaction && !_native.didFetchAppStart) { final nativeAppStart = await _native.fetchNativeAppStart(); - if (nativeAppStart != null) { - event.measurements.add(nativeAppStart.toMeasurement(appStartEnd)); + if (nativeAppStart == null) { + return event; + } + final measurement = nativeAppStart.toMeasurement(appStartEnd); + // We filter out app start more than 60s. + // This could be due to many different reasons. + // If you do the manual init and init the SDK too late and it does not + // compute the app start end in the very first Screen. + // If the process starts but the App isn't in the foreground. + // If the system forked the process earlier to accelerate the app start. + // And some unknown reasons that could not be reproduced. + // We've seen app starts with hours, days and even months. + if (measurement.value >= _maxAppStartMillis) { + return event; } + event.measurements.add(measurement); } return event; } diff --git a/flutter/test/integrations/native_app_start_integration_test.dart b/flutter/test/integrations/native_app_start_integration_test.dart index 964ffacfe5..56222d999f 100644 --- a/flutter/test/integrations/native_app_start_integration_test.dart +++ b/flutter/test/integrations/native_app_start_integration_test.dart @@ -79,6 +79,22 @@ void main() { expect(secondEnriched.measurements.length, 2); expect(secondEnriched.measurements.contains(measurement), true); }); + + test('native app start measurement not added if more than 60s', () async { + fixture.options.autoAppStart = false; + fixture.native.appStartEnd = DateTime.fromMillisecondsSinceEpoch(60001); + fixture.wrapper.nativeAppStart = NativeAppStart(0, true); + + fixture.getNativeAppStartIntegration().call(MockHub(), fixture.options); + + final tracer = fixture.createTracer(); + final transaction = SentryTransaction(tracer); + + final processor = fixture.options.eventProcessors.first; + final enriched = await processor.apply(transaction) as SentryTransaction; + + expect(enriched.measurements.isEmpty, true); + }); }); }