Repository navigation
[NOQA] Sentry: Add spans for expense creation flow #82287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcaaron
merged 5 commits into
Expensify:main
from
callstack-internal:sentry-create-expense-flow-improvements
Feb 19, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b4325bf
add scenario based submit expense span
OlimpiaZurek f008619
add post submit spans
OlimpiaZurek 494be11
add prefixes
OlimpiaZurek 4cacb3d
add comment to markSubmitExpenseEnd call
OlimpiaZurek 330ae99
address cr comments
OlimpiaZurek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import {WRITE_COMMANDS} from '@libs/API/types'; | ||
| import {cancelSpan, endSpan, getSpan, startSpan} from '@libs/telemetry/activeSpans'; | ||
| import CONST from '@src/CONST'; | ||
| import type Middleware from './types'; | ||
|
|
||
| /** | ||
| * Configuration for a tracked command group. | ||
| * Maps a set of write commands to a Sentry span operation name. | ||
| */ | ||
| type TrackedCommandGroup = { | ||
| /** Set of write commands that should be instrumented */ | ||
| commands: Set<string>; | ||
| /** Sentry span operation name */ | ||
| spanOp: string; | ||
| /** Human-readable span name */ | ||
| spanName: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Registry of command groups to instrument with server round-trip timing. | ||
| * Add new entries here to track additional flows without creating new middlewares. | ||
| */ | ||
| const TRACKED_COMMAND_GROUPS: TrackedCommandGroup[] = [ | ||
| { | ||
| commands: new Set<string>([ | ||
| WRITE_COMMANDS.REQUEST_MONEY, | ||
| WRITE_COMMANDS.CREATE_PER_DIEM_REQUEST, | ||
| WRITE_COMMANDS.SPLIT_BILL, | ||
| WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT, | ||
| WRITE_COMMANDS.START_SPLIT_BILL, | ||
| WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, | ||
| WRITE_COMMANDS.TRACK_EXPENSE, | ||
| WRITE_COMMANDS.SEND_INVOICE, | ||
| ]), | ||
| spanOp: CONST.TELEMETRY.SPAN_EXPENSE_SERVER_RESPONSE, | ||
| spanName: 'expense-server-response', | ||
| }, | ||
| ]; | ||
|
|
||
| /** | ||
| * Finds the tracked command group for a given command, if any. | ||
| */ | ||
| function findTrackedGroup(command: string): TrackedCommandGroup | undefined { | ||
| return TRACKED_COMMAND_GROUPS.find((group) => group.commands.has(command)); | ||
| } | ||
|
|
||
| /** | ||
| * Middleware that tracks server round-trip time for configured command groups via Sentry spans. | ||
| * For non-tracked commands, this is a no-op pass-through. | ||
| * | ||
| * To add tracking for a new flow, add an entry to TRACKED_COMMAND_GROUPS above. | ||
| */ | ||
| const SentryServerTiming: Middleware = (response, request) => { | ||
| const group = findTrackedGroup(request.command); | ||
| if (!group) { | ||
| return response; | ||
| } | ||
|
|
||
| const spanId = `${group.spanOp}_${request.requestID}`; | ||
| startSpan(spanId, { | ||
| name: group.spanName, | ||
| op: group.spanOp, | ||
| attributes: { | ||
| [CONST.TELEMETRY.ATTRIBUTE_COMMAND]: request.command, | ||
| }, | ||
| }); | ||
|
|
||
| return response | ||
| .then((data) => { | ||
| const span = getSpan(spanId); | ||
| span?.setAttributes({ | ||
| [CONST.TELEMETRY.ATTRIBUTE_JSON_CODE]: data?.jsonCode, | ||
| }); | ||
| endSpan(spanId); | ||
| return data; | ||
| }) | ||
| .catch((error) => { | ||
| cancelSpan(spanId); | ||
| throw error; | ||
| }); | ||
| }; | ||
|
|
||
| export default SentryServerTiming; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type {IOUType} from '@src/CONST'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| type GetSubmitExpenseScenarioParams = { | ||
| iouType: IOUType; | ||
| isDistanceRequest: boolean; | ||
| isMovingTransactionFromTrackExpense: boolean; | ||
| isUnreported: boolean; | ||
| isCategorizingTrackExpense: boolean; | ||
| isSharingTrackExpense: boolean; | ||
| isPerDiemRequest: boolean; | ||
| isFromGlobalCreate: boolean; | ||
| hasReceiptFiles: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Determines the telemetry scenario string for a submit expense action. | ||
| */ | ||
| function getSubmitExpenseScenario({ | ||
| iouType, | ||
| isDistanceRequest, | ||
| isMovingTransactionFromTrackExpense, | ||
| isUnreported, | ||
| isCategorizingTrackExpense, | ||
| isSharingTrackExpense, | ||
| isPerDiemRequest, | ||
| isFromGlobalCreate, | ||
| hasReceiptFiles, | ||
| }: GetSubmitExpenseScenarioParams): string { | ||
| const {SUBMIT_EXPENSE_SCENARIO} = CONST.TELEMETRY; | ||
|
|
||
| if (iouType !== CONST.IOU.TYPE.TRACK && isDistanceRequest && !isMovingTransactionFromTrackExpense && !isUnreported) { | ||
| return SUBMIT_EXPENSE_SCENARIO.DISTANCE; | ||
| } | ||
| if (iouType === CONST.IOU.TYPE.SPLIT) { | ||
| if (hasReceiptFiles) { | ||
| return SUBMIT_EXPENSE_SCENARIO.SPLIT_RECEIPT; | ||
| } | ||
| if (isFromGlobalCreate) { | ||
| return SUBMIT_EXPENSE_SCENARIO.SPLIT_GLOBAL; | ||
| } | ||
| return SUBMIT_EXPENSE_SCENARIO.SPLIT; | ||
| } | ||
| if (iouType === CONST.IOU.TYPE.INVOICE) { | ||
| return SUBMIT_EXPENSE_SCENARIO.INVOICE; | ||
| } | ||
| if (iouType === CONST.IOU.TYPE.TRACK || isCategorizingTrackExpense || isSharingTrackExpense) { | ||
| return SUBMIT_EXPENSE_SCENARIO.TRACK_EXPENSE; | ||
| } | ||
| if (isPerDiemRequest) { | ||
| return SUBMIT_EXPENSE_SCENARIO.PER_DIEM; | ||
| } | ||
| if (hasReceiptFiles) { | ||
| return SUBMIT_EXPENSE_SCENARIO.REQUEST_MONEY_SCAN; | ||
| } | ||
|
|
||
| return SUBMIT_EXPENSE_SCENARIO.REQUEST_MONEY_MANUAL; | ||
| } | ||
|
|
||
| export default getSubmitExpenseScenario; | ||
| export type {GetSubmitExpenseScenarioParams}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import Performance from '@libs/Performance'; | ||
| import CONST from '@src/CONST'; | ||
| import {endSpan, getSpan} from './activeSpans'; | ||
|
|
||
| /** | ||
| * Mark the post-submit navigation telemetry span as finished. | ||
| */ | ||
| function markNavigateAfterExpenseCreateEnd() { | ||
| if (!getSpan(CONST.TELEMETRY.SPAN_NAVIGATE_AFTER_EXPENSE_CREATE)) { | ||
| return; | ||
| } | ||
| endSpan(CONST.TELEMETRY.SPAN_NAVIGATE_AFTER_EXPENSE_CREATE); | ||
| Performance.markEnd(CONST.TIMING.NAVIGATE_AFTER_EXPENSE_CREATE); | ||
| } | ||
|
|
||
| export default markNavigateAfterExpenseCreateEnd; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import Performance from '@libs/Performance'; | ||
| import CONST from '@src/CONST'; | ||
| import {endSpan, getSpan} from './activeSpans'; | ||
|
|
||
| /** | ||
| * Mark the submit expense telemetry span as finished. | ||
| * Called after all API.write() calls for the expense have been dispatched. | ||
| */ | ||
| function markSubmitExpenseEnd() { | ||
| if (!getSpan(CONST.TELEMETRY.SPAN_SUBMIT_EXPENSE)) { | ||
| return; | ||
| } | ||
| endSpan(CONST.TELEMETRY.SPAN_SUBMIT_EXPENSE); | ||
| Performance.markEnd(CONST.TIMING.SUBMIT_EXPENSE); | ||
| } | ||
|
|
||
| export default markSubmitExpenseEnd; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it fine to call
Performance.markEndwithout ever starting it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't break anything, but it was running on every Search layout for no reason. Added a
getSpan()check so it skips entirely when there's no active span.