Skip to content

[Performance] Extend submit-to-destination-visible span with diagnostic attributes #92359

Closed
JakubKorytko wants to merge 6 commits into
Expensify:mainfrom
software-mansion-labs:korytko/perf/extend-submit-to-destination-attributes
Closed

[Performance] Extend submit-to-destination-visible span with diagnostic attributes #92359
JakubKorytko wants to merge 6 commits into
Expensify:mainfrom
software-mansion-labs:korytko/perf/extend-submit-to-destination-attributes

Conversation

@JakubKorytko

Copy link
Copy Markdown
Contributor

Explanation of Change

Extends the submit-to-destination-visible Sentry span with diagnostic attributes to investigate 6 production issues identified from trace analysis:

What I've observed (from 11 Sentry traces):

  1. default handler fallback hit unexpectedly when fast paths should match - 40-50s blocked JS thread, likely caused by tab navigator state being temporarily unavailable during HybridApp remounts (ce57bcb9, d0c23d02, 2a89ae3d, 9789e05e)
  2. report_pre_insert route lost after dismiss - user lands on LHN instead of pre-inserted report, up to 34.8s manual navigation (ae1d8901, 3779d897, e7e05ac2)
  3. report_in_rhp_dismiss span never ends - onLayout doesn't re-fire when component is revealed after RHP screens are popped (b593642b, b0153d43)
  4. dismiss_modal on narrow layout - dismissModalWithReport returns willOpenReport=false unexpectedly (5bee564c)
  5. search_dismiss modal stays open after successful RequestMoney API call (1ffba096)

What this PR adds:

  • snapshot.* - records the full getSubmitHandler decision tree inputs so handler selection can be replayed from production spans
  • at_dismiss.* - captures split navigator and tab state at dismiss time, including form_has_been_submitted to detect the cleanup race in pre-insert flows
  • dismiss_narrow.* - records root route count, topmost fullscreen route, and will_open_report to explain narrow dismiss decisions
  • search_dismiss.* - adds after_transition_called and elapsed_ms to distinguish "dismiss was slow" from "create flow stayed open"
  • at_end.* - confirms whether the user landed on the expected destination report
  • FOCUS trigger on SearchMoneyRequestReportPage (direct fix for issue 3)

Fixed Issues

$
PROPOSAL: N/A

Tests

  1. Open the app on wide layout, navigate to the Search tab
  2. Tap the global create (+) button and submit a manual expense
  3. Verify that no errors appear in the JS console and the expense is created successfully
  4. Open the Sentry dev tools or React Native dev menu and inspect the ManualSubmitToDestinationVisible span
  5. Verify it contains snapshot.* attributes (e.g. snapshot.is_search_topmost_fullscreen: true), search_dismiss.* attributes, and at_end.* attributes

  1. On narrow layout (or phone), open an existing report chat
  2. Tap (+) and submit a manual expense from that report
  3. Verify the expense is created and you return to the report
  4. Inspect the span and verify it contains dismiss_narrow.* attributes (e.g. dismiss_narrow.will_open_report, dismiss_narrow.root_route_count)

  1. On any layout, open the app from the Settings/Account tab
  2. Tap global create (+) and submit a manual expense
  3. Verify the expense is created and you are navigated to Search
  4. Inspect the span and verify fast_path_handler and at_end.* attributes are present

Offline tests

N/A - changes are purely additive telemetry attributes on an existing Sentry span. No API calls, data fetching, or Onyx operations are modified.

QA Steps

Same as tests - verify expense submission works correctly on all platforms. The diagnostic span attributes are only visible in Sentry/dev tools and do not affect user-facing behavior.

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 shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • 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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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

@JakubKorytko

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

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

@codecov

codecov Bot commented Jun 2, 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.79% <ø> (ø)
.../iou/request/step/confirmation/getSubmitHandler.ts 100.00% <100.00%> (ø)
...st/step/confirmation/getTabNavigatorDiagnostics.ts 100.00% <100.00%> (ø)
src/pages/Search/SearchMoneyRequestReportPage.tsx 0.00% <0.00%> (ø)
...es/iou/request/step/IOURequestStepConfirmation.tsx 64.01% <0.00%> (-0.21%) ⬇️
...st/step/confirmation/SubmitExpenseOrchestrator.tsx 58.75% <38.46%> (-2.68%) ⬇️
src/libs/telemetry/submitFollowUpAction.ts 33.72% <8.00%> (-3.87%) ⬇️
...quest/step/confirmation/submitDismissStrategies.ts 72.82% <7.40%> (-27.18%) ⬇️
... and 13 files with indirect coverage changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends the existing submit-to-destination-visible telemetry span with additional diagnostic attributes to help identify why some submit flows stall or land on unexpected destinations, and adds a focus-based span-end trigger to cover cases where layout does not re-fire after RHP transitions.

