Repository navigation
ref(logs): Intercept Native SDK logs - #1249
Conversation
…gs to JS Migrated from sentry-react-native#5622. Adds an `onNativeLog` option that lets users surface native SDK logs (e.g. HTTP 413 transport errors) in the browser console when `debug: true` is set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…fyListeners Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
…/sentry-capacitor into lz/intercept-js-errors
…/sentry-capacitor into lz/intercept-js-errors
…o resolve Swift concurrency warning Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
q: Is the move of Package.resolved moved to root intentional?
There was a problem hiding this comment.
not really, let me rollback
antonis
left a comment
There was a problem hiding this comment.
Other than the package move LGTM
SDK libraries should not commit Package.resolved — SPM ignores it from dependencies and only the consuming app's lock file is used. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| @@ -1,23 +0,0 @@ | |||
| { | |||
There was a problem hiding this comment.
Tooling opted to not have this file
| androidLogger.log(level, message, args); | ||
|
|
||
| String formattedMessage = | ||
| (args == null || args.length == 0) ? message : String.format(message, args); |
There was a problem hiding this comment.
Unprotected String.format can throw uncaught exception
Medium Severity
The String.format(message, args) calls in the log methods are not wrapped in try-catch. The underlying AndroidLogger.log() internally catches IllegalFormatException from malformed format strings (this was a known crash, sentry-java#1985), but the subsequent String.format call in CapSentryLogger lacks this same protection. If format specifiers in message don't match args, an IllegalFormatException will propagate uncaught into the SDK internals.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 19cae50. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
There are 3 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d8d9fc9. Configure here.
| export function setupNativeLogListener(callback: (log: NativeLogEntry) => void): void { | ||
| if (_removeListener) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Re-init leaves log listener active
Medium Severity
Calling Sentry.init again without close() can leave native log forwarding enabled when debug is later false, and a second init with debug: true will not replace onNativeLog because setupNativeLogListener exits when a listener already exists and sdkInit only registers a listener when debug is true, never tearing it down on init.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit d8d9fc9. Configure here.
| data.put("level", level.name().toLowerCase()); | ||
| data.put("component", "Sentry"); | ||
| data.put("message", message); | ||
| currentEmitter.emit(data); |
There was a problem hiding this comment.
Android forwards logs without debug
Medium Severity
On Android, every native Sentry log is emitted over the Capacitor bridge via notifyListeners whenever the plugin loads, even when debug is false and JavaScript never registers SentryNativeLog, unlike iOS where forwarding is configured only when native debug is enabled.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit d8d9fc9. Configure here.


📢 Type of change
📜 Description
Based on getsentry/sentry-react-native#5622
This PR redirects native Sentry logs to be visible along with the JavaScript logs
💡 Motivation and Context
Allow users to see all SDK logs on a unified way.
💚 How did you test it?
Android logs

iOS

📝 Checklist
sendDefaultPIIis enabled🔮 Next steps
Close #1093