From 2c82b5aed774684771cf415282155a6f255e7aca Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Mon, 10 Feb 2025 16:37:06 -0500 Subject: [PATCH 1/7] Initial commit --- src/Sentry/Internal/Enricher.cs | 7 ++++ .../Sentry.Maui.Device.TestApp.csproj | 34 +++++++++---------- test/Sentry.Tests/Issue2710.cs | 29 ++++++++++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 test/Sentry.Tests/Issue2710.cs diff --git a/src/Sentry/Internal/Enricher.cs b/src/Sentry/Internal/Enricher.cs index 54829dca86..8a686fc8aa 100644 --- a/src/Sentry/Internal/Enricher.cs +++ b/src/Sentry/Internal/Enricher.cs @@ -45,8 +45,15 @@ public void Apply(IEventLike eventLike) } catch { eventLike.Contexts.OperatingSystem.RawDescription = Environment.OSVersion.VersionString; } + #else eventLike.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription; + if (eventLike.Contexts.OperatingSystem.RawDescription.StartsWith("Darwin")) + { + // works for catalyst and net9 base + eventLike.Contexts.OperatingSystem.Name = "macOS"; + eventLike.Contexts.OperatingSystem.Version = Environment.OSVersion.Version.ToString(); // reports macOS version (ie. 15.3.0) + } #endif } } diff --git a/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj b/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj index 24a25093a6..df8e93e506 100644 --- a/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj +++ b/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj @@ -1,9 +1,9 @@  - - $(TargetFrameworks);net8.0-android34.0 - $(TargetFrameworks);net8.0-ios17.0 + net8.0-maccatalyst17.0 + + true - + - - + + - - + + - - + + - - - - + + + + diff --git a/test/Sentry.Tests/Issue2710.cs b/test/Sentry.Tests/Issue2710.cs new file mode 100644 index 0000000000..1c5932ed5b --- /dev/null +++ b/test/Sentry.Tests/Issue2710.cs @@ -0,0 +1,29 @@ +using OperatingSystem = System.OperatingSystem; + +#if MACCATALYST +namespace Sentry.Maui.Tests; + +public class Issue2710 +{ + [Fact] + public void MacVersions() + { + var elike = Substitute.For(); + elike.Contexts = new SentryContexts(); + + var enricher = new Enricher(new SentryOptions()); + enricher.Apply(elike); + + elike.Contexts.OperatingSystem.Name.Should().Be("macOS"); + elike.Contexts.OperatingSystem.Version.Should().Be(Environment.OSVersion.Version.ToString()); + + // output.WriteLine("OS Arch: " + RuntimeInformation.OSArchitecture); + // output.WriteLine("Runtime: " + RuntimeInformation.RuntimeIdentifier); + // output.WriteLine("FW: " + RuntimeInformation.FrameworkDescription); + // output.WriteLine("RAW:" + RuntimeInformation.OSDescription); + // output.WriteLine("Env Platform: " + Environment.OSVersion.Platform); + // output.WriteLine("OS Version: " + Environment.OSVersion.Version); + } +} + +#endif From 3e40806b5a6bee00ee46d99b3a3a92e94b61d85f Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 11 Feb 2025 10:20:25 -0500 Subject: [PATCH 2/7] Finish --- src/Sentry/Internal/Enricher.cs | 2 +- test/Sentry.Tests/EnricherTests.cs | 22 ++++++++++++++++++++++ test/Sentry.Tests/Issue2710.cs | 29 ----------------------------- test/Sentry.Tests/PlatformFact.cs | 25 +++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 test/Sentry.Tests/EnricherTests.cs delete mode 100644 test/Sentry.Tests/Issue2710.cs create mode 100644 test/Sentry.Tests/PlatformFact.cs diff --git a/src/Sentry/Internal/Enricher.cs b/src/Sentry/Internal/Enricher.cs index 8a686fc8aa..3d3629934a 100644 --- a/src/Sentry/Internal/Enricher.cs +++ b/src/Sentry/Internal/Enricher.cs @@ -48,7 +48,7 @@ public void Apply(IEventLike eventLike) #else eventLike.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription; - if (eventLike.Contexts.OperatingSystem.RawDescription.StartsWith("Darwin")) + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { // works for catalyst and net9 base eventLike.Contexts.OperatingSystem.Name = "macOS"; diff --git a/test/Sentry.Tests/EnricherTests.cs b/test/Sentry.Tests/EnricherTests.cs new file mode 100644 index 0000000000..d4439c340a --- /dev/null +++ b/test/Sentry.Tests/EnricherTests.cs @@ -0,0 +1,22 @@ +using Sentry.Tests; + +namespace Sentry.Maui.Tests; + +public class EnricherTests +{ + [PlatformFact(Platform.MacOS)] + public void macOS_Platform_Version() + { + var elike = Substitute.For(); + elike.Sdk.Returns(new SdkVersion()); + elike.User = new SentryUser(); + elike.Contexts = new SentryContexts(); + + var enricher = new Enricher(new SentryOptions()); + enricher.Apply(elike); + + var os = elike.Contexts.OperatingSystem; + os.Name.Should().Be("macOS"); + os.Version.Should().Be(Environment.OSVersion.Version.ToString()); + } +} diff --git a/test/Sentry.Tests/Issue2710.cs b/test/Sentry.Tests/Issue2710.cs deleted file mode 100644 index 1c5932ed5b..0000000000 --- a/test/Sentry.Tests/Issue2710.cs +++ /dev/null @@ -1,29 +0,0 @@ -using OperatingSystem = System.OperatingSystem; - -#if MACCATALYST -namespace Sentry.Maui.Tests; - -public class Issue2710 -{ - [Fact] - public void MacVersions() - { - var elike = Substitute.For(); - elike.Contexts = new SentryContexts(); - - var enricher = new Enricher(new SentryOptions()); - enricher.Apply(elike); - - elike.Contexts.OperatingSystem.Name.Should().Be("macOS"); - elike.Contexts.OperatingSystem.Version.Should().Be(Environment.OSVersion.Version.ToString()); - - // output.WriteLine("OS Arch: " + RuntimeInformation.OSArchitecture); - // output.WriteLine("Runtime: " + RuntimeInformation.RuntimeIdentifier); - // output.WriteLine("FW: " + RuntimeInformation.FrameworkDescription); - // output.WriteLine("RAW:" + RuntimeInformation.OSDescription); - // output.WriteLine("Env Platform: " + Environment.OSVersion.Platform); - // output.WriteLine("OS Version: " + Environment.OSVersion.Version); - } -} - -#endif diff --git a/test/Sentry.Tests/PlatformFact.cs b/test/Sentry.Tests/PlatformFact.cs new file mode 100644 index 0000000000..a43fcb5522 --- /dev/null +++ b/test/Sentry.Tests/PlatformFact.cs @@ -0,0 +1,25 @@ +namespace Sentry.Tests; + +public enum Platform +{ + Windows, + Linux, + MacOS +} + +public class PlatformFact : FactAttribute +{ + public PlatformFact(Platform platform) + { + var actual = platform switch + { + Platform.Windows => OSPlatform.Windows, + Platform.Linux => OSPlatform.Linux, + Platform.MacOS => OSPlatform.OSX, + _ => throw new NotSupportedException() + }; + + if (!RuntimeInformation.IsOSPlatform(actual)) + Skip = "Ignored - Not Platform: " + actual; + } +} From 5144dba87b7edf904320701765159cf65d8f5a41 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 11 Feb 2025 10:23:26 -0500 Subject: [PATCH 3/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d8179867..016e9f880f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - Fixed envelopes with oversized attachments getting stuck in __processing ([#3938](https://github.com/getsentry/sentry-dotnet/pull/3938)) - Unknown stack frames in profiles on .NET 8+ ([#3942](https://github.com/getsentry/sentry-dotnet/pull/3942)) - Deduplicate profiling stack frames ([#3941](https://github.com/getsentry/sentry-dotnet/pull/3941)) - +- OperatingSystem will now return macOS as OS name instead of 'Darwin' as well as the proper version. ([#2710](https://github.com/getsentry/sentry-dotnet/issues/2710) ## 5.1.0 ### Significant change in behavior From 78619f5fe54f3cd814f3debf2639d1286cbaf179 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 11 Feb 2025 10:29:42 -0500 Subject: [PATCH 4/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 016e9f880f..9a3cee2c17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Unknown stack frames in profiles on .NET 8+ ([#3942](https://github.com/getsentry/sentry-dotnet/pull/3942)) - Deduplicate profiling stack frames ([#3941](https://github.com/getsentry/sentry-dotnet/pull/3941)) - OperatingSystem will now return macOS as OS name instead of 'Darwin' as well as the proper version. ([#2710](https://github.com/getsentry/sentry-dotnet/issues/2710) + ## 5.1.0 ### Significant change in behavior From 9c3aa53116bf1d627c02e7a50b92ad6199272ff8 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 11 Feb 2025 10:32:12 -0500 Subject: [PATCH 5/7] Update Sentry.Maui.Device.TestApp.csproj --- .../Sentry.Maui.Device.TestApp.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj b/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj index df8e93e506..5953b65d70 100644 --- a/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj +++ b/test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj @@ -1,9 +1,9 @@  - net8.0-maccatalyst17.0 - - + + $(TargetFrameworks);net8.0-android34.0 + $(TargetFrameworks);net8.0-ios17.0 true