Changes:

  • Add snapshot.*, at_dismiss.*, dismiss_narrow.*, search_dismiss.*, and at_end.* span attributes to capture navigation state/timing at key points in the submit/dismiss flow.
  • Add a FOCUS trigger usage on SearchMoneyRequestReportPage to end the span when the screen is revealed after RHP screens are popped.
  • Introduce getTabNavigatorDiagnostics helper and telemetry helpers (hasSubmitSpan, setSubmitSpanAttributes, getTrackingElapsedMs) to support consistent attribute recording.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit/submitDismissStrategiesTest.ts Updates telemetry mocks to include new helpers used by dismiss strategies.
src/pages/Search/SearchMoneyRequestReportPage.tsx Adds a focus-based submit-to-visible trigger to handle “revealed after pop” cases.
src/pages/iou/request/step/IOURequestStepConfirmation.tsx Wires hasFormBeenSubmitted() callback into the orchestrator for dismiss-time diagnostics.
src/pages/iou/request/step/confirmation/SubmitExpenseOrchestrator.tsx Records snapshot + search-dismiss + dismiss-time span diagnostics during submit orchestration.
src/pages/iou/request/step/confirmation/submitDismissStrategies.ts Adds narrow-dismiss diagnostics and exports buildAtDismissAttributes() for report pre-insert investigation.
src/pages/iou/request/step/confirmation/getTabNavigatorDiagnostics.ts New helper to read TAB_NAVIGATOR availability/active tab/nested state for telemetry.
src/pages/iou/request/step/confirmation/getSubmitHandler.ts Adds buildSnapshotAttributes() to serialize handler decision inputs into span attributes.
src/libs/telemetry/submitFollowUpAction.ts Adds submit-span helpers and at_end.* attributes when ending the span.
src/CONST/index.ts Adds submit span attribute prefixes and an ATTRIBUTE_VALUE_UNAVAILABLE sentinel.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/iou/request/step/confirmation/submitDismissStrategies.ts
@JakubKorytko

Copy link
Copy Markdown
Contributor Author

⚠️ failing Knip check should be ignored. I've asked @shubham1206agra who added the Knip package to codebase what should I do in case of unlisted @sentry/core and he said to ignore it instead of adding bad workaround.

See: slack convo

@JakubKorytko JakubKorytko requested a review from Copilot June 2, 2026 13:31
@JakubKorytko

Copy link
Copy Markdown
Contributor Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

@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: 7d501bd0c4

ℹ️ 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/pages/Search/SearchMoneyRequestReportPage.tsx
@JakubKorytko

Copy link
Copy Markdown
Contributor Author

@codex review

@JakubKorytko JakubKorytko requested a review from Copilot June 2, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

return TAB_NAVIGATOR_UNAVAILABLE;
}

const topmostTabNavigatorRoute = rootState.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR);
Comment on lines +35 to +41
const activeRoute = topmostTabNavigatorRoute.state.routes?.at(index);
const nestedState = activeRoute?.state;
return {
tabNavigatorStateAvailable: true,
tabActiveName: activeRoute?.name,
activeTabState: nestedState && 'routes' in nestedState ? (nestedState as NavigationState) : undefined,
};
Comment on lines +188 to +192
const topmostReportID = getTopmostReportParams(rootState)?.reportID;
if (topmostReportID) {
attrs[`${prefix}topmost_report_id`] = topmostReportID;
}
attrs[`${prefix}report_id_matches`] = reportID !== undefined && topmostReportID === reportID;
Comment on lines +186 to +190
const params = lastSplitRoute.params as Record<string, unknown> | undefined;
const reportID = typeof params?.reportID === 'string' ? params.reportID : undefined;
if (reportID) {
attrs[`${prefix}split_last_report_id`] = reportID;
}

@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: d3de120950

ℹ️ 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 on lines +89 to +93
useSubmitToDestinationVisible(
[CONST.TELEMETRY.SUBMIT_FOLLOW_UP_ACTION.DISMISS_MODAL_AND_OPEN_REPORT, CONST.TELEMETRY.SUBMIT_FOLLOW_UP_ACTION.DISMISS_MODAL_ONLY],
reportIDFromRoute,
CONST.TELEMETRY.SUBMIT_TO_DESTINATION_VISIBLE_TRIGGER.FOCUS,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Delay the focus trigger until the report is actually visible

When this page is newly mounted or revealed while an RHP pop animation is still running, this focus-based trigger can fire before the existing onLayout trigger and before the destination is actually visible; React Navigation's useFocusEffect docs note focus effects may run before transition animations finish. Because endSubmitFollowUpActionSpan clears the pending action on the first trigger, the later layout callback cannot correct the measurement, so submit-to-destination-visible spans for these Search money-request reports will under-report the transition time and hide the slow paths this diagnostic is trying to investigate.

Useful? React with 👍 / 👎.

@JakubKorytko

Copy link
Copy Markdown
Contributor Author

Closing in favor of #93452

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.

2 participants