Skip to content

feat: Automatically load sentry.options.json file #4476

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

Conversation

krystofwoldrich
Copy link
Member

@krystofwoldrich krystofwoldrich commented Jan 22, 2025

📢 Type of change

  • New feature

📜 Description

This PR adds optionsFile options to the Sentry Metro Plugin. This enabled the plugin to automatically load the options from the specified file to the created React Native Bundle.

The plugin uses the customSerializer Metro interface to add a preModule to the entry bundle of the application. This works for both RN and Expo project including Expo Web.

I have not tested standalone React Native Web. Thus at the moment only Expo Web is supported.

Example usage

The optionsFile is enabled by default and loaded only if the file exists. Both relative path to the project root and absolute paths are allowed.

The file specified in the metro config applies only to the JS code. To change the file path for Android and iOS native initialization build options of the respective platforms need to be used.

// RN
const { getDefaultConfig } = require('@react-native/metro-config');
const { withSentryConfig } = require('@sentry/react-native/metro');

const config = getDefaultConfig(__dirname);
module.exports = withSentryConfig(config, {
  optionsFile: 'custom.sentry.options.js',
});

// Expo
const { getSentryExpoConfig } = require('@sentry/react-native/metro');

const config = getSentryExpoConfig(__dirname, {
  optionsFile: 'custom.sentry.options.js',
});

💡 Motivation and Context

💚 How did you test it?

sample apps, unit tests

📝 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

krystofwoldrich and others added 30 commits January 14, 2025 13:47
Copy link
Contributor

github-actions bot commented Jan 22, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Automatically load `sentry.options.json` file ([#4476](https://github.com/getsentry/sentry-react-native/pull/4476))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 2cdcd60

Copy link
Contributor

github-actions bot commented Jan 22, 2025

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 490.60 ms 490.94 ms 0.33 ms
Size 17.75 MiB 20.11 MiB 2.37 MiB

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

Startup times

Revision Plain With Sentry Diff
208f4af 439.23 ms 427.31 ms -11.92 ms
b75148e 440.04 ms 421.36 ms -18.68 ms
555070f 438.67 ms 428.30 ms -10.37 ms

App size

Revision Plain With Sentry Diff
208f4af 17.75 MiB 20.11 MiB 2.37 MiB
b75148e 17.75 MiB 20.11 MiB 2.37 MiB
555070f 17.75 MiB 20.11 MiB 2.37 MiB

Previous results on branch: kw-add-options-file-init-to-js

Startup times

Revision Plain With Sentry Diff
7af80d6 504.40 ms 506.48 ms 2.08 ms
3d551aa 428.53 ms 409.94 ms -18.59 ms

App size

Revision Plain With Sentry Diff
7af80d6 17.75 MiB 20.11 MiB 2.37 MiB
3d551aa 17.75 MiB 20.11 MiB 2.37 MiB

Copy link
Contributor

github-actions bot commented Jan 22, 2025

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 360.02 ms 409.29 ms 49.26 ms
Size 7.15 MiB 8.38 MiB 1.23 MiB

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

Startup times

Revision Plain With Sentry Diff
b75148e+dirty 428.91 ms 461.26 ms 32.35 ms
208f4af+dirty 346.93 ms 402.77 ms 55.84 ms
555070f+dirty 388.25 ms 424.44 ms 36.19 ms

App size

Revision Plain With Sentry Diff
b75148e+dirty 7.15 MiB 8.38 MiB 1.23 MiB
208f4af+dirty 7.15 MiB 8.38 MiB 1.23 MiB
555070f+dirty 7.15 MiB 8.38 MiB 1.23 MiB

Previous results on branch: kw-add-options-file-init-to-js

Startup times

Revision Plain With Sentry Diff
7af80d6+dirty 376.06 ms 403.21 ms 27.14 ms
3d551aa+dirty 398.75 ms 439.94 ms 41.19 ms

App size

Revision Plain With Sentry Diff
7af80d6+dirty 7.15 MiB 8.38 MiB 1.23 MiB
3d551aa+dirty 7.15 MiB 8.38 MiB 1.23 MiB

Copy link
Contributor

github-actions bot commented Jan 22, 2025

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1213.31 ms 1214.00 ms 0.69 ms
Size 2.63 MiB 3.69 MiB 1.05 MiB

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

Startup times

Revision Plain With Sentry Diff
208f4af+dirty 1209.44 ms 1217.13 ms 7.70 ms
b75148e+dirty 1221.53 ms 1220.85 ms -0.68 ms
555070f+dirty 1213.59 ms 1217.79 ms 4.20 ms

App size

Revision Plain With Sentry Diff
208f4af+dirty 2.63 MiB 3.69 MiB 1.05 MiB
b75148e+dirty 2.63 MiB 3.69 MiB 1.06 MiB
555070f+dirty 2.63 MiB 3.69 MiB 1.05 MiB

Previous results on branch: kw-add-options-file-init-to-js

Startup times

Revision Plain With Sentry Diff
3d551aa+dirty 1215.78 ms 1221.58 ms 5.81 ms
7af80d6+dirty 1219.13 ms 1214.67 ms -4.46 ms

App size

Revision Plain With Sentry Diff
3d551aa+dirty 2.63 MiB 3.69 MiB 1.05 MiB
7af80d6+dirty 2.63 MiB 3.69 MiB 1.05 MiB

Copy link
Contributor

github-actions bot commented Jan 22, 2025

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1225.43 ms 1224.22 ms -1.20 ms
Size 3.19 MiB 4.25 MiB 1.07 MiB

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

Startup times

Revision Plain With Sentry Diff
208f4af+dirty 1213.08 ms 1223.82 ms 10.73 ms
b75148e+dirty 1202.72 ms 1212.04 ms 9.32 ms
555070f+dirty 1223.61 ms 1227.57 ms 3.96 ms

App size

Revision Plain With Sentry Diff
208f4af+dirty 3.19 MiB 4.25 MiB 1.06 MiB
b75148e+dirty 3.19 MiB 4.25 MiB 1.07 MiB
555070f+dirty 3.19 MiB 4.25 MiB 1.06 MiB

Previous results on branch: kw-add-options-file-init-to-js

Startup times

Revision Plain With Sentry Diff
3d551aa+dirty 1219.31 ms 1221.22 ms 1.92 ms
7af80d6+dirty 1236.92 ms 1230.04 ms -6.88 ms

App size

Revision Plain With Sentry Diff
3d551aa+dirty 3.19 MiB 4.25 MiB 1.07 MiB
7af80d6+dirty 3.19 MiB 4.25 MiB 1.07 MiB

Base automatically changed from kw-add-read-ios-options-file to capture-app-start-errors January 22, 2025 16:55
@krystofwoldrich krystofwoldrich marked this pull request as ready for review January 24, 2025 12:23
Copy link
Collaborator

@antonis antonis left a comment

Choose a reason for hiding this comment

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

LGTM and worked as expected 🚀
Thank you for the added tests 🙇

l: should we add a changelog for this similar to the native side?

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.

LGTM!
But like @antonis mentioned, we should mention it on changelog since it is a new feature.

@krystofwoldrich krystofwoldrich merged commit 22a5f81 into capture-app-start-errors Feb 3, 2025
10 of 11 checks passed
@krystofwoldrich krystofwoldrich deleted the kw-add-options-file-init-to-js branch February 3, 2025 10:55
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.

3 participants