From 5105f08e1d27b825e7ce224fe672b628b89ab528 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sat, 28 Apr 2018 11:01:10 +0200 Subject: [PATCH 1/4] feat(contexts): non normalized data set to raw-description * Leave Name and Version empty if no propert API available to set it * An SDK consumer with a better system API (i.e: Xamarin) can set Name and Version directly * Server will use Raw Description if no Name and Version was provided to try normalizing into those 2 fields. --- .../Data/Context/OperatingSystem.cs | 18 ++++++++---- src/app/SharpRaven/Data/Context/Runtime.cs | 14 +++++++-- .../Data/Context/OperatingSystemTests.cs | 29 +++++++++---------- .../Data/Context/RuntimeTests.cs | 15 +++++++--- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/app/SharpRaven/Data/Context/OperatingSystem.cs b/src/app/SharpRaven/Data/Context/OperatingSystem.cs index af039bed..c186edb6 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..cbfbc164 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..1e9be0c0 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..9fb0f1e5 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\"}" + }}; } } } From 1a9636938deb9abb26b10795d76292cef9bba59a Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sun, 29 Apr 2018 10:39:47 +0200 Subject: [PATCH 2/4] fix: raw-description -> raw_description --- src/app/SharpRaven/Data/Context/OperatingSystem.cs | 2 +- .../SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/SharpRaven/Data/Context/OperatingSystem.cs b/src/app/SharpRaven/Data/Context/OperatingSystem.cs index c186edb6..fa70b6be 100644 --- a/src/app/SharpRaven/Data/Context/OperatingSystem.cs +++ b/src/app/SharpRaven/Data/Context/OperatingSystem.cs @@ -63,7 +63,7 @@ public class OperatingSystem /// 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)] + [JsonProperty(PropertyName = "raw_description", NullValueHandling = NullValueHandling.Ignore)] public string RawDescription { get; set; } /// /// The internal build revision of the operating system. diff --git a/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs b/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs index 1e9be0c0..a8364258 100644 --- a/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs +++ b/src/tests/SharpRaven.UnitTests/Data/Context/OperatingSystemTests.cs @@ -53,7 +53,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() Assert.That(actual, Is.EqualTo( "{\"name\":\"Windows\"," + "\"version\":\"2016\"," - + "\"raw-description\":\"Windows 2016\"," + + "\"raw_description\":\"Windows 2016\"," + "\"build\":\"14393\"," + "\"kernel_version\":\"who knows\"," + "\"rooted\":true}")); @@ -84,7 +84,7 @@ public static IEnumerable TestCases() yield return new object[] { new TestCase { Object = new OperatingSystem { RawDescription = "some Name, some version" }, - ExpectedSerializationOutput = "{\"raw-description\":\"some Name, some version\"}" + ExpectedSerializationOutput = "{\"raw_description\":\"some Name, some version\"}" }}; yield return new object[] { new TestCase From 0900ab62496b0a5e8d903978999f8a054adf6b9e Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Mon, 30 Apr 2018 09:43:49 +0200 Subject: [PATCH 3/4] fix: raw-description -> raw_description (runtime) --- src/app/SharpRaven/Data/Context/Runtime.cs | 2 +- src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/SharpRaven/Data/Context/Runtime.cs b/src/app/SharpRaven/Data/Context/Runtime.cs index cbfbc164..0136b12b 100644 --- a/src/app/SharpRaven/Data/Context/Runtime.cs +++ b/src/app/SharpRaven/Data/Context/Runtime.cs @@ -60,7 +60,7 @@ public class Runtime /// 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)] + [JsonProperty(PropertyName = "raw_description", NullValueHandling = NullValueHandling.Ignore)] public string RawDescription { get; set; } /// diff --git a/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs b/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs index 9fb0f1e5..3ee2c76a 100644 --- a/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs +++ b/src/tests/SharpRaven.UnitTests/Data/Context/RuntimeTests.cs @@ -41,7 +41,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() var actual = JsonConvert.SerializeObject(runtime); - Assert.That(actual, Is.EqualTo("{\"name\":\"NETCore\",\"version\":\"2.0.1\",\"raw-description\":\"NETCore 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))] @@ -75,7 +75,7 @@ public static IEnumerable TestCases() yield return new object[] { new TestCase { Object = new Runtime { RawDescription = "some Name, some version" }, - ExpectedSerializationOutput = "{\"raw-description\":\"some Name, some version\"}" + ExpectedSerializationOutput = "{\"raw_description\":\"some Name, some version\"}" }}; } } From c8ad5cf396ffb229d0370691c43c40d706208c9d Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Mon, 30 Apr 2018 11:02:48 +0200 Subject: [PATCH 4/4] flaky build failed. Retry fails due to GitVersion+AppVeyor 'Build Number already exists'