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 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
  • chore(deps): update Bundler Plugins to v5.1.1 by github-actions in #5700
  • chore(deps): update JavaScript SDK to v10.40.0 by github-actions in #5715
  • ci: Cancel in-progress CI jobs when a PR is closed or merged by antonis in #5725

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.

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

### Features

- [iOS + Android] Add the ability to intercept errors from native side and forward them to JS console ([#5622](https://github.com/getsentry/sentry-react-native/pull/5622))

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

Generated by 🚫 dangerJS against bd7b7fc

@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 413.90 ms 468.72 ms 54.82 ms
Size 43.75 MiB 48.48 MiB 4.73 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
ec14be7+dirty 403.50 ms 411.46 ms 7.96 ms
e76d0d3+dirty 404.18 ms 411.53 ms 7.35 ms
785ffb1 471.92 ms 460.96 ms -10.96 ms
ff5a06a+dirty 405.97 ms 439.24 ms 33.27 ms
6416d6c+dirty 407.30 ms 422.00 ms 14.70 ms
eec00c2+dirty 447.08 ms 469.04 ms 21.96 ms
7480abe+dirty 411.60 ms 405.81 ms -5.78 ms
c08359e 421.87 ms 445.37 ms 23.50 ms
64cd15c 439.02 ms 427.63 ms -11.39 ms
af9331b 449.77 ms 479.20 ms 29.43 ms

App size

Revision Plain With Sentry Diff
ec14be7+dirty 17.75 MiB 19.69 MiB 1.94 MiB
e76d0d3+dirty 17.75 MiB 19.71 MiB 1.96 MiB
785ffb1 17.75 MiB 20.15 MiB 2.41 MiB
ff5a06a+dirty 43.75 MiB 48.05 MiB 4.29 MiB
6416d6c+dirty 43.75 MiB 48.05 MiB 4.30 MiB
eec00c2+dirty 43.75 MiB 48.05 MiB 4.29 MiB
7480abe+dirty 17.75 MiB 19.68 MiB 1.94 MiB
c08359e 17.75 MiB 20.15 MiB 2.41 MiB
64cd15c 17.75 MiB 20.15 MiB 2.41 MiB
af9331b 17.75 MiB 19.68 MiB 1.94 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 465.28 ms 508.64 ms 43.36 ms
Size 43.94 MiB 49.34 MiB 5.40 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
785ffb1+dirty 380.65 ms 451.83 ms 71.18 ms
59d1977+dirty 366.15 ms 393.21 ms 27.06 ms
95aaf8a+dirty 342.82 ms 393.75 ms 50.93 ms
5ee3314+dirty 358.69 ms 394.00 ms 35.31 ms
b1579bc+dirty 391.87 ms 456.26 ms 64.39 ms
4052277+dirty 369.90 ms 381.16 ms 11.26 ms
4a17c8f+dirty 368.54 ms 381.43 ms 12.89 ms
eb07ba3+dirty 419.49 ms 482.12 ms 62.63 ms
cdf7e97+dirty 389.79 ms 418.13 ms 28.34 ms
93137d1+dirty 367.58 ms 434.94 ms 67.36 ms

App size

Revision Plain With Sentry Diff
785ffb1+dirty 7.15 MiB 8.42 MiB 1.27 MiB
59d1977+dirty 43.94 MiB 49.22 MiB 5.29 MiB
95aaf8a+dirty 7.15 MiB 8.41 MiB 1.26 MiB
5ee3314+dirty 7.15 MiB 8.43 MiB 1.28 MiB
b1579bc+dirty 43.94 MiB 49.27 MiB 5.33 MiB
4052277+dirty 43.94 MiB 49.38 MiB 5.44 MiB
4a17c8f+dirty 43.94 MiB 48.82 MiB 4.88 MiB
eb07ba3+dirty 7.15 MiB 8.42 MiB 1.27 MiB
cdf7e97+dirty 43.94 MiB 49.22 MiB 5.29 MiB
93137d1+dirty 7.15 MiB 8.43 MiB 1.28 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
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.

@antonis rebased this one to the current main 🎉

Awesome! The change LGTM. Let's wait for getsentry/sentry-cocoa#7444 to land in the next Cocoa release and 🚢

return;
}
sentryOptions.experimental.enableSessionReplayInUnreliableEnvironment = enabled;
// sentryOptions.experimental.enableSessionReplayInUnreliableEnvironment = enabled;
Copy link

Choose a reason for hiding this comment

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

Session replay setting silently disabled by commenting out

High Severity

The enableSessionReplayInUnreliableEnvironment assignment is commented out, making setEnableSessionReplayInUnreliableEnvironment:sentryOptions: a no-op. This is unrelated to the PR's native log forwarding feature. Callers in RNSentryStart.m and SentrySDKWrapper.m still invoke this method when session replay is enabled, but it now silently does nothing. This will break session replay on iOS 26+ (Liquid Glass) and cause multiple existing tests to fail because they assert enableSessionReplayInUnreliableEnvironment is set to YES.

Fix in Cursor Fix in Web


Sentry.init({
debug: true,
environment: 'dev',
Copy link

Choose a reason for hiding this comment

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

Development settings added to sample app configuration

Low Severity

debug: true and environment: 'dev' are newly added to the sample app's Sentry.init. While debug: true may be intentional to showcase the new native log forwarding feature, environment: 'dev' appears to be a personal development setting unrelated to this PR's purpose. These settings weren't present before and change the sample app's default behavior for anyone using it as a reference.

Fix in Cursor Fix in Web

* This allows native SDK logs to appear in the Metro console when debug mode is enabled.
*/
public class RNSentryLogger implements ILogger {
private static final String TAG = "Sentry";
Copy link

Choose a reason for hiding this comment

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

Android Logcat tag silently changed from "RNSentry" to "Sentry"

Low Severity

RNSentryLogger uses TAG = "Sentry" for its internal AndroidLogger, but the previous logger in RNSentryModuleImpl used NAME = "RNSentry" as the Logcat tag. This silently changes all Logcat output tags for the React Native Sentry module, which could break developers' Logcat filtering workflows that rely on the "RNSentry" tag.

Additional Locations (1)

Fix in Cursor Fix in Web

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 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

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 1208.07 ms 1212.53 ms 4.46 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 1186.73 ms 1193.26 ms 6.52 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!

],
});
```
- Add `onNativeLog` callback to intercept and forward native SDK logs to JavaScript console
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move the changelog entry in the unreleased section. Other than that LGTM

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