From 06b9efd06b26e05670e3e8da47548b285acf4d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 29 Jan 2024 07:13:38 +0100 Subject: [PATCH] Drop HttpSemanticConventionHelper class. It is no longer needed. --- OpenTelemetry.sln | 1 - src/Shared/HttpSemanticConventionHelper.cs | 85 ------------------- .../OpenTelemetry.Tests.csproj | 1 - .../HttpSemanticConventionHelperTest.cs | 79 ----------------- 4 files changed, 166 deletions(-) delete mode 100644 src/Shared/HttpSemanticConventionHelper.cs delete mode 100644 test/OpenTelemetry.Tests/Shared/HttpSemanticConventionHelperTest.cs diff --git a/OpenTelemetry.sln b/OpenTelemetry.sln index 7c8bb952f0e..28c8c85b510 100644 --- a/OpenTelemetry.sln +++ b/OpenTelemetry.sln @@ -265,7 +265,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{A49299 src\Shared\DiagnosticDefinitions.cs = src\Shared\DiagnosticDefinitions.cs src\Shared\ExceptionExtensions.cs = src\Shared\ExceptionExtensions.cs src\Shared\Guard.cs = src\Shared\Guard.cs - src\Shared\HttpSemanticConventionHelper.cs = src\Shared\HttpSemanticConventionHelper.cs src\Shared\MathHelper.cs = src\Shared\MathHelper.cs src\Shared\PeerServiceResolver.cs = src\Shared\PeerServiceResolver.cs src\Shared\PeriodicExportingMetricReaderHelper.cs = src\Shared\PeriodicExportingMetricReaderHelper.cs diff --git a/src/Shared/HttpSemanticConventionHelper.cs b/src/Shared/HttpSemanticConventionHelper.cs deleted file mode 100644 index 220f9874acd..00000000000 --- a/src/Shared/HttpSemanticConventionHelper.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#nullable enable - -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using Microsoft.Extensions.Configuration; - -namespace OpenTelemetry.Internal; - -/// -/// Helper class for Http Semantic Conventions. -/// -/// -/// Due to a breaking change in the semantic convention, affected instrumentation libraries -/// must inspect an environment variable to determine which attributes to emit. -/// This is expected to be removed when the instrumentation libraries reach Stable. -/// . -/// -internal static class HttpSemanticConventionHelper -{ - public const string SemanticConventionOptInKeyName = "OTEL_SEMCONV_STABILITY_OPT_IN"; - - [Flags] - public enum HttpSemanticConvention - { - /// - /// Instructs an instrumentation library to emit the old experimental HTTP attributes. - /// - Old = 0x1, - - /// - /// Instructs an instrumentation library to emit the new, v1.21.0 Http attributes. - /// - New = 0x2, - - /// - /// Instructs an instrumentation library to emit both the old and new attributes. - /// - Dupe = Old | New, - } - - public static HttpSemanticConvention GetSemanticConventionOptIn(IConfiguration configuration) - { - Debug.Assert(configuration != null, "configuration was null"); - - if (configuration != null && TryGetConfiguredValues(configuration, out var values)) - { - if (values.Contains("http/dup")) - { - return HttpSemanticConvention.Dupe; - } - else if (values.Contains("http")) - { - return HttpSemanticConvention.New; - } - } - - return HttpSemanticConvention.Old; - } - - private static bool TryGetConfiguredValues(IConfiguration configuration, [NotNullWhen(true)] out HashSet? values) - { - try - { - var stringValue = configuration[SemanticConventionOptInKeyName]; - - if (string.IsNullOrWhiteSpace(stringValue)) - { - values = null; - return false; - } - - var stringValues = stringValue!.Split(separator: new[] { ',', ' ' }, options: StringSplitOptions.RemoveEmptyEntries); - values = new HashSet(stringValues, StringComparer.OrdinalIgnoreCase); - return true; - } - catch - { - values = null; - return false; - } - } -} diff --git a/test/OpenTelemetry.Tests/OpenTelemetry.Tests.csproj b/test/OpenTelemetry.Tests/OpenTelemetry.Tests.csproj index 0679b5d3653..86fe7e36844 100644 --- a/test/OpenTelemetry.Tests/OpenTelemetry.Tests.csproj +++ b/test/OpenTelemetry.Tests/OpenTelemetry.Tests.csproj @@ -20,7 +20,6 @@ - diff --git a/test/OpenTelemetry.Tests/Shared/HttpSemanticConventionHelperTest.cs b/test/OpenTelemetry.Tests/Shared/HttpSemanticConventionHelperTest.cs deleted file mode 100644 index a7fb0224bff..00000000000 --- a/test/OpenTelemetry.Tests/Shared/HttpSemanticConventionHelperTest.cs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -using Microsoft.Extensions.Configuration; -using Xunit; -using static OpenTelemetry.Internal.HttpSemanticConventionHelper; - -namespace OpenTelemetry.Tests.Shared; - -public class HttpSemanticConventionHelperTest -{ - public static IEnumerable TestCases => new List - { - new object[] { null, HttpSemanticConvention.Old }, - new object[] { string.Empty, HttpSemanticConvention.Old }, - new object[] { " ", HttpSemanticConvention.Old }, - new object[] { "junk", HttpSemanticConvention.Old }, - new object[] { "none", HttpSemanticConvention.Old }, - new object[] { "NONE", HttpSemanticConvention.Old }, - new object[] { "http", HttpSemanticConvention.New }, - new object[] { "HTTP", HttpSemanticConvention.New }, - new object[] { "http/dup", HttpSemanticConvention.Dupe }, - new object[] { "HTTP/DUP", HttpSemanticConvention.Dupe }, - new object[] { "junk,,junk", HttpSemanticConvention.Old }, - new object[] { "junk,JUNK", HttpSemanticConvention.Old }, - new object[] { "junk1,junk2", HttpSemanticConvention.Old }, - new object[] { "junk,http", HttpSemanticConvention.New }, - new object[] { "junk,http , http ,junk", HttpSemanticConvention.New }, - new object[] { "junk,http/dup", HttpSemanticConvention.Dupe }, - new object[] { "junk, http/dup ", HttpSemanticConvention.Dupe }, - new object[] { "http/dup,http", HttpSemanticConvention.Dupe }, - new object[] { "http,http/dup", HttpSemanticConvention.Dupe }, - }; - - [Fact] - public void VerifyFlags() - { - var testValue = HttpSemanticConvention.Dupe; - Assert.True(testValue.HasFlag(HttpSemanticConvention.Old)); - Assert.True(testValue.HasFlag(HttpSemanticConvention.New)); - - testValue = HttpSemanticConvention.Old; - Assert.True(testValue.HasFlag(HttpSemanticConvention.Old)); - Assert.False(testValue.HasFlag(HttpSemanticConvention.New)); - - testValue = HttpSemanticConvention.New; - Assert.False(testValue.HasFlag(HttpSemanticConvention.Old)); - Assert.True(testValue.HasFlag(HttpSemanticConvention.New)); - } - - [Theory] - [MemberData(nameof(TestCases))] - public void VerifyGetSemanticConventionOptIn_UsingEnvironmentVariable(string input, string expectedValue) - { - try - { - Environment.SetEnvironmentVariable(SemanticConventionOptInKeyName, input); - - var expected = Enum.Parse(typeof(HttpSemanticConvention), expectedValue); - Assert.Equal(expected, GetSemanticConventionOptIn(new ConfigurationBuilder().AddEnvironmentVariables().Build())); - } - finally - { - Environment.SetEnvironmentVariable(SemanticConventionOptInKeyName, null); - } - } - - [Theory] - [MemberData(nameof(TestCases))] - public void VerifyGetSemanticConventionOptIn_UsingIConfiguration(string input, string expectedValue) - { - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary { [SemanticConventionOptInKeyName] = input }) - .Build(); - - var expected = Enum.Parse(typeof(HttpSemanticConvention), expectedValue); - Assert.Equal(expected, GetSemanticConventionOptIn(configuration)); - } -}