From 0ed06ce611828d8836f0e65a49c7e8aeec192a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 May 2022 08:27:26 +0200 Subject: [PATCH 1/5] refactor JaegerExporterOptions string extension --- .../JaegerExporterOptions.cs | 6 ++--- ...ons.cs => JaegerExporterOptionsHelpers.cs} | 24 ++++++++++++------- ...s => JaegerExporterOptionsHelpersTests.cs} | 15 ++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) rename src/OpenTelemetry.Exporter.Jaeger/{JaegerExporterOptionsExtensions.cs => JaegerExporterOptionsHelpers.cs} (51%) rename test/OpenTelemetry.Exporter.Jaeger.Tests/{JaegerExporterOptionsExtensionsTests.cs => JaegerExporterOptionsHelpersTests.cs} (53%) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs index 9845c0e0b77..3787761e8b8 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs @@ -47,11 +47,9 @@ public JaegerExporterOptions() { if (EnvironmentVariableHelper.LoadString(OTelProtocolEnvVarKey, out string protocolEnvVar)) { - var protocol = protocolEnvVar.ToJaegerExportProtocol(); - - if (protocol.HasValue) + if (JaegerExporterOptionsHelpers.TryParseProtocol(protocolEnvVar, out var protocol)) { - this.Protocol = protocol.Value; + this.Protocol = protocol; } else { diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsHelpers.cs similarity index 51% rename from src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsExtensions.cs rename to src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsHelpers.cs index 12f225e421d..1db5f5cd6b4 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsHelpers.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,13 +16,21 @@ namespace OpenTelemetry.Exporter; -internal static class JaegerExporterOptionsExtensions +internal static class JaegerExporterOptionsHelpers { - public static JaegerExportProtocol? ToJaegerExportProtocol(this string protocol) => - protocol?.Trim() switch + public static bool TryParseProtocol(string value, out JaegerExportProtocol result) + { + switch (value?.Trim()) { - "udp/thrift.compact" => JaegerExportProtocol.UdpCompactThrift, - "http/thrift.binary" => JaegerExportProtocol.HttpBinaryThrift, - _ => null, - }; + case "udp/thrift.compact": + result = JaegerExportProtocol.UdpCompactThrift; + return true; + case "http/thrift.binary": + result = JaegerExportProtocol.HttpBinaryThrift; + return true; + default: + result = default; + return false; + } + } } diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsHelpersTests.cs similarity index 53% rename from test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsExtensionsTests.cs rename to test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsHelpersTests.cs index 0dfca9cc3cd..35260fe14e2 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsExtensionsTests.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsHelpersTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,16 +18,17 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests; -public class JaegerExporterOptionsExtensionsTests +public class JaegerExporterOptionsHelpersTests { [Theory] - [InlineData("udp/thrift.compact", JaegerExportProtocol.UdpCompactThrift)] - [InlineData("http/thrift.binary", JaegerExportProtocol.HttpBinaryThrift)] - [InlineData("unsupported", null)] - public void ToJaegerExportProtocol_Protocol_MapsToCorrectValue(string protocol, JaegerExportProtocol? expectedExportProtocol) + [InlineData("udp/thrift.compact", true, JaegerExportProtocol.UdpCompactThrift)] + [InlineData("http/thrift.binary", true, JaegerExportProtocol.HttpBinaryThrift)] + [InlineData("unsupported", false, default(JaegerExportProtocol))] + public void TryParseProtocol_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, JaegerExportProtocol expectedExportProtocol) { - var exportProtocol = protocol.ToJaegerExportProtocol(); + var result = JaegerExporterOptionsHelpers.TryParseProtocol(protocol, out var exportProtocol); Assert.Equal(expectedExportProtocol, exportProtocol); + Assert.Equal(expectedResult, result); } } From b51c156d84ff72a0e0f260045fa84c60010b7037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 May 2022 08:29:54 +0200 Subject: [PATCH 2/5] extract OtlpExportProtocol string extension to separate class --- .../OtlpExporterOptionsExtensions.cs | 8 ----- .../OtlpExporterOptionsHelpers.cs | 29 ++++++++++++++++ .../OtlpExporterOptionsExtensionsTests.cs | 11 ------ .../OtlpExporterOptionsHelpersTests.cs | 34 +++++++++++++++++++ 4 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs create mode 100644 test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index 9d99caf1714..43a6c3a997b 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -121,14 +121,6 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac _ => throw new NotSupportedException($"Protocol {options.Protocol} is not supported."), }; - public static OtlpExportProtocol? ToOtlpExportProtocol(this string protocol) => - protocol.Trim() switch - { - "grpc" => OtlpExportProtocol.Grpc, - "http/protobuf" => OtlpExportProtocol.HttpProtobuf, - _ => null, - }; - public static void TryEnableIHttpClientFactoryIntegration(this OtlpExporterOptions options, IServiceProvider serviceProvider, string httpClientName) { if (serviceProvider != null diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs new file mode 100644 index 00000000000..746ed295fab --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs @@ -0,0 +1,29 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace OpenTelemetry.Exporter +{ + internal static class OtlpExporterOptionsHelpers + { + public static OtlpExportProtocol? ToOtlpExportProtocol(this string protocol) => + protocol.Trim() switch + { + "grpc" => OtlpExportProtocol.Grpc, + "http/protobuf" => OtlpExportProtocol.HttpProtobuf, + _ => null, + }; + } +} diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs index 27864f9c74f..4b4dd25fd53 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs @@ -145,17 +145,6 @@ public void GetTraceExportClient_UnsupportedProtocol_Throws() Assert.Throws(() => options.GetTraceExportClient()); } - [Theory] - [InlineData("grpc", OtlpExportProtocol.Grpc)] - [InlineData("http/protobuf", OtlpExportProtocol.HttpProtobuf)] - [InlineData("unsupported", null)] - public void ToOtlpExportProtocol_Protocol_MapsToCorrectValue(string protocol, OtlpExportProtocol? expectedExportProtocol) - { - var exportProtocol = protocol.ToOtlpExportProtocol(); - - Assert.Equal(expectedExportProtocol, exportProtocol); - } - [Theory] [InlineData("http://test:8888", "http://test:8888/v1/traces")] [InlineData("http://test:8888/", "http://test:8888/v1/traces")] diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs new file mode 100644 index 00000000000..441879b6b0b --- /dev/null +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs @@ -0,0 +1,34 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using Xunit; + +namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests +{ + public class OtlpExporterOptionsHelpersTests : Http2UnencryptedSupportTests + { + [Theory] + [InlineData("grpc", OtlpExportProtocol.Grpc)] + [InlineData("http/protobuf", OtlpExportProtocol.HttpProtobuf)] + [InlineData("unsupported", null)] + public void ToOtlpExportProtocol_Protocol_MapsToCorrectValue(string protocol, OtlpExportProtocol? expectedExportProtocol) + { + var exportProtocol = protocol.ToOtlpExportProtocol(); + + Assert.Equal(expectedExportProtocol, exportProtocol); + } + } +} From 3531152971c544a1031e66bd0e59cd37165c069d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 May 2022 08:35:27 +0200 Subject: [PATCH 3/5] refactor OltprExporterOptions string extension --- .../OtlpExporterOptions.cs | 5 ++--- .../OtlpExporterOptionsHelpers.cs | 20 +++++++++++++------ .../OtlpExporterOptionsHelpersTests.cs | 11 +++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index 020f57ee577..7fd27291263 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -69,10 +69,9 @@ public OtlpExporterOptions() if (EnvironmentVariableHelper.LoadString(ProtocolEnvVarName, out string protocolEnvVar)) { - var protocol = protocolEnvVar.ToOtlpExportProtocol(); - if (protocol.HasValue) + if (OtlpExporterOptionsHelpers.TryParseProtocol(protocolEnvVar, out var protocol)) { - this.Protocol = protocol.Value; + this.Protocol = protocol; } else { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs index 746ed295fab..bf79fdf1d44 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs @@ -18,12 +18,20 @@ namespace OpenTelemetry.Exporter { internal static class OtlpExporterOptionsHelpers { - public static OtlpExportProtocol? ToOtlpExportProtocol(this string protocol) => - protocol.Trim() switch + public static bool TryParseProtocol(string value, out OtlpExportProtocol result) + { + switch (value?.Trim()) { - "grpc" => OtlpExportProtocol.Grpc, - "http/protobuf" => OtlpExportProtocol.HttpProtobuf, - _ => null, - }; + case "grpc": + result = OtlpExportProtocol.Grpc; + return true; + case "http/protobuf": + result = OtlpExportProtocol.HttpProtobuf; + return true; + default: + result = default; + return false; + } + } } } diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs index 441879b6b0b..30a10f6f78f 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs @@ -21,14 +21,15 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests public class OtlpExporterOptionsHelpersTests : Http2UnencryptedSupportTests { [Theory] - [InlineData("grpc", OtlpExportProtocol.Grpc)] - [InlineData("http/protobuf", OtlpExportProtocol.HttpProtobuf)] - [InlineData("unsupported", null)] - public void ToOtlpExportProtocol_Protocol_MapsToCorrectValue(string protocol, OtlpExportProtocol? expectedExportProtocol) + [InlineData("grpc", true, OtlpExportProtocol.Grpc)] + [InlineData("http/protobuf", true, OtlpExportProtocol.HttpProtobuf)] + [InlineData("unsupported", false, default(OtlpExportProtocol))] + public void TryParseProtocol_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, OtlpExportProtocol expectedExportProtocol) { - var exportProtocol = protocol.ToOtlpExportProtocol(); + var result = OtlpExporterOptionsHelpers.TryParseProtocol(protocol, out var exportProtocol); Assert.Equal(expectedExportProtocol, exportProtocol); + Assert.Equal(expectedResult, result); } } } From a68e2fbe6bb7786ae12a1d5f8e23b81ded9c2c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 May 2022 08:41:29 +0200 Subject: [PATCH 4/5] rename protocol parser classes --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs | 2 +- ...terOptionsHelpers.cs => JaegerExporterProtocolParser.cs} | 4 ++-- ...xporterOptionsHelpers.cs => OtlpExportProtocolParser.cs} | 4 ++-- .../OtlpExporterOptions.cs | 2 +- ...HelpersTests.cs => JaegerExporterProtocolParserTests.cs} | 6 +++--- ...ionsHelpersTests.cs => OtlpExportProtocolParserTests.cs} | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) rename src/OpenTelemetry.Exporter.Jaeger/{JaegerExporterOptionsHelpers.cs => JaegerExporterProtocolParser.cs} (91%) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol/{OtlpExporterOptionsHelpers.cs => OtlpExportProtocolParser.cs} (89%) rename test/OpenTelemetry.Exporter.Jaeger.Tests/{JaegerExporterOptionsHelpersTests.cs => JaegerExporterProtocolParserTests.cs} (87%) rename test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/{OtlpExporterOptionsHelpersTests.cs => OtlpExportProtocolParserTests.cs} (81%) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs index 3787761e8b8..be962538994 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs @@ -47,7 +47,7 @@ public JaegerExporterOptions() { if (EnvironmentVariableHelper.LoadString(OTelProtocolEnvVarKey, out string protocolEnvVar)) { - if (JaegerExporterOptionsHelpers.TryParseProtocol(protocolEnvVar, out var protocol)) + if (JaegerExporterProtocolParser.TryParseProtocol(protocolEnvVar, out var protocol)) { this.Protocol = protocol; } diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsHelpers.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterProtocolParser.cs similarity index 91% rename from src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsHelpers.cs rename to src/OpenTelemetry.Exporter.Jaeger/JaegerExporterProtocolParser.cs index 1db5f5cd6b4..e202100cd0e 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptionsHelpers.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterProtocolParser.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +16,7 @@ namespace OpenTelemetry.Exporter; -internal static class JaegerExporterOptionsHelpers +internal static class JaegerExporterProtocolParser { public static bool TryParseProtocol(string value, out JaegerExportProtocol result) { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs similarity index 89% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs index bf79fdf1d44..69cf030f6ac 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsHelpers.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +16,7 @@ namespace OpenTelemetry.Exporter { - internal static class OtlpExporterOptionsHelpers + internal static class OtlpExportProtocolParser { public static bool TryParseProtocol(string value, out OtlpExportProtocol result) { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index 7fd27291263..80da08c6ed0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -69,7 +69,7 @@ public OtlpExporterOptions() if (EnvironmentVariableHelper.LoadString(ProtocolEnvVarName, out string protocolEnvVar)) { - if (OtlpExporterOptionsHelpers.TryParseProtocol(protocolEnvVar, out var protocol)) + if (OtlpExportProtocolParser.TryParseProtocol(protocolEnvVar, out var protocol)) { this.Protocol = protocol; } diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsHelpersTests.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterProtocolParserTests.cs similarity index 87% rename from test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsHelpersTests.cs rename to test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterProtocolParserTests.cs index 35260fe14e2..c6149d1200d 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterOptionsHelpersTests.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterProtocolParserTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests; -public class JaegerExporterOptionsHelpersTests +public class JaegerExporterProtocolParserTests { [Theory] [InlineData("udp/thrift.compact", true, JaegerExportProtocol.UdpCompactThrift)] @@ -26,7 +26,7 @@ public class JaegerExporterOptionsHelpersTests [InlineData("unsupported", false, default(JaegerExportProtocol))] public void TryParseProtocol_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, JaegerExportProtocol expectedExportProtocol) { - var result = JaegerExporterOptionsHelpers.TryParseProtocol(protocol, out var exportProtocol); + var result = JaegerExporterProtocolParser.TryParseProtocol(protocol, out var exportProtocol); Assert.Equal(expectedExportProtocol, exportProtocol); Assert.Equal(expectedResult, result); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExportProtocolParserTests.cs similarity index 81% rename from test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs rename to test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExportProtocolParserTests.cs index 30a10f6f78f..b39d213cb13 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsHelpersTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExportProtocolParserTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests { - public class OtlpExporterOptionsHelpersTests : Http2UnencryptedSupportTests + public class OtlpExportProtocolParserTests : Http2UnencryptedSupportTests { [Theory] [InlineData("grpc", true, OtlpExportProtocol.Grpc)] @@ -26,7 +26,7 @@ public class OtlpExporterOptionsHelpersTests : Http2UnencryptedSupportTests [InlineData("unsupported", false, default(OtlpExportProtocol))] public void TryParseProtocol_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, OtlpExportProtocol expectedExportProtocol) { - var result = OtlpExporterOptionsHelpers.TryParseProtocol(protocol, out var exportProtocol); + var result = OtlpExportProtocolParser.TryParseProtocol(protocol, out var exportProtocol); Assert.Equal(expectedExportProtocol, exportProtocol); Assert.Equal(expectedResult, result); From 14cd22c5f604237d008bc955f82fccea6c4eda20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 May 2022 09:50:19 +0200 Subject: [PATCH 5/5] code review fix: TryParseProtocol -> TryParce --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs | 2 +- .../JaegerExporterProtocolParser.cs | 2 +- .../OtlpExportProtocolParser.cs | 2 +- .../OtlpExporterOptions.cs | 2 +- .../JaegerExporterProtocolParserTests.cs | 4 ++-- .../OtlpExportProtocolParserTests.cs | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs index be962538994..b992048d338 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs @@ -47,7 +47,7 @@ public JaegerExporterOptions() { if (EnvironmentVariableHelper.LoadString(OTelProtocolEnvVarKey, out string protocolEnvVar)) { - if (JaegerExporterProtocolParser.TryParseProtocol(protocolEnvVar, out var protocol)) + if (JaegerExporterProtocolParser.TryParse(protocolEnvVar, out var protocol)) { this.Protocol = protocol; } diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterProtocolParser.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterProtocolParser.cs index e202100cd0e..52fb109350f 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterProtocolParser.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterProtocolParser.cs @@ -18,7 +18,7 @@ namespace OpenTelemetry.Exporter; internal static class JaegerExporterProtocolParser { - public static bool TryParseProtocol(string value, out JaegerExportProtocol result) + public static bool TryParse(string value, out JaegerExportProtocol result) { switch (value?.Trim()) { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs index 69cf030f6ac..23062ce458b 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs @@ -18,7 +18,7 @@ namespace OpenTelemetry.Exporter { internal static class OtlpExportProtocolParser { - public static bool TryParseProtocol(string value, out OtlpExportProtocol result) + public static bool TryParse(string value, out OtlpExportProtocol result) { switch (value?.Trim()) { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index 80da08c6ed0..936da811fa4 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -69,7 +69,7 @@ public OtlpExporterOptions() if (EnvironmentVariableHelper.LoadString(ProtocolEnvVarName, out string protocolEnvVar)) { - if (OtlpExportProtocolParser.TryParseProtocol(protocolEnvVar, out var protocol)) + if (OtlpExportProtocolParser.TryParse(protocolEnvVar, out var protocol)) { this.Protocol = protocol; } diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterProtocolParserTests.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterProtocolParserTests.cs index c6149d1200d..c75a52d674a 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterProtocolParserTests.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterProtocolParserTests.cs @@ -24,9 +24,9 @@ public class JaegerExporterProtocolParserTests [InlineData("udp/thrift.compact", true, JaegerExportProtocol.UdpCompactThrift)] [InlineData("http/thrift.binary", true, JaegerExportProtocol.HttpBinaryThrift)] [InlineData("unsupported", false, default(JaegerExportProtocol))] - public void TryParseProtocol_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, JaegerExportProtocol expectedExportProtocol) + public void TryParse_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, JaegerExportProtocol expectedExportProtocol) { - var result = JaegerExporterProtocolParser.TryParseProtocol(protocol, out var exportProtocol); + var result = JaegerExporterProtocolParser.TryParse(protocol, out var exportProtocol); Assert.Equal(expectedExportProtocol, exportProtocol); Assert.Equal(expectedResult, result); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExportProtocolParserTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExportProtocolParserTests.cs index b39d213cb13..baec4253e73 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExportProtocolParserTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExportProtocolParserTests.cs @@ -24,9 +24,9 @@ public class OtlpExportProtocolParserTests : Http2UnencryptedSupportTests [InlineData("grpc", true, OtlpExportProtocol.Grpc)] [InlineData("http/protobuf", true, OtlpExportProtocol.HttpProtobuf)] [InlineData("unsupported", false, default(OtlpExportProtocol))] - public void TryParseProtocol_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, OtlpExportProtocol expectedExportProtocol) + public void TryParse_Protocol_MapsToCorrectValue(string protocol, bool expectedResult, OtlpExportProtocol expectedExportProtocol) { - var result = OtlpExportProtocolParser.TryParseProtocol(protocol, out var exportProtocol); + var result = OtlpExportProtocolParser.TryParse(protocol, out var exportProtocol); Assert.Equal(expectedExportProtocol, exportProtocol); Assert.Equal(expectedResult, result);