getsentry / sentry-xamarin

Sentry for Xamarin Native and Xamarin.Forms
https://docs.sentry.io/platforms/dotnet/guides/xamarin/
44 stars 11 forks source link

Sentry does not work in XamarinForms.iOS apps #131

Closed PavelRPavlov closed 1 year ago

PavelRPavlov commented 1 year ago

Package

Other

.NET Flavor

Xamarin

.NET Version

.NET Standard 2.0

OS

iOS

SDK Version

1.4.4

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. In VisualStudio (for Windows) create new solution with the template called "MobileApp" - this should create XamarinForms app with Flyout navigation
  2. Install Sentry latest nugets for all projects in the created solution
  3. Init SentrySdk for the iOS project as demonstrated in the sample
  4. Open ItemDetailPage.xaml.cs and throw exception in the constructor
  5. Deploy the app to an iPhone
  6. Start the app and navigate to Browse page then click on any item in the list -> this should open the ItemDetailPage
  7. The app will crash due to the exception and will terminate
  8. Open the app for the second time

Expected Result

Either on step 7 or on step 8 the Sentry should send out the crash report

Actual Result

The crash report does not get sent even after restarting the app

mattjohnsonpint commented 1 year ago

Just to confirm, you're asking about a traditional Xamarin Forms iOS app, and not a new net6.0-ios, net7.0-ios or .NET MAUI app - correct?

PavelRPavlov commented 1 year ago

@mattjohnsonpint yes, that is correct. Currently we are targeting Xamarin.Forms 5.0 for all platforms, but the reported issue is only present for the iOS platform

lucas-zimerman commented 1 year ago

Are you throwing an exception during the initialization from the app? One symptom could be that the SDK doesn't have enough time to flush the Cache, you can increase it by altering the InitCacheFlushTimeout:

                options.InitCacheFlushTimeout = TimeSpan.FromSeconds(5);

Furthermore, could you share the SDK log by enabling the Debug parameter?

                options.Debug = true;
PavelRPavlov commented 1 year ago

@lucas-zimerman Thank you for the suggestions. The Debug parameter is set, as it is set in the aforementioned sample project. However, the InitCacheFlushTimeout was not, but it does not affect the behavior of the iOS app. Regarding your 1st question, I am throwing a test exception after the app is initialized. To further test if that is not an issue on my end I tried to delay the exception throwing by using a timer which was triggered after the ItemDetailPage is fully loaded. I tested delaying 1s, 5s and 10s but the results were the same - I could not see reports in the web dashboard even after restarting the app.

PavelRPavlov commented 1 year ago

To speed up the testing on your side, I am sharing the project that I am testing with. You should be able to restore all nugets and build the app since this is newly created solution from the official XF template in VS. You may want to change the DSN setting in the AppDelegate.cs and to see the timing for the triggering of the exception you can inspect the ItemDetailPage.xaml.cs file xfSentryTest.zip

lucas-zimerman commented 1 year ago

Hello @PavelRPavlov and thanks for your sample project!

It seems like you're facing the problem described here: https://docs.sentry.io/platforms/dotnet/guides/xamarin/troubleshooting/#eventtransaction-capture You can fix it by following the described solution on the troubleshooting page, but in short, you need to install the package System.Memory on a special way.

mattjohnsonpint commented 1 year ago

@lucas-zimerman - It would appear that the Xamarin bug that is referenced in the troubleshooting docs has been resolved.

@PavelRPavlov - Please check the Xamarin version you have installed. In Visual Studio, go to Help - About, then scroll the list of installed products to the bottom where it gives the version for Xamarin.iOS and Xamarin.Mac SDK.

You can update it using Visual Studio Installer.

PavelRPavlov commented 1 year ago

@mattjohnsonpint I checked which are the versions installed on my machine and it turned out I had all the latest.