Skip to content

Comments

[DO NOT MERGE] Start sentry from native#82858

Open
elirangoshen wants to merge 24 commits intoExpensify:mainfrom
callstack-internal:eliran/sentry-start-app-time-native
Open

[DO NOT MERGE] Start sentry from native#82858
elirangoshen wants to merge 24 commits intoExpensify:mainfrom
callstack-internal:eliran/sentry-start-app-time-native

Conversation

@elirangoshen
Copy link
Contributor

@elirangoshen elirangoshen commented Feb 18, 2026

Explanation of Change

Backdates the SPAN_APP_STARTUP Sentry performance span to the true native app launch time, rather than when JS initializes.

Problem: The SPAN_APP_STARTUP span was previously starting when JS runs, which misses the native launch phase (JVM startup, Application.onCreate, RN bridge init, etc.) and underreports startup duration.

Solution:

  1. Record a timestamp as early as possible in the native lifecycle, before React Native initializes:
    • Android (MainApplication.onCreate): writes to SharedPreferences
    • iOS (AppDelegate.didFinishLaunchingWithOptions): writes to UserDefaults
  2. Expose the timestamp to JS via a new AppStartTimeModule NitroModule (added to ExpensifyNitroUtils)
  3. In src/setup/telemetry/index.native.ts, read AppStartTimeNitroModule.appStartTime and pass it as startTime to startSpan(SPAN_APP_STARTUP, ...) so Sentry records the span from true native launch

The companion Mobile-Expensify PR (for HybridApp builds, where a ContentProvider records the time even earlier) is: https://github.com/Expensify/Mobile-Expensify/pull/13855

Fixed Issues

$ #82974

MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/13855

Do not merge until https://github.com/Expensify/Mobile-Expensify/pull/13855 would be merged

Tests

  1. Build and run the app on Android Native or iOS Native
  2. Trigger an app cold start
  3. In Sentry → Performance, find a SPAN_APP_STARTUP transaction
  4. Verify the span start time is earlier than before (reflecting native launch, not JS init)
  5. Verify no errors appear in the JS console related to AppStartTimeModule

Offline tests

N/A — only affects Sentry telemetry, no offline behavior impact.

QA Steps

  1. Build and run on Android Native and iOS Native
  2. Verify the app launches and behaves normally
  3. Verify no JS console errors appear

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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • 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

@github-actions
Copy link
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/CONST/index.ts 92.43% <ø> (ø)
src/setup/telemetry/index.ts 0.00% <0.00%> (ø)
src/setup/telemetry/index.web.ts 0.00% <0.00%> (ø)
src/setup/telemetry/index.native.ts 0.00% <0.00%> (ø)
src/setup/telemetry/setupSentry.ts 0.00% <0.00%> (ø)
... and 28 files with indirect coverage changes

@roryabraham
Copy link
Contributor

@elirangoshen can you get this cleaned up a bit before I re-review https://github.com/Expensify/Mobile-Expensify/pull/13855? It's still not clear to me how we're using the native app start time we added, and it looks like this PR contains both the TurboModule and the NitroModule implementations.

@Julesssss Julesssss self-requested a review February 19, 2026 22:57
elirangoshen and others added 7 commits February 20, 2026 11:16
- Delete AppStartTimeModule.kt (TurboModule) which was unused by JS
- Remove its registration from ExpensifyAppPackage
- Replace AppStartTimeModule.appStartTime assignment in MainApplication with
  direct SharedPreferences write (matching what the NitroModule reads)
- Replace AppStartTime.setAppStartTime() in AppDelegate with direct
  UserDefaults write (matching what the NitroModule reads)
- Update Mobile-Expensify submodule to eliran/native-module-start-time HEAD

The NitroModule (HybridAppStartTimeModule) is the single implementation.
Native startup writes the timestamp to SharedPreferences/UserDefaults,
JS reads it via AppStartTimeNitroModule.appStartTime and uses it to
backdate the SPAN_APP_STARTUP Sentry span to true native launch time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lication

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@elirangoshen
Copy link
Contributor Author

@elirangoshen can you get this cleaned up a bit before I re-review Expensify/Mobile-Expensify#13855? It's still not clear to me how we're using the native app start time we added, and it looks like this PR contains both the TurboModule and the NitroModule implementations.

done

elirangoshen and others added 4 commits February 20, 2026 12:51
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@elirangoshen elirangoshen changed the title Start sentry from native [DO NOT MERGE] Start sentry from native Feb 20, 2026
@elirangoshen elirangoshen marked this pull request as ready for review February 20, 2026 12:44
@elirangoshen elirangoshen requested review from a team as code owners February 20, 2026 12:44
@melvin-bot melvin-bot bot requested review from joekaufmanexpensify and removed request for a team February 20, 2026 12:44
@melvin-bot
Copy link

melvin-bot bot commented Feb 20, 2026

@abdulrahuman5196 @roryabraham One of you needs to 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 removed the request for review from a team February 20, 2026 12:44
@github-actions
Copy link
Contributor

Code Review - Claude Code

Critical Issues

1. Bug: breadcrumbsIntegration and consoleIntegration silently dropped (src/setup/telemetry/setupSentry.ts:17)

The original index.ts included 5 integrations but the refactored setupSentry.ts only includes 3. breadcrumbsIntegration (disables console breadcrumbs) and consoleIntegration (logs errors to Sentry) were removed without explanation. These integrations still exist in @libs/telemetry/integrations and should be restored.

2. Bug: Sentry startSpan expects seconds, not milliseconds (src/setup/telemetry/index.native.ts:19)

The native modules store System.currentTimeMillis() / Date().timeIntervalSince1970 * 1000 (milliseconds). But Sentry startSpan's startTime option expects seconds (or a Date object). Passing milliseconds will produce a start time ~year 65000 and nonsensical spans. Fix: startTime: nativeAppStartTimeMs ? nativeAppStartTimeMs / 1000 : undefined

Medium Issues

3. Telemetry disabled on fallback platforms (src/setup/telemetry/index.ts:1)

The default index.ts is now a no-op — no Sentry init, no startup span. Previously this file handled all platforms. Any platform not matching .native.ts or .web.ts will have zero telemetry silently. Is this intentional?

4. recordAppStartTime() appears to be dead code (HybridAppStartTimeModule.kt:9)

The native entry points (MainApplication.onCreate and AppDelegate.didFinishLaunchingWithOptions) write directly to SharedPreferences/UserDefaults. The recordAppStartTime() method on the NitroModule duplicates this but is never called. Consider removing it or adding a comment if intended for the companion Mobile-Expensify PR.

Minor Issues

5. ?? undefined is redundant (src/setup/telemetry/index.native.ts:20)

nativeAppStartTimeMs is already number | undefined, so ?? undefined is a no-op.

6. Silent error swallowing (src/setup/telemetry/index.native.ts:12)

The catch block silently swallows errors from AppStartTimeNitroModule.appStartTime without logging, making debugging telemetry issues on native platforms difficult.

7. Unrelated Podfile.lock change

ExpoWebBrowser was added to ios/Podfile.lock — appears unrelated to this PR's scope.

Copy link

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

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: 38d9c0092c

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

elirangoshen and others added 2 commits February 20, 2026 14:51
- Guard against 0 value from NitroModule (would backdate span to Unix epoch)
- Use Log.warn instead of silent catch for NitroModule read failure
- Add justification to eslint-disable comment in AppStartTimeModule spec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@elirangoshen
Copy link
Contributor Author

elirangoshen commented Feb 20, 2026

Code Review - Claude Code

Critical Issues

1. Bug: breadcrumbsIntegration and consoleIntegration silently dropped (src/setup/telemetry/setupSentry.ts:17)

The original index.ts included 5 integrations but the refactored setupSentry.ts only includes 3. breadcrumbsIntegration (disables console breadcrumbs) and consoleIntegration (logs errors to Sentry) were removed without explanation. These integrations still exist in @libs/telemetry/integrations and should be restored.

2. Bug: Sentry startSpan expects seconds, not milliseconds (src/setup/telemetry/index.native.ts:19)

The native modules store System.currentTimeMillis() / Date().timeIntervalSince1970 * 1000 (milliseconds). But Sentry startSpan's startTime option expects seconds (or a Date object). Passing milliseconds will produce a start time ~year 65000 and nonsensical spans. Fix: startTime: nativeAppStartTimeMs ? nativeAppStartTimeMs / 1000 : undefined

Medium Issues

3. Telemetry disabled on fallback platforms (src/setup/telemetry/index.ts:1)

The default index.ts is now a no-op — no Sentry init, no startup span. Previously this file handled all platforms. Any platform not matching .native.ts or .web.ts will have zero telemetry silently. Is this intentional?

4. recordAppStartTime() appears to be dead code (HybridAppStartTimeModule.kt:9)

The native entry points (MainApplication.onCreate and AppDelegate.didFinishLaunchingWithOptions) write directly to SharedPreferences/UserDefaults. The recordAppStartTime() method on the NitroModule duplicates this but is never called. Consider removing it or adding a comment if intended for the companion Mobile-Expensify PR.

Minor Issues

5. ?? undefined is redundant (src/setup/telemetry/index.native.ts:20)

nativeAppStartTimeMs is already number | undefined, so ?? undefined is a no-op.

6. Silent error swallowing (src/setup/telemetry/index.native.ts:12)

The catch block silently swallows errors from AppStartTimeNitroModule.appStartTime without logging, making debugging telemetry issues on native platforms difficult.

7. Unrelated Podfile.lock change

ExpoWebBrowser was added to ios/Podfile.lock — appears unrelated to this PR's scope.

  • 1 (breadcrumbs/consoleIntegration dropped) — already fixed ✓
  • 2 (ms vs seconds) — invalid, Sentry's ensureTimestampInSeconds auto-detects ms (checks > 9999999999) and divides by 1000. Our timestamps (~1.74 trillion) are handled correctly.
  • 3 (empty index.ts) — intentional by design, no action needed
  • 4 (recordAppStartTime() dead code) — fixed ✓
  • 5 (?? undefined redundant) — already fixed ✓
  • 6 (silent catch) — already fixed ✓
  • 7 (Podfile.lock) — came in from merging main, not our change

- Restore breadcrumbsIntegration and consoleIntegration that were
  accidentally dropped in the setupSentry refactor
- Add comment to recordAppStartTime() explaining it cannot be called
  from JS and that recording is done natively

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment on lines +6 to +7
class HybridAppStartTimeModule : HybridAppStartTimeModuleSpec() {
override val memorySize: Long = 16L
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're tracking here is the Android MainApplication tracking redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No as the MainApplication tracking is for the standalone application and this tracking is for the HybridApp.
Do you think we should add the same early entry using ContentProvider to the standalone app as well ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should add the same early entry
Yeah I guess that makes sense?

As for the standalone app tracking, I don't think we need that as users will remain on HybridApp for another year or so. However, if we could isolate the metrics within Sentry it would be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok so I added tag to distinguish between those build types. let me know if its ok

Comment on lines +8 to +9
* initializes. The actual recording is done natively — in MainApplication.onCreate()
* on Android and AppDelegate.didFinishLaunchingWithOptions() on iOS — by writing
Copy link
Contributor

@Julesssss Julesssss Feb 20, 2026

Choose a reason for hiding this comment

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

The actual recording is done natively — in MainApplication.onCreate()

Leaving this comment for now, to remember to verify this function comment

@joekaufmanexpensify
Copy link
Contributor

No product review needed

@joekaufmanexpensify joekaufmanexpensify removed their request for review February 20, 2026 19:33
Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

LGTM, holding on Mobile-Expensify PR. prettier change seems unrelated

@github-actions
Copy link
Contributor

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

@github-actions

This comment has been minimized.

@Expensify Expensify deleted a comment from elirangoshen Feb 25, 2026
@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

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.

4 participants