[No QA] Fix infinite Sentry spans caused by app state transitions#84736
[No QA] Fix infinite Sentry spans caused by app state transitions#84736rlinoz merged 5 commits intoExpensify:mainfrom
Conversation
|
@ShridharGoel Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc618e543a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d162045fbe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ((AppState.currentState ?? CONST.APP_STATE.ACTIVE) !== CONST.APP_STATE.ACTIVE) { | ||
| return; |
There was a problem hiding this comment.
Preserve startup span when app launches from background
Returning early for any non-active app state drops spans entirely instead of closing them, which regresses startup telemetry for launch paths where React Native starts in background/inactive (the comment in src/libs/actions/App.ts already notes startup can be background). In those sessions, startSpan(CONST.TELEMETRY.SPAN_APP_STARTUP, ...) in src/setup/telemetry/index.native.ts no longer creates a span, so endSpan(CONST.TELEMETRY.SPAN_APP_STARTUP) in Expensify.onSplashHide cannot record startup duration at all; this silently removes data from performance traces rather than producing a canceled/finished span.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
We want to discard all spans created in background. This is desired behavior
There was a problem hiding this comment.
Yeah let's just test that we are still getting ManualAppStartup spans. I will run an adhoc build.
|
🚧 @rlinoz has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
not an emergency, I had already approved and Melvin re-requested my review and I didn't see it 🫠 |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 @rlinoz has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/rlinoz in version: 9.3.36-0 🚀
|
|
🚀 Deployed to production by https://github.com/luacmartins in version: 9.3.36-10 🚀
|


Explanation of Change
Sentry spans were being created and tracked even when the app was in background or inactive state, causing them to never close properly and pollute traces with falsely long durations.
Two fixes:
activeSpans.ts:startSpannow checksAppState.currentStatebefore creating a tracked span. If the app is not active, it creates a span, immediately marks it as cancelled, and ends it — so nothing lingers in the active spans map.App.ts: When the app returns to foreground (inactive/background → active),cancelAllSpans()is called to clean up any stale spans that may have been opened before the guard was in place or during edge-case transitions.Fixed Issues
$ #79653
PROPOSAL:
Tests
canceledvalueOffline tests
N/A
QA Steps
Same as tests
N/A
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari