sentry-capacitor
sentry-capacitor copied to clipboard
[feature request] Migration docs for existing Sentry Capacitor users
I have a production Ionic/Angular/Capacitor project that was previously set up using:
- @sentry/browser (5.26.0) for Angular layer with deployment on native iOS, native Android, and public web app
- iOS Sentry / sentry-cocoa for native iOS crash reporting / low memory tracking etc and custom Capacitor plugin
- Android Sentry SDK for use in native Android crash reporting and custom Capacitor plugin
This has worked really nicely with a separate Sentry project for each of the above bullet points.
Now when moving from Capacitor 2 to 3, my existing sentry/browser Angular logging doesn't trigger Sentry error handling when operating inside the Capacitor webview, even though the exact same build triggers Sentry Error handling when served up directly in the browser. I have a custom ErrorHandler class in Angular, and for some reason it just isn't getting triggered.
As part of sentry/capacitor, it would be really useful if there were some docs in troubleshooting or the repo README to explain:
- Whether it's now required (maybe due to Capacitor 3 changes?) to move to sentry-capacitor, or if it's still possible to use classic sentry/browser inside a Capacitor 3 webview. Is there some special way of calling sentry/browser that will still work in a Capacitor webview?
- If sentry/capacitor is required, then is it safe to continue using the native Sentry libraries for iOS and Android in parallel (maybe with enableNative: false as part of Sentry.init in the webview)?
- Does sentry-capacitor provide access to native Sentry libs when writing Java or Swift code as part of Capacitor app or plugins?
Thanks
Hi So you were using sentry/browser with a native SDK? You can use Sentry Capacitor with Sentry Angular, and also interact with the Native SDK, for that you'll need to include the sentry-android implementation as a dependency on your Gradle build. On the iOS side you don't need to configure anything to access the native SDK.
About only using @sentry/browser I'm not sure at the moment so we'll need to investigate it. If you enable the debug flag on Sentry Options, does it point out why it's not registering events?
@thmclellan Make sure you have updated plugin initialization as required by Capacitor 3, described here: https://github.com/getsentry/sentry-capacitor/issues/174#issuecomment-1134678640.
Thanks @lucas-zimerman and @piotr-cz for the support here, I figured out the root cause of why my global error handler wasn't getting triggered on native, and it's not Sentry.
It turns out my underlying Ionic framework had a new bug in v5 that was swallowing errors with overlay prompts (https://github.com/ionic-team/ionic-framework/issues/22724). I was only using a prompt in the native build (to choose Web or Native crash), so I mistakenly assumed it was something broken at the sentry or capacitor level. Sorry for the mix-up, I thought it was because I was upgrading from sentry/browser.
Now it's working for both native and web-level errors on Android, iOS, and web builds. My native crash reporting is working on iOS and Android when calling bad functions in my custom Capacitor (v3) plugin, and an iOS share extension. Thanks for the tip about adding sentry-android to build.gradle.
My original setup was using @sentry/browser to capture Angular/Ionic level errors for all platforms, and separate native Sentry implementations for iOS and Android. The sentry-capacitor approach of using the same DSN / project is actually nicer because you can see DOM-level breadcrumbs leading up to a native crash.
From a docs perspective, it would be helpful to show an example of @sentry/angular with a custom error handler and an example of using Sentry in a capacitor plugin, but these may just be nice-to-have. Feel free to close this issue.