Skip to content

Conversation

@antonis
Copy link
Contributor

@antonis antonis commented Mar 7, 2025

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

Based on feat: Capture app start errors before JS
Based on #5470

📜 Description

Adds RNSentrySDK APIs support to @sentry/react-native/expo plugin by importing sentry and adding injecting RNSentrySDK.init/start in the Android MainApplication (Kotlin or Java) or AppDelegate (Objective-C or Swift).

This feature is opt-out to enable it set useNativeInit to true in your @sentry/react-native/expo plugin configuration.

"plugins": [
  [
    "@sentry/react-native/expo",
    {
      "useNativeInit": true
    }
  ],

💡 Motivation and Context

Fixes #4625

💚 How did you test it?

CI, Manual

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • No breaking changes

🔮 Next steps

#skip-changelog

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 1c2a7b7

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1205.92 ms 1206.60 ms 0.69 ms
Size 3.44 MiB 4.67 MiB 1.23 MiB

Baseline results on branch: capture-app-start-errors-v7

Startup times

Revision Plain With Sentry Diff
60d1e83+dirty 1207.79 ms 1207.35 ms -0.44 ms
f26d7a8+dirty 1209.49 ms 1207.54 ms -1.95 ms

App size

Revision Plain With Sentry Diff
60d1e83+dirty 3.41 MiB 4.67 MiB 1.26 MiB
f26d7a8+dirty 3.44 MiB 4.67 MiB 1.23 MiB

Previous results on branch: antonis/4625-expo-useNativeInit

Startup times

Revision Plain With Sentry Diff
2c56c66+dirty 1210.14 ms 1211.94 ms 1.80 ms

App size

Revision Plain With Sentry Diff
2c56c66+dirty 3.41 MiB 4.67 MiB 1.26 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1217.39 ms 1216.65 ms -0.73 ms
Size 3.44 MiB 4.67 MiB 1.23 MiB

Baseline results on branch: capture-app-start-errors-v7

Startup times

Revision Plain With Sentry Diff
60d1e83+dirty 1201.87 ms 1204.61 ms 2.74 ms
f26d7a8+dirty 1227.33 ms 1220.67 ms -6.66 ms

App size

Revision Plain With Sentry Diff
60d1e83+dirty 3.41 MiB 4.67 MiB 1.26 MiB
f26d7a8+dirty 3.44 MiB 4.67 MiB 1.23 MiB

Previous results on branch: antonis/4625-expo-useNativeInit

Startup times

Revision Plain With Sentry Diff
2c56c66+dirty 1226.29 ms 1223.27 ms -3.02 ms

App size

Revision Plain With Sentry Diff
2c56c66+dirty 3.41 MiB 4.67 MiB 1.26 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 405.06 ms 416.68 ms 11.62 ms
Size 43.75 MiB 48.08 MiB 4.32 MiB

Baseline results on branch: capture-app-start-errors-v7

Startup times

Revision Plain With Sentry Diff
f26d7a8+dirty 571.36 ms 637.92 ms 66.56 ms
60d1e83+dirty 396.72 ms 390.04 ms -6.68 ms

App size

Revision Plain With Sentry Diff
f26d7a8+dirty 43.75 MiB 48.08 MiB 4.32 MiB
60d1e83+dirty 43.75 MiB 48.08 MiB 4.32 MiB

Previous results on branch: antonis/4625-expo-useNativeInit

Startup times

Revision Plain With Sentry Diff
2c56c66+dirty 507.32 ms 544.50 ms 37.18 ms

App size

Revision Plain With Sentry Diff
2c56c66+dirty 43.75 MiB 48.08 MiB 4.32 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 402.61 ms 441.25 ms 38.64 ms
Size 43.94 MiB 48.90 MiB 4.96 MiB

Baseline results on branch: capture-app-start-errors-v7

Startup times

Revision Plain With Sentry Diff
f26d7a8+dirty 380.15 ms 407.84 ms 27.68 ms
60d1e83+dirty 406.16 ms 422.83 ms 16.67 ms

App size

Revision Plain With Sentry Diff
f26d7a8+dirty 43.94 MiB 48.90 MiB 4.96 MiB
60d1e83+dirty 43.94 MiB 48.90 MiB 4.96 MiB

Previous results on branch: antonis/4625-expo-useNativeInit

Startup times

Revision Plain With Sentry Diff
2c56c66+dirty 375.54 ms 401.17 ms 25.63 ms

App size

Revision Plain With Sentry Diff
2c56c66+dirty 43.94 MiB 48.90 MiB 4.96 MiB

@antonis antonis linked an issue Mar 7, 2025 that may be closed by this pull request
@antonis antonis marked this pull request as ready for review March 7, 2025 16:22
Copy link
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

Overall the PR looks good and thank you for the tests!
I still think we could fine tune a bit more the android part and after it we could get ready for merge

antonis and others added 2 commits April 4, 2025 11:01
Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com>
@antonis antonis requested a review from lucas-zimerman April 4, 2025 09:45
@antonis
Copy link
Contributor Author

antonis commented Apr 4, 2025

Note: The Build & Test / Type Check Typescript 3.8 (pull_request) failure should be fixed when we merge #4673 from main

@antonis antonis requested a review from krystofwoldrich April 15, 2025 10:00
Co-authored-by: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com>
@krystofwoldrich
Copy link
Contributor

I'm currently updating the base branch with the latest main since there was quite a lot of development that was not synced to the feature branch.

@antonis
Copy link
Contributor Author

antonis commented Jun 11, 2025

I'm currently updating the base branch with the latest main since there was quite a lot of development that was not synced to the feature branch.

Thank you for the heads up @krystofwoldrich 🙇
I'll update this branch after that along with the review feedback.

@krystofwoldrich krystofwoldrich force-pushed the capture-app-start-errors branch 3 times, most recently from 2363742 to 588ba6d Compare June 12, 2025 15:26
Copy link
Contributor

@krystofwoldrich krystofwoldrich left a comment

Choose a reason for hiding this comment

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

Thank you for the fixes. 🚀 It looks great!


### Features

- Add RNSentrySDK APIs support to @sentry/react-native/expo plugin ([#4633](https://github.com/getsentry/sentry-react-native/pull/4633))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. It would be nice to include an example code snippet and a small summary of what will the flag do.

@lucas-zimerman
Copy link
Collaborator

@sentry review

@lucas-zimerman
Copy link
Collaborator

@antonis should we restart this PR?

@antonis
Copy link
Contributor Author

antonis commented Dec 11, 2025

@antonis should we restart this PR?

I don't expect this to have major conflicts with main/v7.

- Resolved conflicts by separating imports from logger and version modules
- Preserved useNativeInit functionality from PR #4633
- Fixed optional chain expressions in withSentryAndroid and withSentryIOS
- Updated test mocks to use logger instead of utils
@antonis antonis changed the base branch from capture-app-start-errors to capture-app-start-errors-v7 December 15, 2025 15:11
@antonis antonis requested a review from alwx as a code owner December 15, 2025 15:11
@antonis antonis added the ready-to-merge Triggers the full CI test suite label Dec 15, 2025
}

export function modifyAppDelegate(config: ExpoConfig): ExpoConfig {
return withAppDelegate(config, async config => {
Copy link

Choose a reason for hiding this comment

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

Bug: The modifyAppDelegate function incorrectly returns a Promise<ExpoConfig> instead of ExpoConfig due to an async callback, breaking the synchronous call chain for iOS native initialization.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The modifyAppDelegate function is declared to return an ExpoConfig but it uses an async callback with withAppDelegate, which causes the function to actually return a Promise<ExpoConfig>. The return value, stored in appDelegateCfc, is then used as if it were a synchronous ExpoConfig object and passed to withDangerousMod. This occurs when useNativeInit is true. Passing a promise instead of the expected configuration object to withDangerousMod will cause the Sentry iOS native initialization to fail.

💡 Suggested Fix

Remove the async keyword from the callback passed to withAppDelegate inside the modifyAppDelegate function. This will make the function return ExpoConfig synchronously, matching its type signature and the Android implementation.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/core/plugin/src/withSentryIOS.ts#L90

Potential issue: The `modifyAppDelegate` function is declared to return an `ExpoConfig`
but it uses an `async` callback with `withAppDelegate`, which causes the function to
actually return a `Promise<ExpoConfig>`. The return value, stored in `appDelegateCfc`,
is then used as if it were a synchronous `ExpoConfig` object and passed to
`withDangerousMod`. This occurs when `useNativeInit` is true. Passing a promise instead
of the expected configuration object to `withDangerousMod` will cause the Sentry iOS
native initialization to fail.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7592441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RNSentrySDK APIs support to @sentry/react-native/expo plugin

3 participants