Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry support for AvaloniaUI #2614

Open
manuc66 opened this issue Sep 12, 2023 · 9 comments
Open

Sentry support for AvaloniaUI #2614

manuc66 opened this issue Sep 12, 2023 · 9 comments
Labels
Feature New feature or request New Package

Comments

@manuc66
Copy link

manuc66 commented Sep 12, 2023

Problem Statement

I am attempting to integrate Sentry into my AvaloniaUI application for error monitoring and reporting. However, I have encountered challenges as there doesn't seem to be official support or guidance for using the Sentry .NET SDK with AvaloniaUI applications.

Solution Brainstorm

No response

@manuc66 manuc66 added Feature New feature or request Platform: .NET labels Sep 12, 2023
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Sep 12, 2023
manuc66 added a commit to manuc66/ImgTagFanOut that referenced this issue Sep 12, 2023
@jamescrosswell
Copy link
Collaborator

Hey @manuc66, thanks for reaching out and you're right, we don't yet have anything built specifically to support Avalonia. Realistically, we won't have the bandwidth to build an official integration for this anytime soon.

I can try to help you work through the issues you've run into. As long as Avalonia has some kind of global exception handler, you could probably get some basic exception capturing going on.

There's quite a lot of complexity in instrumenting multi platform applications properly however. For our MAUI integration, we had to create bindings into Sentry's Android and iOS SDKs, to properly instrument the native code that gets produced when deploying to these platforms. That could maybe serve as an example of how this might be done in frameworks like Avalonia.

@bruno-garcia
Copy link
Member

bruno-garcia commented Sep 12, 2023

It should work with the core Sentry package. Just SentrySdk.Init early in the program. You can also use any Avalonia specific error handler and call into SentrySdk.CaptureException.

Here's how we document for WPF: https://docs.sentry.io/platforms/dotnet/guides/wpf/ (for WPF there was also #1036 )

That said, what would a specific Sentry.Avalonia offer? What kind of hooks, etc does Avalonia have that we could leverage?

@bitsandfoxes
Copy link
Contributor

Taken from the Avalonia docs Avalonia UI does not offer any mechanism to handle exceptions globally.
So I don't think there is anything a Sentry.Avalonia would be able to provide there from an error-capturing perspective.
Subscribing to lifetime events for breadcrumbs might be nice tho.

@bruno-garcia
Copy link
Member

Subscribing to lifetime events for breadcrumbs might be nice tho.

👍

@AArnott
Copy link

AArnott commented Jul 12, 2024

we had to create bindings into Sentry's Android and iOS SDKs, to properly instrument the native code that gets produced when deploying to these platforms

@jamescrosswell Does that mean AvaloniaUI apps should add Maui or Android/iOS packages specifically so that native code crashes will be handled properly? My Avalonia app runs on Windows/Linux/MacOS as will as Android and iOS. Do I need to add several packages with #if code to activate OS-specific hooks?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 12, 2024
@jamescrosswell
Copy link
Collaborator

@jamescrosswell Does that mean AvaloniaUI apps should add Maui or Android/iOS packages specifically so that native code crashes will be handled properly?

@AArnott you definitely wouldn't use the Maui package as that depends on Microsoft.Maui.Hosting.MauiAppBuilder (you won't have one of those in an AvaloniaUI app).

I'm not sure how you would use the Android, iOS and Native bindings from AvaloniaUI.

@bruno-garcia or @vaind might be able to answer as they were more involved in the Maui and Native integrations.

@bitsandfoxes
Copy link
Contributor

The core Sentry package handles the import of the bindings based on the targeted platform here

<!-- Platform-specific props included here -->
<Import Project="Platforms\Android\Sentry.Android.props" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
<Import Project="Platforms\Cocoa\Sentry.Cocoa.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
<Import Project="Platforms\Native\Sentry.Native.targets"
Condition="'$(TargetPlatformIdentifier)' != 'android' and '$(TargetPlatformIdentifier)' != 'ios' and '$(TargetPlatformIdentifier)' != 'maccatalyst'"/>

If AvaloniaUI has some different TargetPlatformIdentifiers that might be an additional thing a dedicated package could provide.

@AArnott
Copy link

AArnott commented Jul 12, 2024

That's very useful. I don't target maccatalyst explicitly. I just run the net8.0 targeted project on macos. It looks then like I'll get more out of sentry by targeting macos specifically, which I should be able to do.
And I was already targeting android explicitly.
Thanks!

@bruno-garcia
Copy link
Member

It looks then like I'll get more out of sentry by targeting macos specifically, which I should be able to do.

With the macos support of .NET we have Native AOT support, with native crashes included.
maccatalyst gives you bindings to the Sentry SDK for Cocoa which has many other features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request New Package
Projects
Status: No status
Development

No branches or pull requests

5 participants