Skip to content

Fix Android logcat spam from empty call.resolve()#1123

Closed
mattriese wants to merge 5 commits intogetsentry:mainfrom
mattriese:fix/log-spam
Closed

Fix Android logcat spam from empty call.resolve()#1123
mattriese wants to merge 5 commits intogetsentry:mainfrom
mattriese:fix/log-spam

Conversation

@mattriese
Copy link
Copy Markdown

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Wrap all call.resolve() invocations with JSObject() (e.g. call.resolve(new JSObject())) for plugin methods that return no meaningful data, instead of calling call.resolve() with no argument.

This prevents Android logcat from being flooded with blank/undefined console log entries. When Capacitor's bridge completes a plugin call, it logs the resolved value to logcat. Calling call.resolve() with no argument causes Capacitor to log "File: - Line 333 - Msg: undefined" (or similar) for every completed call. By passing an empty JSObject instead, the bridge receives a valid serializable value and does not emit these noisy undefined logs.

💡 Motivation and Context

This addresses a known Capacitor Android bug: ionic-team/capacitor#8063 — "PluginCall.resolve logs in Logcat inconsistently". When call.resolve() is invoked with no argument, the Capacitor Console API logs undefined to logcat for every completed plugin call.

The Sentry Capacitor plugin makes many bridge calls, and several methods (especially addBreadcrumb, which runs for every console log captured as a breadcrumb) resolve with no return value. In apps with frequent logging or breadcrumb activity, this produces significant logcat spam—hundreds of lines like:

Capacitor/Console I  File: -  Line: 333  Msg: undefined

This obscures real logs and makes Android debugging difficult. The fix is a simple workaround: pass new JSObject() to call.resolve() instead of nothing. Capacitor does not log when given a proper object, so the spam is eliminated.

Related: ionic-team/capacitor#8063 (closed, fixed in Capacitor core via #8225). This change provides the same workaround for users on older Capacitor versions and ensures clean logcat output regardless.

💚 How did you test it?

I have been using this fork in my app for 2+ months now and it has been working great. I have not noticed any regressions. I forked off of 2.4.1 and just merged in 3.0.0. I will mark this as ready after using the new merged version for a while.

  1. Before the fix: Run the app, trigger normal Sentry activity (console breadcrumbs, init, etc.). Observe logcat: many lines of Capacitor/Console I ... Msg: undefined.
  2. After the fix: Same scenario. Logcat no longer shows undefined entries for Sentry plugin completions; only meaningful logs appear.

📝 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

None. This is a self-contained bugfix.

When Capacitor Android bridge methods resolve with no payload (call.resolve()),
the bridge logs "undefined" to Logcat for each call. This creates massive log
spam for high-frequency methods like addBreadcrumb (called for every console log).

Changes:
- addBreadcrumb: resolve with new JSObject() instead of no args
- captureEnvelope: resolve with new JSObject() instead of no args
- closeNativeSdk: resolve with new JSObject() instead of no args
- setExtra: resolve with new JSObject() instead of no args
- setTag: resolve with new JSObject() instead of no args
- clearBreadcrumbs: add missing call.resolve(new JSObject())
- setUser: add missing call.resolve(new JSObject())
- iOS setContext: add missing call.resolve() for parity

Fixes the "Capacitor/Console I File: - Msg: undefined" spam in Logcat
when console breadcrumbs are enabled.

See: ionic-team/capacitor#4986
@github-actions
Copy link
Copy Markdown
Contributor

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


  • Fix Android logcat spam from empty call.resolve() by mattriese in #1123

🤖 This preview updates automatically when you update the PR.

# And the CLI then renames it

# node files
dist/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lets keep dist on this list

@@ -1,11 +1,11 @@
{
"name": "@sentry/capacitor",
"homepage": "https://github.com/getsentry/sentry-capacitor",
"homepage": "https://github.com/mattriese/sentry-capacitor",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would you be able to undo the changes here?

@lucas-zimerman
Copy link
Copy Markdown
Collaborator

Thank you for this PR!
Would be able to say if you used any AI tool for writing this code?

}
call.resolve();
// Resolve with empty object to avoid Capacitor logging "undefined" to Logcat
// See: https://github.com/ionic-team/capacitor/issues/4986
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this link correct? it redirects to a PR ionic-team/capacitor#4986

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants