Skip to content

fix: drop canceled tab navigation spans and add Inbox span context attributes#95480

Merged
JS00001 merged 4 commits into
Expensify:mainfrom
callstack-internal:fix/inbox-tab-span-telemetry
Jul 9, 2026
Merged

fix: drop canceled tab navigation spans and add Inbox span context attributes#95480
JS00001 merged 4 commits into
Expensify:mainfrom
callstack-internal:fix/inbox-tab-span-telemetry

Conversation

@BartekObudzinski

@BartekObudzinski BartekObudzinski commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

The tab-navigation spans (ManualNavigateToInboxTab, ManualNavigateToReports*) contain events that don't measure a navigation. The big one: abandoned navigations are canceled but still sent with status OK and wall-clock durations, so a span canceled after the laptop wakes up records the whole absence. In production that's up to 2-hour "navigations", under 1% of web events but 61% of recorded time (web avg 1250ms with them, ~420ms without). On top of that, wide vs narrow layouts (~3x cost difference) and warm re-focuses (~30ms) vs cold mounts (~150ms) were indistinguishable in the data.

The fix:

  • canceledTabNavigationFilter drops canceled tab-navigation spans in beforeSend. It only matches events with a tab-navigation op AND the canceled attribute (set exclusively by cancelSpan), so a completed navigation can never be dropped. Unit-tested.
  • New attributes on the Inbox span for honest slicing: wide_layout, skeleton_shown (navigation raced app startup), and is_warm (mirrors the Reports span). Verified live on web.
  • Removed dead render-duration instrumentation from useSidebarOrderedReports (write-only, nothing consumed it).

Note for metric consumers: the four tab-navigation metrics shift definitionally at merge (e.g. Inbox blended p90 ~-40ms, avg ~-60%), so baselines reset from the merge date. The only signal lost is the count of canceled tab navigations, dominated by benign tab-switching.

Fixed Issues

$ #95489
PROPOSAL:

Tests

  1. Open the web app with the DevTools console open.
  2. Navigate to the Reports tab, then click the Inbox tab. Verify a console line [Sentry][ManualNavigateToInboxTab] Ending span appears and its logged attributes include wide_layout (true on wide layouts, false on narrow) and is_warm: false on the first visit.
  3. On a narrow layout, switch to Reports and back to Inbox. Verify the span logged for the warm return has is_warm: true. (On wide layouts the sidebar remounts on every visit, so is_warm stays false — this is expected, not a warm re-focus.)
  4. Click the Inbox tab and immediately click the Reports tab before Inbox finishes loading. Verify the console shows the Inbox span being canceled and that no ManualNavigateToInboxTab transaction with canceled: true is sent in the Sentry envelope requests (Network tab).
  5. Verify Inbox and Reports tab navigation still works normally on narrow and wide layouts.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

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.

Files with missing lines Coverage Δ
src/CONST/index.ts 93.33% <ø> (ø)
src/hooks/useInboxTabSpanLifecycle.ts 100.00% <100.00%> (ø)
src/hooks/useSidebarOrderedReports.tsx 90.66% <100.00%> (-1.10%) ⬇️
src/libs/telemetry/cancelTabNavigationSpans.ts 100.00% <ø> (ø)
...lemetry/middlewares/canceledTabNavigationFilter.ts 100.00% <100.00%> (ø)
src/pages/inbox/sidebar/BaseSidebarScreen.tsx 100.00% <100.00%> (ø)
src/pages/inbox/sidebar/SidebarLinksData.tsx 100.00% <100.00%> (ø)
...nts/Navigation/NavigationTabBar/InboxTabButton.tsx 26.31% <0.00%> (ø)
src/libs/telemetry/middlewares/index.ts 0.00% <0.00%> (ø)
... and 31 files with indirect coverage changes

@BartekObudzinski BartekObudzinski marked this pull request as ready for review July 7, 2026 13:14
@BartekObudzinski BartekObudzinski requested review from a team as code owners July 7, 2026 13:14
@melvin-bot melvin-bot Bot requested review from marufsharifi and removed request for a team July 7, 2026 13:14
@melvin-bot

melvin-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

@marufsharifi 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]

@melvin-bot melvin-bot Bot requested review from flaviadefaria and removed request for a team July 7, 2026 13:14
@marufsharifi

marufsharifi commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp

Not Applicable.

Android: mWeb Chrome

Not Applicable.

iOS: HybridApp

Not Applicable.

iOS: mWeb Safari

Not Applicable.

MacOS: Chrome / Safari
Screencast.From.2026-07-08.22-00-49.mp4

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c4f172eaa

ℹ️ 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".

Comment thread src/hooks/useInboxTabSpanLifecycle.ts
@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

Hi @marufsharifi How's the things going?

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Review: LGTM — the change is correct, well-scoped, and well-tested. I verified the risky bits locally against 0c4f172.

