getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
584 stars 206 forks source link

Document how to initialize Sentry on native mobile apps (not MAUI) #3651

Open sauravchaudhary94 opened 2 weeks ago

sauravchaudhary94 commented 2 weeks ago

Hi,

I have seen earlier we have support of sentry on Xamarin.Forms as well as Xamarin.Android project. But now with documentation I can see it only for Maui , I don't see any integration documentation for Maui.Android(.net For Android) project, may you please help me if we can integrate sentry with native Maui project as well? I am having .Net for Android project and want to integrate logging using it.

bruno-garcia commented 2 weeks ago

For native Android apps with .NET, without MAUI, you can just use the Sentry SDK.

It includes the bindings under the hood when you compile for netX-android.

The Sentry.Maui package has MAUI specific stuff, and depends on the core Sentry package with the bindings stuff. It's what I did on Symbol Collector. It's a .NET app running on Android, without any MAUI.

We could do a better job of describing that on the docs, this has come up before.

bruno-garcia commented 2 weeks ago

I'll keep it open so we can document this better

sauravchaudhary94 commented 2 weeks ago

Thanks, can you please provide some insights on after adding sentry as nuget how will we register it and how to capture logs ? It will be great help.

bruno-garcia commented 2 weeks ago

Thanks, can you please provide some insights on after adding sentry as nuget how will we register it and how to capture logs ? It will be great help.

@sauravchaudhary94 it's the same as any other .NET app.

You can follow the standard .NET docs: https://docs.sentry.io/platforms/dotnet/

Here's a sample:

https://github.com/getsentry/sentry-dotnet/blob/23ad0b4b3bbbdf106ef59cf7cc165c71cb417207/samples/Sentry.Samples.Ios/AppDelegate.cs#L15-L26

**don't forget to change that URL (called DSN) in the sample with your own URL*** You'll get your own DSN when you create a project in Sentry. Just pick "project type .NET". Doesn't need to be any framework since you're not using MAUI, Xamarin, ASPNET or anything. It's plain .NET.

sauravchaudhary94 commented 2 weeks ago

Thanks @bruno-garcia , I have implemented it in sample project. If you need any participation from my end while documenting, I am open to contribute. Thanks again.

jamescrosswell commented 2 weeks ago

I'm wondering where we'd document this. Would we create separate "platforms" in the docs for Android and iOS under the .NET documentation?

bruno-garcia commented 3 days ago

I'm wondering where we'd document this. Would we create separate "platforms" in the docs for Android and iOS under the .NET documentation?

Sounds like a good approach to me. It could even be the original snippet we have, with:

Sentry.Init(o => {
 o.Stuff = // the current documented stuff that's already there, etc

#if ANDROID
 o.Native.Something = bla; // optional Android specific docs
#elif IOS 
 o.Native.Something = bla; // optional iOS specific docs
#endif
})

And on the text above mention that if no specific framework is used, just install Sentry. And that will work on Windows, macOS, Linux, Android, iOS and in the Browser. And includes native integrations for Android and iOS.