Skip to content

Commit ee62bb9

Browse files
authored
Fix #2710 - Return macOS instead of 'Darwin' and return proper version (#3956)
* Initial commit * Finish * Update CHANGELOG.md * Update CHANGELOG.md * Update Sentry.Maui.Device.TestApp.csproj * Update EnricherTests.cs * Update CHANGELOG.md
1 parent 4169cb7 commit ee62bb9

File tree

5 files changed

+72
-15
lines changed

5 files changed

+72
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Fixed envelopes with oversized attachments getting stuck in __processing ([#3938](https://github.com/getsentry/sentry-dotnet/pull/3938))
1111
- Unknown stack frames in profiles on .NET 8+ ([#3942](https://github.com/getsentry/sentry-dotnet/pull/3942))
1212
- Deduplicate profiling stack frames ([#3941](https://github.com/getsentry/sentry-dotnet/pull/3941))
13+
- OperatingSystem will now return macOS as OS name instead of 'Darwin' as well as the proper version. ([#2710](https://github.com/getsentry/sentry-dotnet/pull/3956))
1314
- Ignore null value on CocoaScopeObserver.SetTag ([#3948](https://github.com/getsentry/sentry-dotnet/pull/3948))
1415

1516
## 5.1.0

src/Sentry/Internal/Enricher.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ public void Apply(IEventLike eventLike)
4545
} catch {
4646
eventLike.Contexts.OperatingSystem.RawDescription = Environment.OSVersion.VersionString;
4747
}
48+
4849
#else
4950
eventLike.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription;
51+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
52+
{
53+
// works for catalyst and net9 base
54+
eventLike.Contexts.OperatingSystem.Name = "macOS";
55+
eventLike.Contexts.OperatingSystem.Version = Environment.OSVersion.Version.ToString(); // reports macOS version (ie. 15.3.0)
56+
}
5057
#endif
5158
}
5259
}

test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks />
4+
<TargetFrameworks></TargetFrameworks>
55
<TargetFrameworks Condition="'$(NO_ANDROID)' == ''">$(TargetFrameworks);net8.0-android34.0</TargetFrameworks>
66
<TargetFrameworks Condition="'$(NO_IOS)' == '' And $([MSBuild]::IsOSPlatform('OSX'))">$(TargetFrameworks);net8.0-ios17.0</TargetFrameworks>
77
<UseMaui>true</UseMaui>
@@ -65,33 +65,33 @@
6565
</PropertyGroup>
6666

6767
<ItemGroup>
68-
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
69-
<PackageReference Include="Microsoft.Maui.Core" Version="$(MauiVersion)" />
70-
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
68+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
69+
<PackageReference Include="Microsoft.Maui.Core" Version="$(MauiVersion)"/>
70+
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)"/>
7171

7272
<!-- https://github.com/advisories/GHSA-5f2m-466j-3848 -->
73-
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
73+
<PackageReference Include="System.Private.Uri" Version="4.3.2"/>
7474
</ItemGroup>
7575

7676
<!-- Configure XUnit -->
7777
<ItemGroup>
78-
<AndroidAsset Include="..\xunit.runner.json" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
79-
<Content Include="..\xunit.runner.json" CopyToOutputDirectory="PreserveNewest" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
78+
<AndroidAsset Include="..\xunit.runner.json" Condition="'$(TargetPlatformIdentifier)' == 'android'"/>
79+
<Content Include="..\xunit.runner.json" CopyToOutputDirectory="PreserveNewest" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'"/>
8080
</ItemGroup>
8181

8282
<ItemGroup>
83-
<PackageReference Include="DeviceRunners.XHarness.Maui" Version="0.1.0-preview.1" />
84-
<PackageReference Include="DeviceRunners.XHarness.Xunit" Version="0.1.0-preview.1" />
83+
<PackageReference Include="DeviceRunners.XHarness.Maui" Version="0.1.0-preview.1"/>
84+
<PackageReference Include="DeviceRunners.XHarness.Xunit" Version="0.1.0-preview.1"/>
8585
<!-- Prevent downgrade of these packages for DeviceRunners.XHarness.Xunit 0.1.0-preview.1 -->
86-
<PackageReference Include="System.Net.Primitives" Version="4.3.0" />
87-
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
86+
<PackageReference Include="System.Net.Primitives" Version="4.3.0"/>
87+
<PackageReference Include="System.IO.FileSystem" Version="4.3.0"/>
8888
</ItemGroup>
8989

9090
<ItemGroup>
91-
<ProjectReference Include="..\Sentry.Android.AssemblyReader.Tests\Sentry.Android.AssemblyReader.Tests.csproj" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
92-
<ProjectReference Include="..\Sentry.Tests\Sentry.Tests.csproj" />
93-
<ProjectReference Include="..\Sentry.Extensions.Logging.Tests\Sentry.Extensions.Logging.Tests.csproj" />
94-
<ProjectReference Include="..\Sentry.Maui.Tests\Sentry.Maui.Tests.csproj" />
91+
<ProjectReference Include="..\Sentry.Android.AssemblyReader.Tests\Sentry.Android.AssemblyReader.Tests.csproj" Condition="'$(TargetPlatformIdentifier)' == 'android'"/>
92+
<ProjectReference Include="..\Sentry.Tests\Sentry.Tests.csproj"/>
93+
<ProjectReference Include="..\Sentry.Extensions.Logging.Tests\Sentry.Extensions.Logging.Tests.csproj"/>
94+
<ProjectReference Include="..\Sentry.Maui.Tests\Sentry.Maui.Tests.csproj"/>
9595
</ItemGroup>
9696

9797
</Project>

test/Sentry.Tests/EnricherTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#if NET6_0_OR_GREATER
2+
using Sentry.Tests;
3+
4+
namespace Sentry.Maui.Tests;
5+
6+
public class EnricherTests
7+
{
8+
[PlatformFact(Platform.MacOS)]
9+
public void macOS_Platform_Version()
10+
{
11+
var elike = Substitute.For<IEventLike>();
12+
elike.Sdk.Returns(new SdkVersion());
13+
elike.User = new SentryUser();
14+
elike.Contexts = new SentryContexts();
15+
16+
var enricher = new Enricher(new SentryOptions());
17+
enricher.Apply(elike);
18+
19+
var os = elike.Contexts.OperatingSystem;
20+
os.Name.Should().Be("macOS");
21+
os.Version.Should().Be(Environment.OSVersion.Version.ToString());
22+
}
23+
}
24+
#endif

test/Sentry.Tests/PlatformFact.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace Sentry.Tests;
2+
3+
public enum Platform
4+
{
5+
Windows,
6+
Linux,
7+
MacOS
8+
}
9+
10+
public class PlatformFact : FactAttribute
11+
{
12+
public PlatformFact(Platform platform)
13+
{
14+
var actual = platform switch
15+
{
16+
Platform.Windows => OSPlatform.Windows,
17+
Platform.Linux => OSPlatform.Linux,
18+
Platform.MacOS => OSPlatform.OSX,
19+
_ => throw new NotSupportedException()
20+
};
21+
22+
if (!RuntimeInformation.IsOSPlatform(actual))
23+
Skip = "Ignored - Not Platform: " + actual;
24+
}
25+
}

0 commit comments

Comments
 (0)