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 11 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 11 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 JavaScript SDK to v10.39.0 by github-actions in #5674
  • fix(spotlight): Add Sentry Spotlight dependency for debug builds by romtsn in #5667
  • chore(deps): bump github/codeql-action from 4.32.2 to 4.32.3 by dependabot in #5669
  • chore(deps): bump faraday from 1.10.4 to 1.10.5 in /samples/react-native-macos by dependabot in #5671
  • chore(deps): bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.21.2 to 2.21.4 by dependabot in #5668
  • chore(deps): bump getsentry/craft from 2.21.2 to 2.21.4 by dependabot in #5670
  • feat: v8: Expose iOS options to ignore views from subtree traversal by antonis in #5663
  • chore(deps): bump faraday from 1.10.4 to 1.10.5 in /samples/react-native by dependabot in #5658
  • chore(deps): bump faraday from 1.10.4 to 1.10.5 in /performance-tests by dependabot in #5659

🤖 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 fcba8c8

@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 447.61 ms 502.88 ms 55.27 ms
Size 43.75 MiB 48.42 MiB 4.67 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
2f9fb30+dirty 416.78 ms 444.94 ms 28.16 ms
8d89cc9+dirty 537.83 ms 536.02 ms -1.81 ms
6fee48d+dirty 407.42 ms 437.71 ms 30.29 ms
d751a5d+dirty 434.24 ms 486.08 ms 51.84 ms
05bef0e+dirty 349.78 ms 334.04 ms -15.74 ms
f8d19f8+dirty 422.98 ms 421.98 ms -1.00 ms
cd5f27f+dirty 494.04 ms 516.62 ms 22.58 ms
1ef8a04+dirty 415.16 ms 415.22 ms 0.06 ms
459a438+dirty 417.09 ms 406.52 ms -10.57 ms
5c16cdc+dirty 423.48 ms 452.35 ms 28.88 ms

App size

Revision Plain With Sentry Diff
2f9fb30+dirty 43.75 MiB 48.05 MiB 4.29 MiB
8d89cc9+dirty 17.75 MiB 19.68 MiB 1.94 MiB
6fee48d+dirty 17.75 MiB 19.68 MiB 1.94 MiB
d751a5d+dirty 17.75 MiB 19.68 MiB 1.94 MiB
05bef0e+dirty 17.75 MiB 19.70 MiB 1.95 MiB
f8d19f8+dirty 43.75 MiB 48.08 MiB 4.33 MiB
cd5f27f+dirty 43.75 MiB 48.41 MiB 4.66 MiB
1ef8a04+dirty 43.75 MiB 48.05 MiB 4.29 MiB
459a438+dirty 17.75 MiB 19.70 MiB 1.95 MiB
5c16cdc+dirty 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 437.64 ms 487.13 ms 49.49 ms
Size 43.94 MiB 49.29 MiB 5.35 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6c11c6a+dirty 462.02 ms 488.50 ms 26.48 ms
b80b14f+dirty 320.33 ms 376.06 ms 55.73 ms
05bef0e+dirty 451.63 ms 533.90 ms 82.27 ms
c4e097a+dirty 382.43 ms 443.77 ms 61.34 ms
6c36ba5+dirty 367.14 ms 426.80 ms 59.66 ms
cd5f27f+dirty 388.19 ms 447.42 ms 59.23 ms
136effd+dirty 451.30 ms 450.87 ms -0.43 ms
161947d+dirty 349.27 ms 435.09 ms 85.82 ms
2adbd1e+dirty 366.13 ms 419.49 ms 53.36 ms
180638b+dirty 434.46 ms 470.90 ms 36.44 ms

App size

Revision Plain With Sentry Diff
6c11c6a+dirty 43.94 MiB 48.92 MiB 4.98 MiB
b80b14f+dirty 43.94 MiB 48.87 MiB 4.93 MiB
05bef0e+dirty 7.15 MiB 8.43 MiB 1.28 MiB
c4e097a+dirty 7.15 MiB 8.41 MiB 1.26 MiB
6c36ba5+dirty 43.94 MiB 49.27 MiB 5.33 MiB
cd5f27f+dirty 43.94 MiB 49.27 MiB 5.33 MiB
136effd+dirty 43.94 MiB 48.81 MiB 4.88 MiB
161947d+dirty 7.15 MiB 8.43 MiB 1.28 MiB
2adbd1e+dirty 7.15 MiB 8.43 MiB 1.28 MiB
180638b+dirty 43.94 MiB 48.91 MiB 4.97 MiB

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Let's skip the changes on this file since it's mainly formatting

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 🚢

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