Skip to content

Commit

Permalink
Various .NET MAUI fixes / improvements (#2403)
Browse files Browse the repository at this point in the history
* Fix battery level

* Set OS architecture

* Fix Windows OS version info

* Fix in-app frames for Windows

* Fix in-app frames for iOS/MacCatalyst

* Update CHANGELOG.md
  • Loading branch information
mattjohnsonpint authored Jun 1, 2023
1 parent 80c3227 commit f551ffe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

- SentryHttpMessageHandler added when AddHttpClient is before UseSentry ([#2390](https://github.com/getsentry/sentry-dotnet/pull/2390))
- Set the native sdk name for Android ([#2389](https://github.com/getsentry/sentry-dotnet/pull/2389))
- Various .NET MAUI fixes / improvements ([#2403](https://github.com/getsentry/sentry-dotnet/pull/2403))
- The battery level was being reported incorrectly due to percentage multiplier.
- The device architecture (x64, arm64, etc.) is now reported
- On Windows, the OS type is now reported as "Windows" instead of "WinUI". Additionally, the OS display version (ex, "22H2") is now included.
- `UIKit`, `ABI.Microsoft` and `WinRT` frames are now marked "system" instead of "in app".

### Dependencies

Expand Down
4 changes: 2 additions & 2 deletions src/Sentry.Maui/Internal/MauiDeviceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public static void ApplyMauiDeviceData(this Device device, IDiagnosticLogger? lo
// device.Brand ??= ?
// device.Family ??= ?
// device.ModelId ??= ?
// device.Architecture ??= ?
device.Architecture ??= RuntimeInformation.OSArchitecture.ToString();
// ? = deviceInfo.Platform;
// ? = deviceInfo.VersionString;

// https://docs.microsoft.com/dotnet/maui/platform-integration/device/battery
try
{
var battery = Battery.Default;
device.BatteryLevel ??= battery.ChargeLevel < 0 ? null : (short)battery.ChargeLevel;
device.BatteryLevel ??= battery.ChargeLevel < 0 ? null : (short)(battery.ChargeLevel * 100.0);
device.BatteryStatus ??= battery.State.ToString();
device.IsCharging ??= battery.State switch
{
Expand Down
24 changes: 18 additions & 6 deletions src/Sentry.Maui/Internal/MauiOsData.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Win32;
using Sentry.Extensibility;
using OperatingSystem = Sentry.Protocol.OperatingSystem;

Expand All @@ -17,13 +18,24 @@ public static void ApplyMauiOsData(this OperatingSystem os, IDiagnosticLogger? l
return;
}

os.Name ??= deviceInfo.Platform.ToString();
os.Version ??= deviceInfo.VersionString;
os.Version = deviceInfo.VersionString;

#if WINDOWS
os.Name ??= "Windows";

using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
if (key?.GetValue("DisplayVersion") is string displayVersion)
{
os.Build = displayVersion;
}
else if (key?.GetValue("ReleaseId") is string releaseId)
{
os.Build = releaseId;
}
#else
os.Name = deviceInfo.Platform.ToString();
#endif

// TODO: fill in these
// os.Build ??= ?
// os.KernelVersion ??= ?
// os.Rooted ??= ?
}
catch (Exception ex)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,9 @@ public SentryOptions()
"Sentry",
"Microsoft",
"MS", // MS.Win32, MS.Internal, etc: Desktop apps
"ABI.Microsoft", // MAUI
"WinRT", // WinRT, UWP, WinUI
"UIKit", // iOS / MacCatalyst
"Newtonsoft.Json",
"FSharp",
"Serilog",
Expand Down

0 comments on commit f551ffe

Please sign in to comment.