diff --git a/src/app/SharpRaven/Data/Context/OperatingSystem.cs b/src/app/SharpRaven/Data/Context/OperatingSystem.cs index af039bed..fa70b6be 100644 --- a/src/app/SharpRaven/Data/Context/OperatingSystem.cs +++ b/src/app/SharpRaven/Data/Context/OperatingSystem.cs @@ -57,6 +57,15 @@ public class OperatingSystem [JsonProperty(PropertyName = "version", NullValueHandling = NullValueHandling.Ignore)] public string Version { get; set; } /// + /// An optional raw description that Sentry can use in an attempt to normalize OS info. + /// + /// + /// When the system doesn't expose a clear API for and + /// this field can be used to provide a raw system info (e.g: uname) + /// + [JsonProperty(PropertyName = "raw_description", NullValueHandling = NullValueHandling.Ignore)] + public string RawDescription { get; set; } + /// /// The internal build revision of the operating system. /// [JsonProperty(PropertyName = "build", NullValueHandling = NullValueHandling.Ignore)] @@ -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 @@ -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) diff --git a/src/app/SharpRaven/Data/Context/Runtime.cs b/src/app/SharpRaven/Data/Context/Runtime.cs index 05c2dc79..0136b12b 100644 --- a/src/app/SharpRaven/Data/Context/Runtime.cs +++ b/src/app/SharpRaven/Data/Context/Runtime.cs @@ -53,6 +53,15 @@ public class Runtime /// [JsonProperty(PropertyName = "version", NullValueHandling = NullValueHandling.Ignore)] public string Version { get; set; } + /// + /// An optional raw description that Sentry can use in an attempt to normalize Runtime info. + /// + /// + /// When the system doesn't expose a clear API for and + /// this field can be used to provide a raw system info (e.g: .NET Framework 4.7.1) + /// + [JsonProperty(PropertyName = "raw_description", NullValueHandling = NullValueHandling.Ignore)] + public string RawDescription { get; set; } /// /// Clones this instance @@ -63,7 +72,8 @@ internal Runtime Clone() return new Runtime { Name = this.Name, - Version = this.Version + Version = this.Version, + RawDescription = this.RawDescription }; } @@ -77,7 +87,7 @@ public static Runtime Create() { var runtime = new Runtime { - Name = RuntimeInfoHelper.GetRuntimeVersion() + RawDescription = RuntimeInfoHelper.GetRuntimeVersion() }; return runtime; diff --git a/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs b/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs index 9f1c77fa..a8364258 100644 --- a/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs +++ b/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs @@ -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] @@ -54,6 +43,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() Name = "Windows", KernelVersion = "who knows", Version = "2016", + RawDescription = "Windows 2016", Build = "14393", Rooted = true }; @@ -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}")); @@ -90,6 +81,12 @@ public static IEnumerable 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" }, diff --git a/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs b/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs index a5dc838a..3ee2c76a 100644 --- a/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs +++ b/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs @@ -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] @@ -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\"}")); } [Test, TestCaseSource(typeof(RuntimeTests), nameof(TestCases))] @@ -70,6 +71,12 @@ public static IEnumerable 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\"}" + }}; } } }