Skip to content

Commit

Permalink
Fix #2710 - Return macOS instead of 'Darwin' and return proper version (
Browse files Browse the repository at this point in the history
#3956)

* Initial commit

* Finish

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update Sentry.Maui.Device.TestApp.csproj

* Update EnricherTests.cs

* Update CHANGELOG.md
  • Loading branch information
aritchie authored Feb 12, 2025
1 parent 4169cb7 commit ee62bb9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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/pull/3956))
- Ignore null value on CocoaScopeObserver.SetTag ([#3948](https://github.com/getsentry/sentry-dotnet/pull/3948))

## 5.1.0
Expand Down
7 changes: 7 additions & 0 deletions src/Sentry/Internal/Enricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// 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
}
}
Expand Down
30 changes: 15 additions & 15 deletions test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks />
<TargetFrameworks></TargetFrameworks>
<TargetFrameworks Condition="'$(NO_ANDROID)' == ''">$(TargetFrameworks);net8.0-android34.0</TargetFrameworks>
<TargetFrameworks Condition="'$(NO_IOS)' == '' And $([MSBuild]::IsOSPlatform('OSX'))">$(TargetFrameworks);net8.0-ios17.0</TargetFrameworks>
<UseMaui>true</UseMaui>
Expand Down Expand Up @@ -65,33 +65,33 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Core" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Maui.Core" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)"/>

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

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

<ItemGroup>
<PackageReference Include="DeviceRunners.XHarness.Maui" Version="0.1.0-preview.1" />
<PackageReference Include="DeviceRunners.XHarness.Xunit" Version="0.1.0-preview.1" />
<PackageReference Include="DeviceRunners.XHarness.Maui" Version="0.1.0-preview.1"/>
<PackageReference Include="DeviceRunners.XHarness.Xunit" Version="0.1.0-preview.1"/>
<!-- Prevent downgrade of these packages for DeviceRunners.XHarness.Xunit 0.1.0-preview.1 -->
<PackageReference Include="System.Net.Primitives" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Net.Primitives" Version="4.3.0"/>
<PackageReference Include="System.IO.FileSystem" Version="4.3.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Sentry.Android.AssemblyReader.Tests\Sentry.Android.AssemblyReader.Tests.csproj" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
<ProjectReference Include="..\Sentry.Tests\Sentry.Tests.csproj" />
<ProjectReference Include="..\Sentry.Extensions.Logging.Tests\Sentry.Extensions.Logging.Tests.csproj" />
<ProjectReference Include="..\Sentry.Maui.Tests\Sentry.Maui.Tests.csproj" />
<ProjectReference Include="..\Sentry.Android.AssemblyReader.Tests\Sentry.Android.AssemblyReader.Tests.csproj" Condition="'$(TargetPlatformIdentifier)' == 'android'"/>
<ProjectReference Include="..\Sentry.Tests\Sentry.Tests.csproj"/>
<ProjectReference Include="..\Sentry.Extensions.Logging.Tests\Sentry.Extensions.Logging.Tests.csproj"/>
<ProjectReference Include="..\Sentry.Maui.Tests\Sentry.Maui.Tests.csproj"/>
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions test/Sentry.Tests/EnricherTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if NET6_0_OR_GREATER
using Sentry.Tests;

namespace Sentry.Maui.Tests;

public class EnricherTests
{
[PlatformFact(Platform.MacOS)]
public void macOS_Platform_Version()
{
var elike = Substitute.For<IEventLike>();
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());
}
}
#endif
25 changes: 25 additions & 0 deletions test/Sentry.Tests/PlatformFact.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit ee62bb9

Please sign in to comment.