Skip to content

[iOS + Android] Add the ability to intercept errors from native side and forward them to JS console#5622

Open
alwx wants to merge 15 commits intomainfrom
alwx/experiment/native-logs
Open

[iOS + Android] Add the ability to intercept errors from native side and forward them to JS console#5622
alwx wants to merge 15 commits intomainfrom
alwx/experiment/native-logs

Conversation

@alwx
Copy link
Contributor

@alwx alwx commented Feb 5, 2026

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Was born as an attempt to fix #5566 and turned out to be a good idea in general.
It also fixes #5242

This PR makes it possible to intercept native logs (currently only works with iOS and only with a patch, see notes below) and forward them to JS console:

Sentry.init({
  onNativeLog: ({ level, component, message }) => {
    // Use logWithoutTracing to avoid feedback loops with Sentry's console integration
    logWithoutTracing(`[Sentry Native] [${level.toUpperCase()}] [${component}] ${message}`);
  },
  debug: true,
}

(that only works when debug is set to true)

This PR makes it so that instead of handling HTTP code 413 somehow separately we can allow users to just get native logs in their JS console and see code 413 or any other error codes themselves. Filtering per level or component is also possible.

Notes

⚠️ Currently is works on Android without any further changes but on iOS it only works with a minor change to SentrySDKLog.swift. The change is done in this PR: getsentry/sentry-cocoa#7444

📝 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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • [iOS + Android] Add the ability to intercept errors from native side and forward them to JS console by alwx in #5622
  • chore(deps): bump brace-expansion from 1.1.11 to 1.1.12 by dependabot in #5751
  • chore(deps): bump minimatch to fix ReDoS vulnerabilities and tmp to ^0.2.4 by antonis in #5749
  • chore(deps): bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.21.7 to 2.23.1 by dependabot in #5738
  • chore(deps): update Wizard to v6.12.0 by github-actions in #5747
  • chore(deps): update JavaScript SDK to v10.41.0 by github-actions in #5744
  • chore(deps): bump tar to ^7.5.8 by antonis in #5703
  • chore(deps): bump js-yaml to fix prototype pollution in merge by antonis in #5709
  • chore(deps): bump ajv to fix ReDoS in $data option by antonis in #5710
  • chore(deps): update CLI to v3.2.3 by github-actions in #5743
  • Fixes the issue with unit mismatch in adjustTransactionDuration by alwx in #5740
  • Handle inactive state for spans by alwx in #5742
  • chore(deps): bump actions/github-script from 7 to 8 by dependabot in #5737
  • chore(deps): bump actions/upload-artifact from 6 to 7 by dependabot in #5739
  • chore(deps): bump futureware-tech/simulator-action from 4 to 5 by dependabot in #5735
  • chore(deps): bump actions/download-artifact from 7 to 8 by dependabot in #5736
  • chore(deps): bump path-to-regexp to 0.1.12 by antonis in #5706
  • fix(ios): resolve relative SOURCEMAP_FILE against project root in Xcode build script by antonis in #5730
  • test(metro): Add type tests for SentryExpoConfigOptions.getDefaultConfig by antonis in #5733
  • chore(deps): bump axios to ^1.13.5 by antonis in #5708
  • chore(deps): bump on-headers to ^1.1.0 by antonis in #5704
  • chore(deps): bump dottie from 2.0.6 to 2.0.7 by dependabot in #5731
  • Cirrus Labs runners for other important workflows (where it makes sense to do so) + Ubuntu update (22.04 -> 24.04) by alwx in #5696
  • chore(deps): bump diff to ^5.2.2 by antonis in #5705

Plus 3 more


🤖 This preview updates automatically when you update the PR.

@alwx alwx force-pushed the alwx/experiment/native-logs branch from 2108fe1 to f369c1d Compare February 9, 2026 12:40
@alwx alwx changed the title WIP: An (ongoing) experiment with adding native logs listener Native logs listener Feb 10, 2026
@alwx alwx changed the title Native logs listener Native logs listener to intercept errors from native side and forward them to JS console Feb 10, 2026
@alwx alwx changed the title Native logs listener to intercept errors from native side and forward them to JS console Intercept errors from native side and forward them to JS console Feb 10, 2026
@alwx alwx changed the title Intercept errors from native side and forward them to JS console Add the ability to intercept errors from native side and forward them to JS console Feb 10, 2026
@alwx alwx self-assigned this Feb 10, 2026
@alwx alwx marked this pull request as ready for review February 10, 2026 10:51
@alwx alwx added the ready-to-merge Triggers the full CI test suite label Feb 10, 2026
@alwx alwx changed the title Add the ability to intercept errors from native side and forward them to JS console [iOS only] Add the ability to intercept errors from native side and forward them to JS console Feb 10, 2026
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.

So far it's looking good! I left a few suggestions that would be nice to be addressed before merging.

@alwx alwx changed the title [iOS only] Add the ability to intercept errors from native side and forward them to JS console [iOS + Android] Add the ability to intercept errors from native side and forward them to JS console Feb 12, 2026
@alwx
Copy link
Contributor Author

alwx commented Feb 12, 2026

I've updated this PR to support Android as well (that was easy on Android because all the required methods are already there) 🎉

@alwx alwx requested a review from lucas-zimerman February 12, 2026 10:32
@alwx alwx force-pushed the alwx/experiment/native-logs branch from 524e190 to 313b4e6 Compare February 12, 2026 11:00
@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 501.65 ms 542.12 ms 40.47 ms
Size 43.75 MiB 48.49 MiB 4.74 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
86584b7+dirty 463.83 ms 500.31 ms 36.48 ms
9a81842+dirty 412.23 ms 416.56 ms 4.33 ms
c637fc7+dirty 433.70 ms 467.76 ms 34.06 ms
d73150f+dirty 411.21 ms 465.86 ms 54.65 ms
fa7bb7e+dirty 350.37 ms 377.02 ms 26.65 ms
3bd3f0d+dirty 447.21 ms 472.31 ms 25.10 ms
88890fe+dirty 350.94 ms 365.74 ms 14.80 ms
95aaf8a 437.89 ms 419.45 ms -18.44 ms
c0842e7+dirty 527.76 ms 566.69 ms 38.93 ms
1e7a472+dirty 348.80 ms 362.55 ms 13.75 ms

App size

Revision Plain With Sentry Diff
86584b7+dirty 43.75 MiB 48.08 MiB 4.33 MiB
9a81842+dirty 43.75 MiB 48.08 MiB 4.33 MiB
c637fc7+dirty 43.75 MiB 48.40 MiB 4.64 MiB
d73150f+dirty 43.75 MiB 48.55 MiB 4.80 MiB
fa7bb7e+dirty 17.75 MiB 19.75 MiB 2.00 MiB
3bd3f0d+dirty 17.75 MiB 19.70 MiB 1.95 MiB
88890fe+dirty 17.75 MiB 19.71 MiB 1.96 MiB
95aaf8a 17.75 MiB 19.68 MiB 1.93 MiB
c0842e7+dirty 43.75 MiB 48.41 MiB 4.66 MiB
1e7a472+dirty 17.75 MiB 19.70 MiB 1.96 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 388.13 ms 420.23 ms 32.11 ms
Size 43.94 MiB 49.35 MiB 5.41 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
7480abe+dirty 363.80 ms 431.34 ms 67.54 ms
2b89ce9+dirty 372.22 ms 417.06 ms 44.84 ms
170d5ea+dirty 348.79 ms 406.94 ms 58.15 ms
b1579bc+dirty 391.87 ms 456.26 ms 64.39 ms
73f2455+dirty 369.33 ms 398.90 ms 29.57 ms
0b64753+dirty 358.55 ms 429.16 ms 70.61 ms
6a70a7e+dirty 382.45 ms 424.54 ms 42.09 ms
2adbd1e+dirty 366.13 ms 419.49 ms 53.36 ms
f8d19f8+dirty 374.17 ms 383.40 ms 9.23 ms
7be1f99+dirty 369.02 ms 399.60 ms 30.58 ms

App size

Revision Plain With Sentry Diff
7480abe+dirty 7.15 MiB 8.41 MiB 1.26 MiB
2b89ce9+dirty 7.15 MiB 8.41 MiB 1.26 MiB
170d5ea+dirty 7.15 MiB 8.42 MiB 1.27 MiB
b1579bc+dirty 43.94 MiB 49.27 MiB 5.33 MiB
73f2455+dirty 43.94 MiB 48.82 MiB 4.88 MiB
0b64753+dirty 7.15 MiB 8.42 MiB 1.27 MiB
6a70a7e+dirty 7.15 MiB 8.42 MiB 1.26 MiB
2adbd1e+dirty 7.15 MiB 8.43 MiB 1.28 MiB
f8d19f8+dirty 43.94 MiB 48.91 MiB 4.97 MiB
7be1f99+dirty 7.15 MiB 8.42 MiB 1.27 MiB

Copy link
Contributor

@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.

Awesome idea and execution @alwx 🎸

⚠️ Currently is works on Android without any further changes but on iOS it only works with a minor change to SentrySDKLog.swift. The change is done in this PR: getsentry/sentry-cocoa#7444

Since this requires a Cocoa change we may target v8 (or wait to be merged) since the v9 bumped required changes in the ObjC gluecode and there might be conflicts with the changes here.

@alwx alwx force-pushed the alwx/experiment/native-logs branch 2 times, most recently from ce577a8 to 2182293 Compare February 16, 2026 09:02
@alwx
Copy link
Contributor Author

alwx commented Feb 16, 2026

@antonis rebased this one to the current main 🎉

@alwx alwx requested a review from antonis February 16, 2026 09:12
@alwx alwx force-pushed the alwx/experiment/native-logs branch from 2bfd1ba to 61ea8c0 Compare February 16, 2026 09:15
// Use our custom logger that forwards to JS
options.setLogger(rnLogger);
},
logger);
Copy link

Choose a reason for hiding this comment

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

Current activity no longer set during SDK initialization

High Severity

The call to RNSentryStart.startWithOptions switched from the overload accepting an Activity parameter (which passed getCurrentActivity()) to the overload accepting an OptionsConfiguration lambda. The new overload internally calls updateWithReactDefaults(options, null), which means CurrentActivityHolder is never set with the current activity during initialization. This breaks features that depend on having the current activity available early, such as screenshot attachment, view hierarchy capture, and other activity-dependent functionality.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might still be valid. The startWithOptions called here is also used in the RNSentrySDK but RNSentrySDK is a standalone utility class for initializing the SDK outside of a React Native module context. There's no getCurrentActivity() available at that call site.
The RNSentryModuleImpl is different: it runs inside the RN bridge and does have access to getCurrentActivity(). The issue is specifically that the refactored call switched from the activity-aware overload to the no-activity overload, dropping the activity that was previously available and passed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@alwx Maybe we can create a new overload in RNSentryStart that accepts both the activity and the options and then use it here. Something like:

  static void startWithOptions(                                                                                                                            
      @NotNull final Context context,                                                                                                                      
      @NotNull final ReadableMap rnOptions,                                                                                                                
      @Nullable Activity currentActivity,
      @NotNull Sentry.OptionsConfiguration<SentryAndroidOptions> configuration,
      @NotNull ILogger logger) {
    Sentry.OptionsConfiguration<SentryAndroidOptions> defaults =
        options -> updateWithReactDefaults(options, currentActivity);
    Sentry.OptionsConfiguration<SentryAndroidOptions> rnConfigurationOptions =
        options -> getSentryAndroidOptions(options, rnOptions, logger);
    RNSentryCompositeOptionsConfiguration compositeConfiguration =
        new RNSentryCompositeOptionsConfiguration(
            rnConfigurationOptions, defaults, configuration, RNSentryStart::updateWithReactFinals);
    SentryAndroid.init(context, compositeConfiguration);
  }

Copy link
Contributor

@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.

⚠️ Currently is works on Android without any further changes but on iOS it only works with a minor change to SentrySDKLog.swift. The change is done in this PR: getsentry/sentry-cocoa#7444

Since this requires a Cocoa change we may target v8 (or wait to be merged) since the v9 bumped required changes in the ObjC gluecode and there might be conflicts with the changes here.

This should be unblocked by #5724 since getsentry/sentry-cocoa#7444 is included in 9.5.1 🎉

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1211.54 ms 1212.04 ms 0.50 ms
Size 3.38 MiB 4.79 MiB 1.41 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
ea3e26e+dirty 1229.13 ms 1228.46 ms -0.67 ms
80e4616+dirty 1221.32 ms 1225.64 ms 4.32 ms
818a608+dirty 1205.76 ms 1208.00 ms 2.24 ms
77061ed+dirty 1233.16 ms 1234.88 ms 1.71 ms
bef3709+dirty 1222.07 ms 1220.24 ms -1.83 ms
a206511+dirty 1185.00 ms 1186.35 ms 1.35 ms
74979ac+dirty 1210.49 ms 1213.31 ms 2.82 ms
a2bb688+dirty 1223.53 ms 1232.90 ms 9.37 ms
8a868fe+dirty 1221.50 ms 1230.78 ms 9.28 ms
d590428+dirty 1211.77 ms 1220.51 ms 8.75 ms

App size

Revision Plain With Sentry Diff
ea3e26e+dirty 3.41 MiB 4.58 MiB 1.17 MiB
80e4616+dirty 3.38 MiB 4.60 MiB 1.22 MiB
818a608+dirty 2.63 MiB 3.91 MiB 1.28 MiB
77061ed+dirty 2.63 MiB 3.98 MiB 1.34 MiB
bef3709+dirty 3.38 MiB 4.78 MiB 1.40 MiB
a206511+dirty 3.41 MiB 4.67 MiB 1.25 MiB
74979ac+dirty 3.38 MiB 4.60 MiB 1.22 MiB
a2bb688+dirty 2.63 MiB 3.99 MiB 1.36 MiB
8a868fe+dirty 3.38 MiB 4.60 MiB 1.22 MiB
d590428+dirty 3.38 MiB 4.78 MiB 1.39 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1221.73 ms 1224.90 ms 3.16 ms
Size 3.38 MiB 4.79 MiB 1.41 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
ea3e26e+dirty 1216.61 ms 1214.15 ms -2.47 ms
80e4616+dirty 1206.90 ms 1205.94 ms -0.96 ms
818a608+dirty 1218.84 ms 1223.18 ms 4.34 ms
77061ed+dirty 1210.77 ms 1218.45 ms 7.68 ms
bef3709+dirty 1217.79 ms 1225.33 ms 7.54 ms
a206511+dirty 1225.02 ms 1223.74 ms -1.28 ms
74979ac+dirty 1212.33 ms 1212.54 ms 0.21 ms
a2bb688+dirty 1244.82 ms 1238.60 ms -6.22 ms
8a868fe+dirty 1206.85 ms 1215.04 ms 8.19 ms
d590428+dirty 1221.23 ms 1225.27 ms 4.03 ms

App size

Revision Plain With Sentry Diff
ea3e26e+dirty 3.41 MiB 4.58 MiB 1.17 MiB
80e4616+dirty 3.38 MiB 4.60 MiB 1.22 MiB
818a608+dirty 3.19 MiB 4.48 MiB 1.29 MiB
77061ed+dirty 3.19 MiB 4.54 MiB 1.36 MiB
bef3709+dirty 3.38 MiB 4.78 MiB 1.40 MiB
a206511+dirty 3.41 MiB 4.67 MiB 1.25 MiB
74979ac+dirty 3.38 MiB 4.60 MiB 1.22 MiB
a2bb688+dirty 3.19 MiB 4.56 MiB 1.37 MiB
8a868fe+dirty 3.38 MiB 4.60 MiB 1.22 MiB
d590428+dirty 3.38 MiB 4.78 MiB 1.39 MiB

@alwx alwx requested a review from antonis February 27, 2026 10:28
@lucas-zimerman
Copy link
Collaborator

lets add the suggested changelog and LGTM! Thank you for the PR!

@alwx alwx requested a review from antonis February 27, 2026 14:16
@alwx alwx force-pushed the alwx/experiment/native-logs branch from 913b181 to be4b465 Compare February 27, 2026 15:31
@alwx alwx requested a review from lucas-zimerman February 27, 2026 15:35
@lucas-zimerman
Copy link
Collaborator

it's weird the ios test is failing with any error

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@alwx alwx requested a review from antonis March 3, 2026 13:55
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.

SDK Handling HTTP 413 [React Native] Show Native Logs

3 participants