Skip to content

Commit

Permalink
Add OS information from MAUI device data (#1717)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Jun 15, 2022
1 parent 711efd2 commit 54fded1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- MAUI events become extra context in Sentry events ([#1706](https://github.com/getsentry/sentry-dotnet/pull/1706))
- Add options for PII breadcrumbs from MAUI events ([#1709](https://github.com/getsentry/sentry-dotnet/pull/1709))
- Add device information to the event context ([#1713](https://github.com/getsentry/sentry-dotnet/pull/1713))
- Add platform OS information to the event context ([#1717](https://github.com/getsentry/sentry-dotnet/pull/1717))
- Added a new `net6.0-android` target for the `Sentry` core library, which bundles the [Sentry Android SDK](https://docs.sentry.io/platforms/android/):
- Initial .NET 6 Android support ([#1288](https://github.com/getsentry/sentry-dotnet/pull/1288))
- Update Android Support ([#1669](https://github.com/getsentry/sentry-dotnet/pull/1669))
Expand Down
34 changes: 34 additions & 0 deletions src/Sentry.Maui/Internal/MauiOsData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Sentry.Extensibility;
using OperatingSystem = Sentry.Protocol.OperatingSystem;

namespace Sentry.Maui.Internal;

internal static class MauiOsData
{
public static void ApplyMauiOsData(this OperatingSystem os, IDiagnosticLogger? logger)
{
try
{
// https://docs.microsoft.com/dotnet/maui/platform-integration/device/information
var deviceInfo = DeviceInfo.Current;
if (deviceInfo.Platform == DevicePlatform.Unknown)
{
// return early so we don't get NotImplementedExceptions (i.e., in unit tests, etc.)
return;
}

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

// TODO: fill in these
// os.Build ??= ?
// os.KernelVersion ??= ?
// os.Rooted ??= ?
}
catch (Exception ex)
{
// Log, but swallow the exception so we can continue sending events
logger?.LogError("Error getting MAUI OS information.", ex);
}
}
}
1 change: 1 addition & 0 deletions src/Sentry.Maui/Internal/SentryMauiEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public SentryEvent Process(SentryEvent @event)
@event.Sdk.Name = Constants.SdkName;
@event.Sdk.Version = Constants.SdkVersion;
@event.Contexts.Device.ApplyMauiDeviceData(_options.DiagnosticLogger);
@event.Contexts.OperatingSystem.ApplyMauiOsData(_options.DiagnosticLogger);

return @event;
}
Expand Down

0 comments on commit 54fded1

Please sign in to comment.