Skip to content

Comments

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

Open
alwx wants to merge 12 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 12 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): update Sentry Android Gradle Plugin to v6.1.0 by github-actions in #5687
  • Ref(CI): Add android sdk version check by lucas-zimerman in #5686

🤖 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 85d0939

@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 416.23 ms 449.76 ms 33.53 ms
Size 43.75 MiB 48.42 MiB 4.67 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
ff5a06a+dirty 405.97 ms 439.24 ms 33.27 ms
8ff81c0+dirty 574.58 ms 611.44 ms 36.86 ms
8d0a325+dirty 406.48 ms 415.02 ms 8.54 ms
6c36ba5+dirty 385.48 ms 442.36 ms 56.88 ms
817b2c1+dirty 471.91 ms 489.55 ms 17.64 ms
136effd+dirty 398.57 ms 494.91 ms 96.34 ms
95aaf8a 437.89 ms 419.45 ms -18.44 ms
01d24f6+dirty 362.50 ms 362.23 ms -0.27 ms
6bb8427+dirty 360.48 ms 400.04 ms 39.56 ms
1853710 555.47 ms 556.59 ms 1.12 ms

App size

Revision Plain With Sentry Diff
ff5a06a+dirty 43.75 MiB 48.05 MiB 4.29 MiB
8ff81c0+dirty 43.75 MiB 48.05 MiB 4.29 MiB
8d0a325+dirty 43.75 MiB 48.08 MiB 4.33 MiB
6c36ba5+dirty 43.75 MiB 48.41 MiB 4.66 MiB
817b2c1+dirty 43.75 MiB 48.40 MiB 4.64 MiB
136effd+dirty 43.75 MiB 47.99 MiB 4.23 MiB
95aaf8a 17.75 MiB 19.68 MiB 1.93 MiB
01d24f6+dirty 17.75 MiB 19.74 MiB 2.00 MiB
6bb8427+dirty 43.75 MiB 48.08 MiB 4.33 MiB
1853710 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 403.78 ms 421.56 ms 17.78 ms
Size 43.94 MiB 49.29 MiB 5.35 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
55b77fc+dirty 410.46 ms 414.11 ms 3.65 ms
c7f264b+dirty 356.98 ms 407.46 ms 50.48 ms
90e7cb3+dirty 415.17 ms 458.48 ms 43.31 ms
d1fd647+dirty 374.46 ms 409.51 ms 35.05 ms
7091004+dirty 377.76 ms 402.11 ms 24.35 ms
69602ce+dirty 375.37 ms 405.28 ms 29.91 ms
1c38acd+dirty 411.84 ms 470.18 ms 58.34 ms
3e0a5f9+dirty 379.92 ms 450.96 ms 71.04 ms
bb4ea33+dirty 360.73 ms 375.02 ms 14.29 ms
0b64753+dirty 358.55 ms 429.16 ms 70.61 ms

App size

Revision Plain With Sentry Diff
55b77fc+dirty 43.94 MiB 48.82 MiB 4.88 MiB
c7f264b+dirty 7.15 MiB 8.41 MiB 1.26 MiB
90e7cb3+dirty 43.94 MiB 48.85 MiB 4.91 MiB
d1fd647+dirty 7.15 MiB 8.43 MiB 1.28 MiB
7091004+dirty 43.94 MiB 48.81 MiB 4.88 MiB
69602ce+dirty 7.15 MiB 8.41 MiB 1.26 MiB
1c38acd+dirty 43.94 MiB 48.91 MiB 4.97 MiB
3e0a5f9+dirty 7.15 MiB 8.42 MiB 1.27 MiB
bb4ea33+dirty 43.94 MiB 48.91 MiB 4.97 MiB
0b64753+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
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 🚢

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.

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

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