Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
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
18 changes: 13 additions & 5 deletions src/app/SharpRaven/Data/Context/OperatingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public class OperatingSystem
[JsonProperty(PropertyName = "version", NullValueHandling = NullValueHandling.Ignore)]
public string Version { get; set; }
/// <summary>
/// An optional raw description that Sentry can use in an attempt to normalize OS info.
/// </summary>
/// <remarks>
/// When the system doesn't expose a clear API for <see cref="Name"/> and <see cref="Version"/>
/// this field can be used to provide a raw system info (e.g: uname)
/// </remarks>
[JsonProperty(PropertyName = "raw_description", NullValueHandling = NullValueHandling.Ignore)]
public string RawDescription { get; set; }
/// <summary>
/// The internal build revision of the operating system.
/// </summary>
[JsonProperty(PropertyName = "build", NullValueHandling = NullValueHandling.Ignore)]
Expand All @@ -83,6 +92,7 @@ internal OperatingSystem Clone()
{
Version = this.Version,
Name = this.Name,
RawDescription = this.RawDescription,
Build = this.Build,
KernelVersion = this.KernelVersion,
Rooted = this.Rooted
Expand All @@ -97,21 +107,19 @@ internal static OperatingSystem Create()
{
try
{
var os = Environment.OSVersion;
#if HAS_RUNTIME_INFORMATION
// https://github.com/dotnet/corefx/blob/dbb7a3f2d3938b9b888b876ba4b2fd45fdc10985/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Unix.cs#L25
// https://github.com/dotnet/corefx/blob/c46e2e98b77d8c5eb2bc147df13b1505cf9c041e/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Windows.cs#L22
var name = RuntimeInformation.OSDescription;
var description = RuntimeInformation.OSDescription;
#else
// https://github.com/dotnet/corefx/blob/fbe2ff101137abed0bc7fa67f40491d277088a79/src/System.Runtime.Extensions/src/System/OperatingSystem.cs#L53
// Same as RuntimeInformation.OSDescription on Mono: https://github.com/mono/mono/blob/90b49aa3aebb594e0409341f9dca63b74f9df52e/mcs/class/corlib/System.Runtime.InteropServices.RuntimeInformation/RuntimeInformation.cs#L69
var name = os.VersionString;
var description = Environment.OSVersion.VersionString;
#endif

return new OperatingSystem
{
Name = name,
Version = os.Version.ToString()
RawDescription = description,
};
}
catch (Exception e)
Expand Down
14 changes: 12 additions & 2 deletions src/app/SharpRaven/Data/Context/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public class Runtime
/// </summary>
[JsonProperty(PropertyName = "version", NullValueHandling = NullValueHandling.Ignore)]
public string Version { get; set; }
/// <summary>
/// An optional raw description that Sentry can use in an attempt to normalize Runtime info.
/// </summary>
/// <remarks>
/// When the system doesn't expose a clear API for <see cref="Name"/> and <see cref="Version"/>
/// this field can be used to provide a raw system info (e.g: .NET Framework 4.7.1)
/// </remarks>
[JsonProperty(PropertyName = "raw-description", NullValueHandling = NullValueHandling.Ignore)]
public string RawDescription { get; set; }

/// <summary>
/// Clones this instance
Expand All @@ -63,7 +72,8 @@ internal Runtime Clone()
return new Runtime
{
Name = this.Name,
Version = this.Version
Version = this.Version,
RawDescription = this.RawDescription
};
}

Expand All @@ -77,7 +87,7 @@ public static Runtime Create()
{
var runtime = new Runtime
{
Name = RuntimeInfoHelper.GetRuntimeVersion()
RawDescription = RuntimeInfoHelper.GetRuntimeVersion()
};

return runtime;
Expand Down
29 changes: 13 additions & 16 deletions src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,19 @@ namespace SharpRaven.UnitTests.Data.Context
public class OperatingSystemTests
{
[Test]
public void Create_Name_SameAsEnvironment()
public void Create_RawDescription_SameAsEnvironment()
{
var operatingSystem = OperatingSystem.Create();


var actual =
#if HAS_RUNTIME_INFORMATION
// Microsoft Windows 10.0.16299
System.Runtime.InteropServices.RuntimeInformation.OSDescription;
var expected = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
#else
Environment.OSVersion.VersionString;
var expected = Environment.OSVersion.VersionString;
#endif

Assert.NotNull(operatingSystem.Name);
Assert.AreEqual(actual, operatingSystem.Name);
}

[Test]
public void Create_Version_SameAsEnvironment()
{
var operatingSystem = OperatingSystem.Create();

Assert.NotNull(operatingSystem.Version);
Assert.AreEqual(Environment.OSVersion.Version.ToString(), operatingSystem.Version);
Assert.NotNull(operatingSystem.RawDescription);
Assert.AreEqual(expected, operatingSystem.RawDescription);
}

[Test]
Expand All @@ -54,6 +43,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
Name = "Windows",
KernelVersion = "who knows",
Version = "2016",
RawDescription = "Windows 2016",
Build = "14393",
Rooted = true
};
Expand All @@ -63,6 +53,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
Assert.That(actual, Is.EqualTo(
"{\"name\":\"Windows\","
+ "\"version\":\"2016\","
+ "\"raw_description\":\"Windows 2016\","
+ "\"build\":\"14393\","
+ "\"kernel_version\":\"who knows\","
+ "\"rooted\":true}"));
Expand Down Expand Up @@ -90,6 +81,12 @@ public static IEnumerable<object[]> TestCases()
ExpectedSerializationOutput = "{\"name\":\"some name\"}"
}};

yield return new object[] { new TestCase
{
Object = new OperatingSystem { RawDescription = "some Name, some version" },
ExpectedSerializationOutput = "{\"raw_description\":\"some Name, some version\"}"
}};

yield return new object[] { new TestCase
{
Object = new OperatingSystem { Build = "some build" },
Expand Down
15 changes: 11 additions & 4 deletions src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace SharpRaven.UnitTests.Data.Context
public class RuntimeTests
{
[Test]
public void Create_Name_NotNullAndAsHelper()
public void Create_RawDescription_NotNullAndAsHelper()
{
var runtime = Runtime.Create();

var expected = RuntimeInfoHelper.GetRuntimeVersion();
Assert.NotNull(runtime.Name);
Assert.AreEqual(expected, runtime.Name);
Assert.NotNull(runtime.RawDescription);
Assert.AreEqual(expected, runtime.RawDescription);
}

[Test]
Expand All @@ -36,11 +36,12 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
{
Version = "2.0.1",
Name = "NETCore",
RawDescription = "NETCore 2.0.1"
};

var actual = JsonConvert.SerializeObject(runtime);

Assert.That(actual, Is.EqualTo("{\"name\":\"NETCore\",\"version\":\"2.0.1\"}"));
Assert.That(actual, Is.EqualTo("{\"name\":\"NETCore\",\"version\":\"2.0.1\",\"raw-description\":\"NETCore 2.0.1\"}"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be raw_description! Same below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catching that! I updated OS and forgot Runtime

}

[Test, TestCaseSource(typeof(RuntimeTests), nameof(TestCases))]
Expand Down Expand Up @@ -70,6 +71,12 @@ public static IEnumerable<object[]> TestCases()
Object = new Runtime { Version = "some version" },
ExpectedSerializationOutput = "{\"version\":\"some version\"}"
}};

yield return new object[] { new TestCase
{
Object = new Runtime { RawDescription = "some Name, some version" },
ExpectedSerializationOutput = "{\"raw-description\":\"some Name, some version\"}"
}};
}
}
}