Skip to content

Add receipt capture-to-upload observability logging#94950

Merged
mountiny merged 13 commits into
Expensify:mainfrom
callstack-internal:durable-receipts-v2
Jul 9, 2026
Merged

Add receipt capture-to-upload observability logging#94950
mountiny merged 13 commits into
Expensify:mainfrom
callstack-internal:durable-receipts-v2

Conversation

@rinej

@rinej rinej commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

It is based on the initial PR -> #94212

Adds structured logging so we can follow a single receipt from capture through to upload. Each receipt gets a unique trace id at capture time, and we log [Receipt] lines at three points: captured, submitted to the API, and enqueued in the network queue. We also log a snapshot of any still-pending receipts at sign-out, app backgrounding, and foregrounding.

The trace id and transaction id are also sent to Sentry as a breadcrumb and tag, so if the app crashes mid-upload the crash report shows the receipt's trail.

Fixed Issues

$ #92139
PROPOSAL:

Tests

This PR is logging-only - no user-facing behavior change.

  • Capture a receipt (camera or gallery) and submit it. Verify the expense is created and the image is attached.
  • Open the JS console (web DevTools, or adb logcat/Safari Web Inspector on native) and filter for [Receipt]. After step 1 confirm three lines appear: event: captured, event: submitted, event: enqueued, all carrying the same receiptTraceId.
  • Capture another receipt while offline, then sign out. Confirm a [Receipt] queue snapshot line is emitted with trigger: signOut.

Offline tests

QA Steps

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

LogsReceipts.mp4
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

adhorodyski and others added 2 commits June 30, 2026 12:52
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rinej

rinej commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@rinej
rinej marked this pull request as ready for review June 30, 2026 12:35
@rinej
rinej requested review from a team as code owners June 30, 2026 12:35
@melvin-bot
melvin-bot Bot requested review from heyjennahay and mkhutornyi and removed request for a team June 30, 2026 12:36
@melvin-bot

melvin-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

@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: 88b51f71d2

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

isMultiScanEnabled,
transactions,
draftTransactionIDsToCleanUp,
captureSource = 'file',

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 Preserve the real capture source

When this helper is used from the scan camera's onCapture path or the gallery/file picker's onPicked path, none of the call sites pass captureSource, so every new receipt is logged as captureSource: 'file'. That makes camera and gallery captures indistinguishable/mislabeled in the new [Receipt] captured telemetry, which undermines the capture-source analysis this instrumentation is meant to support; please pass the source from the camera/picker call sites instead of defaulting all captures to file.

Useful? React with 👍 / 👎.

Comment on lines +34 to +37
WRITE_COMMANDS.SPLIT_BILL,
WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT,
WRITE_COMMANDS.START_SPLIT_BILL,
WRITE_COMMANDS.COMPLETE_SPLIT_BILL,

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 Exclude receiptless split commands

For offline/manual split bills using SplitBill, SplitBillAndOpenReport, or CompleteSplitBill, the request params written by Split.ts don't include a receipt, but adding these commands to the receipt-bearing set makes push() and queue snapshots emit [Receipt] logs with no trace id for ordinary split requests. That pollutes the pending-receipt trail with non-receipt queue entries; either filter on data.receipt before logging/snapshotting or keep only commands whose params actually carry the local receipt file.

Useful? React with 👍 / 👎.

@mkhutornyi

mkhutornyi commented Jun 30, 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
android.mov
Android: mWeb Chrome
iOS: HybridApp
ios.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

@codecov

codecov Bot commented Jun 30, 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/libs/DebugUtils.ts 68.76% <ø> (ø)
src/libs/Network/SequentialQueue.ts 86.61% <100.00%> (+0.20%) ⬆️
src/libs/actions/IOU/MoneyRequest.ts 67.46% <100.00%> (+0.33%) ⬆️
src/libs/actions/IOU/Receipt.ts 79.12% <100.00%> (+0.46%) ⬆️
src/libs/actions/Session/index.ts 42.03% <100.00%> (+0.12%) ⬆️
...equestStepScan/components/ScanSkipConfirmation.tsx 76.92% <100.00%> (ø)
...request/step/confirmation/ReceiptFileValidator.tsx 60.00% <ø> (ø)
src/libs/telemetry/forwardLogsToSentry.ts 86.44% <95.65%> (+5.30%) ⬆️
...p/IOURequestStepScan/components/ScanFromReport.tsx 71.42% <50.00%> (ø)
...step/IOURequestStepScan/utils/buildReceiptFiles.ts 83.33% <75.00%> (-3.34%) ⬇️
... and 3 more
... and 9 files with indirect coverage changes

@mkhutornyi

Copy link
Copy Markdown
Contributor

Please address codex reviews and fix conflict

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Code review — receipt capture-to-upload observability logging

Overall this is a clean, well-documented, logging-only change with genuinely good test coverage (capture/snapshot behavior, the Sentry PII whitelist, and the end-to-end receiptTraceId pass-through). No correctness blockers found. A few things worth addressing before merge:


1. ~Half the diff is unrelated formatting churn — hurts reviewability. A large share of the +841/-89 is reformatting of lines the receipt feature never touches — e.g. dozens of untouched setMoneyRequest* helpers in MoneyRequest.ts and most of the participant-object edits in RequestMoneyTest.ts get expanded from one line to multi-line. The actual feature is only ~200 meaningful lines. This makes the substantive change hard to isolate and raises the odds of conflicts with other in-flight PRs. If this is just npm run fmt (oxfmt) reformatting whole files you opened, please confirm the formatter is clean and consider limiting the diff to lines the feature actually changes so reviewers can see the real surface area.

2. enqueuedAtByTransactionID is only pruned inside the snapshot path. ReceiptObservability.ts writes an entry on every enqueue but only drains stale keys inside logReceiptQueueSnapshot. A session that never backgrounds/foregrounds/signs out (e.g. a long-lived web tab) accumulates one entry per submitted receipt with no upper bound. Entries are tiny so impact is low, but consider pruning on successful drain or capping the map. (nit / low)

3. The Sentry param whitelist broadening is global, not [Receipt]-scoped. Adding event and transactionID to PARAMETERS_WHITELIST in forwardLogsToSentry.ts also forwards those keys for the other prefixes ([Reauthenticate], [MFA], [OnyxUpdateManagerError]). event is a very generic key — worth a conscious confirmation that no other forwarded log line carries an event/transactionID param you don't want in Sentry. (question)

Minor notes
  • Undefined-traceId noise: logReceiptSubmitted/logReceiptEnqueued still fire when receiptTraceId is undefined (a receipt created outside the mint path). The snapshot path deliberately skips non-correlatable rows — the submit/enqueue paths don't, so they can emit rows that can't be joined to a capture log. Minor inconsistency.
  • receipt in createTransaction is receiptFile.file ?? {}, so receipt.receiptTraceId can't throw — good.
  • Nice touches worth calling out: avoiding Sentry.setTag to prevent cross-crash tag contamination (well documented), restamping the trace id in ReceiptFileValidator after the file is rebuilt from disk, and including the ongoing-request slot in the snapshot.

Next Steps: Reply with @MelvinBot <feedback> to refine this review. This is an automated review — a human reviewer should still sign off.

@rinej

rinej commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@mkhutornyi I addressed the review feedback:

Formatting churn (MelvinBot 1) - Reverted the stray oxfmt object-expansion on untouched lines back to main's style across App.ts, MoneyRequest.ts, RequestMoneyTest.ts, SequentialQueue.ts, and the 3 Scan components

Unbounded timing map (MelvinBot 2) - enqueuedAtByTransactionID is now bounded by a cap (MAX_TRACKED_ENQUEUE_TIMESTAMPS = 100) in addition to the snapshot-path drain, so a long-lived session that never backgrounds/signs out can't grow it without bound

Sentry whitelist scope (MelvinBot 3) - event, transactionID, and receiptTraceId are no longer in the global PARAMETERS_WHITELIST; they're now in a prefix-scoped whitelist that only forwards them for [Receipt] lines. Also dded a regression test covering this

Codex P2s - both were already handled before - camera/gallery/replace paths now pass the real captureSource (no more everything-as-file), and receipt split commands are gated on data.receipt in both the enqueue and snapshot paths

Conflicts are also resolved 👍

@melvin-bot

melvin-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

We did not find an internal engineer to review this PR, trying to assign a random engineer to #92139 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@melvin-bot
melvin-bot Bot requested a review from cead22 July 6, 2026 17:03

@cead22 cead22 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.

  • Conflicts
  • Please test sign out, background, and foreground cases
  • With AI writing most code, we should strive to make our code comments very easy to understand. AI by default uses CAPS, ;, dashes, → , parenthesis, hyphenated words, and other words that aren't common to find in human written comments. Please update the code comments to make them easy to parse and understand by humans

@rinej

rinej commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

I resolved conflicts and I updated the comments as requested.

Pasting the recording for test for foreground/background and signOut:

Foreground Background:

BackgroundForeground.mp4

signOut:

SignOut.mp4

Also here we have the follow up PR which shows new modal and saves the receipt in the user gallery before signing out -> #94973

receipt?: {receiptTraceId?: string};
};
// Only log when there is a receipt at data.receipt. SplitBill nests it in the splits JSON, and SendMoney and
// friends can run without one. A row without a trace id cannot be joined to the capture log, so it is just noise.

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.

...SendMoney and friends can run without one.

I think this need to be either more precise or dropped? We should rather state that some commands do not have this appended.

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.

I mean the wording just seem to be too loose

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.

Yeah lets update this but I wont block on it @adhorodyski @rinej

}
}

// Save the request to the persisted queue. The in-memory update inside save()

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.

not sure why we're documenting it here, this promise is not related to the observability, right?

@mountiny mountiny 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.

Excited to see what these observability enhancments will bring us when debugging the flows

receipt?: {receiptTraceId?: string};
};
// Only log when there is a receipt at data.receipt. SplitBill nests it in the splits JSON, and SendMoney and
// friends can run without one. A row without a trace id cannot be joined to the capture log, so it is just noise.

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.

Yeah lets update this but I wont block on it @adhorodyski @rinej

Comment on lines +36 to +44
/**
* Write commands whose params can carry a captured receipt. A pending request with one of these commands is a receipt
* that has not reached the server yet. Keep this in sync with the durability slice so the two features agree on which
* queued requests own a local receipt file.
*/
const RECEIPT_BEARING_COMMANDS = new Set<string>([
WRITE_COMMANDS.REQUEST_MONEY,
WRITE_COMMANDS.TRACK_EXPENSE,
WRITE_COMMANDS.SPLIT_BILL,

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.

This was already in the other PR so I assume we need to clean these up now

@mountiny
mountiny merged commit 39fa722 into Expensify:main Jul 9, 2026
38 checks passed
marufsharifi pushed a commit to marufsharifi/App that referenced this pull request Jul 9, 2026
Add the required delegateAccountID field to the requestMoney call introduced in Expensify#94950.

Co-authored-by: Cursor <cursoragent@cursor.com>
@rinej

rinej commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@adhorodyski @mountiny
Based on your comments, I created follow up PR with the cleanup -> #95811

@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed the changes in this PR against Expensify's help site content under App/docs/articles.

No help site changes are required, and no draft PR was created.

This PR is logging/observability-only with no user-facing behavior change:

  • All changed files are internal telemetry/logging code — receipt trace IDs, [Receipt] structured log lines (captured → submitted → enqueued), a pending-receipt queue snapshot at sign-out/background/foreground, and Sentry breadcrumbs/tags — plus supporting tests.
  • Nothing alters a customer-facing feature, setting, label, tab, button, or user flow. The receipt capture/upload experience itself is unchanged.
  • Help site articles document customer-facing product behavior, so there is nothing here to add or update.

Since no docs update is needed, there is no linked help site PR to review. If you believe a user-facing behavior did change and should be documented, reply with @MelvinBot and point me to the specific behavior, and I'll create the draft PR.

@mitarachim

mitarachim commented Jul 13, 2026

Copy link
Copy Markdown

@rinej This PR is failing in step 2 because of a regression issue #95919

Screenshot 2026-07-13 at 7 42 06 AM

The issue is reproducible in: Web

Bug7206528_1783901735284.PR-WEB.mp4

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/lakchote in version: 9.4.33-8 🚀

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

Bundle Size Analysis (Sentry):

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.

8 participants