What I checked

  • ✅ Both test suites pass locally (13 tests): canceledTabNavigationFilterTest.ts + useInboxTabSpanLifecycle.test.ts. The new test file uses the …FilterTest.ts name — confirmed it's still picked up by Jest's tests/unit/**/* glob.
  • useCallback removal in useInboxTabSpanLifecycle is safe. Dropping useCallback around the useFocusEffect/onLayout callbacks would normally re-run the focus effect (cancel + re-end the span) on every re-render. I ran the React Compiler compliance check and the file COMPILED, so the inline callbacks are auto-memoized — equivalent to the old useCallback([]). No behavior change. (useInboxTabSpanLifecycle.ts:33)
  • Dead-code removal is complete. No remaining references to componentsUsingHook, useSidebarOrderedReportsPerformance, renderDuration, or hookDuration, and all useSidebarOrderedReportsState() / useSidebarOrderedReports() callers were updated to drop the componentName arg. No imports left unused.
  • {isWideLayout: false} in the narrow path is correct, not a hardcoded miss — it only runs after the if (isWideLayout) return <WideInboxTabButton/> guard (which passes true). (InboxTabButton.tsx:183)
  • canceledTabNavigationFilter faithfully mirrors minDurationFilter (root-transaction check + child-span filter), and the drop is justified: cancelSpan sets canceled + SPAN_STATUS_OK and ends the span, so canceled navigations are sent to Sentry with full wall-clock duration today. The op+canceled double-guard means a completed navigation can never be dropped.
Minor notes (non-blocking)
  1. useSidebarOrderedReports.tsx still fails the React Compiler compliance check (7 errors, all "Cannot access refs during render" from the hasDraftByReportIDRef-in-useMemo pattern at line 271). This is pre-existing — that pattern isn't touched by this PR, and the PR only removes code from the file. Not a regression, and the author added an explanatory comment. CI's check-changed should be fine as long as the file was already non-compiling on main.
  2. When a canceled tab-nav span is the root transaction, returning null drops the whole transaction, including any child spans (e.g. http.client) recorded during it. That's intended for an abandoned navigation, just flagging the side effect.
  3. skeleton_shown is stamped on whatever inbox-tab span is currently active (BaseSidebarScreen.tsx:50). In a rare race it could attribute to a different navigation's span, but impact on telemetry is negligible.
  4. As the author already called out, the only signal lost is the count of canceled tab navigations — acceptable given it's dominated by benign tab-switching.

I did not run the full typecheck/lint suite; signatures (endSpanWithAttributes, startNavigateToInboxTabSpan) line up and read clean, but CI is the source of truth there.

@marufsharifi

Copy link
Copy Markdown
Contributor

@BartekObudzinski, I am still testing; I will update here in a few hours. thanks.

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

thank you!

@marufsharifi

Copy link
Copy Markdown
Contributor

@BartekObudzinski, could you please take a look at this? For the second visit, is_warm is still showing as false.

RF-1.webm
RF-2

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

Thanks for testing this! This is expected on wide layout rather than a bug.

On wide layout the Inbox sidebar is re-mounted on every tab navigation, so each visit is a full cold mount (~180ms) — there's no cached layout to re-focus, so is_warm is correctly false. The warm path only applies where the screen instance is preserved: on narrow layout (and native), where react-freeze keeps it mounted. I measured a narrow warm return at ~11ms with is_warm: true vs ~360ms cold, so it works there.

The wide_layout attribute already lets us separate the two cohorts in Sentry, so wide (always cold) stays distinguishable from narrow/native (cold vs warm).

@marufsharifi

Copy link
Copy Markdown
Contributor

Reload the app and click the Inbox tab while the app-loading skeleton is visible. Verify the resulting span has skeleton_shown: true.

pr-95480-05.webm

@BartekObudzinski, I don't see skeleton_shown after reload. Is this a bug? thanks.

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

@marufsharifi Not a bug, this is my test step 5 being inaccurate, sorry my bad. The app-loading skeleton (isLoadingApp) only shows during the initial OpenApp; reloading an existing session runs reconnectApp, which never shows that skeleton, and hasEverFinishedLoading latches after the first load so it can't reappear. skeleton_shown targets the genuine cold-start: first app open that lands on another tab, then tapping Inbox while the initial load is still in flight. I'll correct step 5 to reflect that.

@melvin-bot melvin-bot Bot requested a review from JS00001 July 9, 2026 11:08
@marufsharifi

Copy link
Copy Markdown
Contributor

LGTM

@JS00001 JS00001 merged commit 916481a into Expensify:main Jul 9, 2026
41 of 42 checks passed
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🚧 JS00001 has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.33-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 cancelled 🔪

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 No help site changes required.

I reviewed the changes in this PR against Expensify's help site content in App/docs/articles, and no documentation updates are needed. No draft PR was created.

Why: every change here is internal Sentry/telemetry instrumentation with no user-facing impact:

  • New span attribute keys in src/CONST/index.ts (wide_layout, skeleton_shown) used only for slicing performance data
  • A beforeSend middleware (canceledTabNavigationFilter) that drops abandoned tab-navigation spans before they're sent to Sentry
  • Span-lifecycle attribute tagging (is_warm, skeleton_shown) on the Inbox navigation span
  • Removal of dead render-duration instrumentation in useSidebarOrderedReports

The help site documents customer-facing product behavior — features, tabs, settings labels, buttons, and workflows. This PR changes none of those; it only affects how the app records internal performance telemetry, which is invisible to end users and not covered by any help article.

@BartekObudzinski, no linked help site PR was created since no docs changes are required. If you believe any user-facing behavior did change here that should be documented, let me know and I'll draft the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants