Repository navigation
fix: drop canceled tab navigation spans and add Inbox span context attributes #95480
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
JS00001
merged 4 commits into
Expensify:main
from
callstack-internal:fix/inbox-tab-span-telemetry
Jul 9, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d32e77a
fix: drop canceled tab navigation spans and add Inbox span context at…
BartekObudzinski b50c02f
Merge remote-tracking branch 'upstream/main' into fix/inbox-tab-span-…
BartekObudzinski 9938372
refactor: address span telemetry review findings
BartekObudzinski 0c4f172
fix: cspell word and update hook test for endSpanWithAttributes
BartekObudzinski 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
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
33 changes: 33 additions & 0 deletions
33
src/libs/telemetry/middlewares/canceledTabNavigationFilter.ts
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,33 @@ | ||
| import {TAB_NAVIGATION_SPAN_IDS} from '@libs/telemetry/cancelTabNavigationSpans'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import type {TelemetryBeforeSend} from './index'; | ||
|
|
||
| // Tab-navigation spans are canceled when the user abandons the navigation (switching tabs mid-flight, | ||
| // sending the app to the background). Their duration reflects the arbitrary moment of the abort rather than | ||
| // a finished navigation, so sending them would skew the tab-navigation percentiles in both directions. Drop them. | ||
| const TAB_NAVIGATION_OPS: ReadonlySet<string> = new Set(TAB_NAVIGATION_SPAN_IDS); | ||
|
|
||
| // The attribute is set as a boolean, but attribute values can arrive stringified depending on the SDK layer. | ||
| function isCanceled(value: unknown): boolean { | ||
| return value === true || value === 'true'; | ||
| } | ||
|
|
||
| const canceledTabNavigationFilter: TelemetryBeforeSend = (event) => { | ||
| const op = event.contexts?.trace?.op; | ||
| if (op && TAB_NAVIGATION_OPS.has(op) && isCanceled(event.contexts?.trace?.data?.[CONST.TELEMETRY.ATTRIBUTE_CANCELED])) { | ||
| return null; | ||
| } | ||
|
|
||
| // Tab-navigation spans are usually root transactions, but without forceTransaction they can be adopted | ||
| // as child spans of an active transaction, so filter those the same way (mirrors minDurationFilter). | ||
| if (!event.spans) { | ||
| return event; | ||
| } | ||
| const spans = event.spans.filter((span) => !(span.op && TAB_NAVIGATION_OPS.has(span.op) && isCanceled(span.data?.[CONST.TELEMETRY.ATTRIBUTE_CANCELED]))); | ||
|
|
||
| return {...event, spans}; | ||
| }; | ||
|
|
||
| export default canceledTabNavigationFilter; |
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,61 @@ | ||
| import canceledTabNavigationFilter from '@libs/telemetry/middlewares/canceledTabNavigationFilter'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import type {TransactionEvent} from '@sentry/core'; | ||
|
|
||
| jest.mock('@libs/telemetry/activeSpans', () => ({ | ||
| cancelSpan: jest.fn(), | ||
| })); | ||
|
|
||
| const INBOX_OP = CONST.TELEMETRY.SPAN_NAVIGATE_TO_INBOX_TAB; | ||
| const REPORTS_OP = CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS; | ||
| const CANCELED = CONST.TELEMETRY.ATTRIBUTE_CANCELED; | ||
|
|
||
| type ChildSpan = NonNullable<TransactionEvent['spans']>[number]; | ||
| type SpanData = Record<string, string | number | boolean>; | ||
|
|
||
| function buildTransaction(op: string, data?: SpanData, spans?: ChildSpan[]): TransactionEvent { | ||
| return { | ||
| type: 'transaction', | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention -- Sentry protocol field names | ||
| contexts: {trace: {span_id: 'a', trace_id: 'b', op, data}}, | ||
| spans, | ||
| }; | ||
| } | ||
|
|
||
| function buildChildSpan(op: string, data?: SpanData): ChildSpan { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention -- Sentry protocol field names | ||
| return {span_id: 'c', trace_id: 'b', start_timestamp: 0, timestamp: 1, data: data ?? {}, op}; | ||
| } | ||
|
|
||
| describe('canceledTabNavigationFilter', () => { | ||
| it('drops a canceled inbox tab navigation transaction', async () => { | ||
| expect(await canceledTabNavigationFilter(buildTransaction(INBOX_OP, {[CANCELED]: true}), {})).toBeNull(); | ||
| }); | ||
|
|
||
| it('drops a canceled reports tab navigation transaction', async () => { | ||
| expect(await canceledTabNavigationFilter(buildTransaction(REPORTS_OP, {[CANCELED]: true}), {})).toBeNull(); | ||
| }); | ||
|
|
||
| it('drops a canceled tab navigation transaction when the attribute arrives stringified', async () => { | ||
| expect(await canceledTabNavigationFilter(buildTransaction(INBOX_OP, {[CANCELED]: 'true'}), {})).toBeNull(); | ||
| }); | ||
|
|
||
| it('keeps a completed tab navigation transaction without the canceled attribute', async () => { | ||
| const event = buildTransaction(INBOX_OP); | ||
| expect(await canceledTabNavigationFilter(event, {})).toBe(event); | ||
| }); | ||
|
|
||
| it('keeps a canceled transaction with an unrelated op', async () => { | ||
| const event = buildTransaction('ManualAppStartup', {[CANCELED]: true}); | ||
| expect(await canceledTabNavigationFilter(event, {})).toBe(event); | ||
| }); | ||
|
|
||
| it('strips canceled tab navigation child spans but keeps the rest', async () => { | ||
| const event = buildTransaction('pageload', undefined, [buildChildSpan(INBOX_OP, {[CANCELED]: true}), buildChildSpan('http.client')]); | ||
| const result = await canceledTabNavigationFilter(event, {}); | ||
| expect(result?.spans).toHaveLength(1); | ||
| expect(result?.spans?.at(0)?.op).toBe('http.client'); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.