getsentry / sentry-dotnet

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

device context not included in new sentry .net sdk #285

Open tgreenman opened 5 years ago

tgreenman commented 5 years ago

When attempting to integrate with sentry .net using the nlog integration, I noticed that device context wasn't being sent up like other platforms already do.

The older raven-csharp sdk appears to support adding this information based on https://github.com/getsentry/raven-csharp/blob/4fdc94eb514d96c22a83d851e2141fa9df10f613/src/app/SharpRaven/Data/Context/Device.cs#L212. (I haven't actually integrated with raven-csharp to verify, just assuming based on this file).

Is sentry-dotnet intended to not add this information by default? Example information I'm looking for is cpu arch, screen_resolution, storage, memory, and etc

bruno-garcia commented 5 years ago

That part should have been moved to Sentry.PlatformAbstractions but that's right it seems not to have been there.

CPU arch is straight forward to add (the code in SharpRaven) but I'm afraid screen resolution is going to be less platform independent.

Could you please share what framework are you using? Is this Xamarin, WPF, UWP etc?

bruno-garcia commented 5 years ago

There's actually an issue on PlatformAbstractions:

https://github.com/getsentry/sentry-dotnet-platform-abstractions/issues/7

I'm planning to sunset that lib and just bring the relevant bits to this repo, inside the Sentry package. With that we can drop support .NET Framework 3.5 to 4.6.0 which simplifies things a lot.

tgreenman commented 5 years ago

I'm using WPF, but saw this with a c# console application too. For clarity, here's a picture of the section I was expecting on the sentry website after a report https://i.imgur.com/MkaJFL1.png. Windows would obviously be different (android shown), but that information seems to come for free on the current MacOS and Android SDKs

bruno-garcia commented 5 years ago

We use the APIs available in the specific frameworks. Like Unity gives us some API as well as Android and unfortunately we don't have some in .NET. We could try to fetch data when running on .NET Framework but I'm unaware of a multi-platform (.NET Core/.NET Standard) way to get it.

For example to get battery level one can use System.Windows.Forms.SystemInformation.PowerStatus.

That namespace is for WinForms, which was ported to .NET Core (Windows only).

We can investigate what information to retrieve and try to find a way to get it for .NET Standard, or at least for the .NET Framework target.

SimonCropp commented 2 years ago

TODO: we will confirm all the context we have and if anything is missing.

bitsandfoxes commented 2 months ago

Wait, an issue about the SDK not automatically populating the device context? That doesn't sound right. Is this about the NLog integration specifically?

hemulator commented 2 weeks ago

This issue is still not resolved 5 years after it was found. What the current plan to solve it? Without OS and device data, it's much harder to figure out the root causes of the issues.

bruno-garcia commented 2 weeks ago

This issue is still not resolved 5 years after it was found. What the current plan to solve it? Without OS and device data, it's much harder to figure out the root causes of the issues.

Which data exactly are you missing? The SDK sends OS name and version, runtime name and version and a lot of other context.

This is what I see from an ASP.NET Core server (+ user browser info) ![Image](https://github.com/user-attachments/assets/132e2535-6b3e-430f-aeab-dee3ae89054d)
This is from a native Android app written in C# ![Image](https://github.com/user-attachments/assets/10387e78-b49f-4529-ad49-aad4575605d1)
I also see Memory Info, Thread Pool info and more ![Image](https://github.com/user-attachments/assets/5bf529ee-53a4-4eea-83cf-211bdef9abc3)

A list of things we could add and if possible, what APIs are available to get them, would be very helpful.

hemulator commented 2 weeks ago

This is what I see for Sentry UWP SDK events: Image

bruno-garcia commented 2 weeks ago

@hemulator could you share the SDK version you're on? If you could share a link to an event in Sentry, that'd be helpful

hemulator commented 2 weeks ago

And this is the event details: Image

There's obviously things missing.

bruno-garcia commented 2 weeks ago

It looks like some UWP thing. Since .NET Core 4.6 doesn't exist, that already looks off.

hemulator commented 2 weeks ago

I'm using the same nuget package as for any other .NET. It compatible works fine except device/OS context. https://www.nuget.org/packages/Sentry/4.13.0?_src=template

bruno-garcia commented 2 weeks ago

I'm using the same nuget package as for any other .NET. It compatible works fine except device/OS context. https://www.nuget.org/packages/Sentry/4.13.0?_src=template

I understand it's the same package, we don't have one just for UWP. That said, UWP isn't .NET, so some of .NET's APIs to get device data might not be available there.

How would you get device information from a UWP app? Which APIs would you use?

We might be able to add a net8.0-windows target, and use Windows-only APIs to get additional data. If that makes sense.

bruno-garcia commented 2 weeks ago

These folks are adding additional context to the SDK based on some other APIs available. We could learn something from them:

https://github.com/Valkirie/HandheldCompanion/blob/32e011cc677312e3d6894a7fb758924ee6bbeafb/HandheldCompanion/Devices/IDevice.cs#L560-L567