Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instrumentation.AspNetCore, Instrumentation.Http] Revert support for OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS #1754

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class HttpInListener : IDisposable
{
private readonly HttpRequestRouteHelper routeHelper = new();
private readonly AspNetTraceInstrumentationOptions options;
private readonly RequestDataHelper requestDataHelper = new();
private readonly RequestDataHelper requestDataHelper = new(configureByHttpKnownMethodsEnvironmentalVariable: true);

public HttpInListener(AspNetTraceInstrumentationOptions options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation;
internal sealed class HttpInMetricsListener : IDisposable
{
private readonly HttpRequestRouteHelper routeHelper = new();
private readonly RequestDataHelper requestDataHelper = new();
private readonly RequestDataHelper requestDataHelper = new(configureByHttpKnownMethodsEnvironmentalVariable: true);
private readonly Histogram<double> httpServerDuration;
private readonly AspNetMetricsInstrumentationOptions options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation;
internal static class TelemetryHelper
{
public static readonly object[] BoxedStatusCodes = InitializeBoxedStatusCodes();
internal static readonly RequestDataHelper RequestDataHelper = new();
internal static readonly RequestDataHelper RequestDataHelper = new(configureByHttpKnownMethodsEnvironmentalVariable: false);

public static object GetBoxedStatusCode(int statusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation;
/// </summary>
internal static class HttpTagHelper
{
internal static readonly RequestDataHelper RequestDataHelper = new();
internal static readonly RequestDataHelper RequestDataHelper = new(configureByHttpKnownMethodsEnvironmentalVariable: false);

/// <summary>
/// Gets the OpenTelemetry standard uri tag value for a span based on its request <see cref="Uri"/>.
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/RequestDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ internal sealed class RequestDataHelper
private readonly Dictionary<string, string> knownHttpMethods;
#endif

public RequestDataHelper()
public RequestDataHelper(bool configureByHttpKnownMethodsEnvironmentalVariable)
{
var suppliedKnownMethods = Environment.GetEnvironmentVariable(KnownHttpMethodsEnvironmentVariable)
?.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);
var suppliedKnownMethods = configureByHttpKnownMethodsEnvironmentalVariable ? Environment.GetEnvironmentVariable(KnownHttpMethodsEnvironmentVariable)
?.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries) : null;
var knownMethodSet = suppliedKnownMethods?.Length > 0
? suppliedKnownMethods.ToDictionary(x => x, x => x, StringComparer.OrdinalIgnoreCase)
: new(StringComparer.OrdinalIgnoreCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RequestDataHelperTests : IDisposable
[InlineData("invalid", "_OTHER")]
public void MethodMappingWorksForKnownMethods(string method, string expected)
{
var requestHelper = new RequestDataHelper();
var requestHelper = new RequestDataHelper(configureByHttpKnownMethodsEnvironmentalVariable: true);
var actual = requestHelper.GetNormalizedHttpMethod(method);
Assert.Equal(expected, actual);
}
Expand All @@ -55,11 +55,20 @@ public void MethodMappingWorksForKnownMethods(string method, string expected)
public void MethodMappingWorksForEnvironmentVariables(string method, string expected)
{
Environment.SetEnvironmentVariable("OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS", "GET,POST");
var requestHelper = new RequestDataHelper();
var requestHelper = new RequestDataHelper(configureByHttpKnownMethodsEnvironmentalVariable: true);
var actual = requestHelper.GetNormalizedHttpMethod(method);
Assert.Equal(expected, actual);
}

[Fact]
public void MethodMappingWorksIfEnvironmentalVariableConfigurationIsDisabled()
{
Environment.SetEnvironmentVariable("OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS", "GET,POST");
var requestHelper = new RequestDataHelper(configureByHttpKnownMethodsEnvironmentalVariable: false);
var actual = requestHelper.GetNormalizedHttpMethod("CONNECT");
Assert.Equal("CONNECT", actual);
}

[Theory]
[InlineData("HTTP/1.1", "1.1")]
[InlineData("HTTP/2", "2")]
Expand Down
Loading