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

Add OS information from MAUI device data #1717

Merged
merged 3 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 device 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