From 85eb41b93bc6034bf8196f9d47b17462ae760923 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 22 Jun 2022 21:27:23 +0200 Subject: [PATCH 1/2] Filter out app start with more than 60s --- CHANGELOG.md | 5 +++ src/js/tracing/reactnativetracing.ts | 9 +++++ test/tracing/reactnativetracing.test.ts | 46 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb280255f3..46affcbf8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Filter out app start with more than 60s ([#2303](https://github.com/getsentry/sentry-react-native/pull/2303)) + ## 4.0.0 - Bump Sentry Cocoa 7.18.0 ([#2303](https://github.com/getsentry/sentry-react-native/pull/2303)) @@ -16,6 +20,7 @@ ## 4.0.0-beta.4 - Bump Sentry Cocoa 7.17.0 ([#2300](https://github.com/getsentry/sentry-react-native/pull/2300)) + - [changelog](https://github.com/getsentry/sentry-cocoa/blob/7.17.0/CHANGELOG.md) - [diff](https://github.com/getsentry/sentry-cocoa/compare/7.16.1...7.17.0) diff --git a/src/js/tracing/reactnativetracing.ts b/src/js/tracing/reactnativetracing.ts index ed235603bb..824d38653c 100644 --- a/src/js/tracing/reactnativetracing.ts +++ b/src/js/tracing/reactnativetracing.ts @@ -110,6 +110,8 @@ export class ReactNativeTracing implements Integration { * @inheritDoc */ public static id: string = 'ReactNativeTracing'; + /** We filter out App starts more than 60s */ + private static _maxAppStart: number = 60000; /** * @inheritDoc */ @@ -294,6 +296,13 @@ export class ReactNativeTracing implements Integration { const appStartDurationMilliseconds = this._appStartFinishTimestamp * 1000 - appStart.appStartTime; + // we filter out app start more than 60s. + // this could be due to many different reasons. + // we've seen app starts with hours, days and even months. + if (appStartDurationMilliseconds >= ReactNativeTracing._maxAppStart) { + return; + } + transaction.setMeasurement(appStartMode, appStartDurationMilliseconds); } diff --git a/test/tracing/reactnativetracing.test.ts b/test/tracing/reactnativetracing.test.ts index b7430f80ba..f6ddc5069d 100644 --- a/test/tracing/reactnativetracing.test.ts +++ b/test/tracing/reactnativetracing.test.ts @@ -165,6 +165,52 @@ describe('ReactNativeTracing', () => { }); }); + it('Does not add app start measurement if more than 60s', (done) => { + const integration = new ReactNativeTracing(); + + const timeOriginMilliseconds = Date.now(); + const appStartTimeMilliseconds = timeOriginMilliseconds - 65000; + const mockAppStartResponse: NativeAppStartResponse = { + isColdStart: false, + appStartTime: appStartTimeMilliseconds, + didFetchAppStart: false, + }; + + mockFunction(getTimeOriginMilliseconds).mockReturnValue( + timeOriginMilliseconds + ); + // eslint-disable-next-line @typescript-eslint/unbound-method + mockFunction(NATIVE.fetchNativeAppStart).mockResolvedValue( + mockAppStartResponse + ); + + const mockHub = getMockHub(); + integration.setupOnce(addGlobalEventProcessor, () => mockHub); + + // use setImmediate as app start is handled inside a promise. + setImmediate(() => { + const transaction = mockHub.getScope()?.getTransaction(); + + expect(transaction).toBeDefined(); + + jest.runOnlyPendingTimers(); + + if (transaction) { + expect( + // @ts-ignore access private for test + transaction._measurements?.app_start_warm + ).toBeUndefined(); + + expect( + // @ts-ignore access private for test + transaction._measurements?.app_start_cold + ).toBeUndefined(); + + done(); + } + }); + }); + it('Does not create app start transaction if didFetchAppStart == true', (done) => { const integration = new ReactNativeTracing(); From d7ace61cc080480ac078e3e1bde498c4a6bac657 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Thu, 23 Jun 2022 08:28:43 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md Co-authored-by: Bruno Garcia --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46affcbf8d..c97d7876c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,6 @@ ## 4.0.0-beta.4 - Bump Sentry Cocoa 7.17.0 ([#2300](https://github.com/getsentry/sentry-react-native/pull/2300)) - - [changelog](https://github.com/getsentry/sentry-cocoa/blob/7.17.0/CHANGELOG.md) - [diff](https://github.com/getsentry/sentry-cocoa/compare/7.16.1...7.17.0)