Skip to content

Commit

Permalink
Add support for OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS
Browse files Browse the repository at this point in the history
  • Loading branch information
ngruson committed Dec 21, 2023
1 parent 65dd83b commit 81790f5
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public static MeterProviderBuilder AddAspNetCoreInstrumentation(
#if NET8_0_OR_GREATER
return builder.ConfigureMeters();
#else
// Note: Warm-up the status code and method mapping.
// Note: Warm-up the status code.
_ = TelemetryHelper.BoxedStatusCodes;
_ = RequestMethodHelper.KnownMethods;

builder.AddMeter(HttpInMetricsListener.InstrumentationName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static TracerProviderBuilder AddAspNetCoreInstrumentation(

// Note: Warm-up the status code and method mapping.
_ = TelemetryHelper.BoxedStatusCodes;
_ = RequestMethodHelper.KnownMethods;

name ??= Options.DefaultName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if NET8_0_OR_GREATER
using System.Collections.Frozen;

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-report (windows-latest)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check warning on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-stable

Using directive is unnecessary.

Check warning on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-stable

Using directive is unnecessary.

Check warning on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-experimental

Using directive is unnecessary.

Check warning on line 5 in src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-experimental

Using directive is unnecessary.
#endif
using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -29,6 +32,15 @@ internal AspNetCoreTraceInstrumentationOptions(IConfiguration configuration)
{
this.EnableGrpcAspNetCoreSupport = enableGrpcInstrumentation;
}

if (configuration.TryGetStringValue("OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS", out var knownHttpMethods))
{
this.KnownHttpMethods = knownHttpMethods
.Split(',')
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToList();
}
}

/// <summary>
Expand Down Expand Up @@ -91,4 +103,6 @@ internal AspNetCoreTraceInstrumentationOptions(IConfiguration configuration)
/// https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-spans.md.
/// </remarks>
internal bool EnableGrpcAspNetCoreSupport { get; set; }

internal List<string> KnownHttpMethods { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ internal class HttpInListener : ListenerHandler
private readonly PropertyFetcher<string> beforeActionTemplateFetcher = new("Template");
#endif
private readonly AspNetCoreTraceInstrumentationOptions options;
private readonly RequestMethodHelper requestMethodHelper;

public HttpInListener(AspNetCoreTraceInstrumentationOptions options)
: base(DiagnosticSourceName)
{
Guard.ThrowIfNull(options);

this.options = options;
this.requestMethodHelper = new RequestMethodHelper(this.options.KnownHttpMethods);
}

public override void OnEventWritten(string name, object payload)
Expand Down Expand Up @@ -105,8 +107,7 @@ public void OnStartActivity(Activity activity, object payload)
// By this time, samplers have already run and
// activity.IsAllDataRequested populated accordingly.

HttpContext context = payload as HttpContext;
if (context == null)
if (payload is not HttpContext context)
{
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStartActivity), activity.OperationName);
return;
Expand Down Expand Up @@ -176,7 +177,7 @@ public void OnStartActivity(Activity activity, object payload)
#endif

var path = (request.PathBase.HasValue || request.Path.HasValue) ? (request.PathBase + request.Path).ToString() : "/";
activity.DisplayName = GetDisplayName(request.Method);
activity.DisplayName = this.GetDisplayName(request.Method);

// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md

Expand All @@ -196,7 +197,7 @@ public void OnStartActivity(Activity activity, object payload)
activity.SetTag(SemanticConventions.AttributeUrlQuery, request.QueryString.Value);
}

RequestMethodHelper.SetHttpMethodTag(activity, request.Method);
this.requestMethodHelper.SetHttpMethodTag(activity, request.Method);

activity.SetTag(SemanticConventions.AttributeUrlScheme, request.Scheme);
activity.SetTag(SemanticConventions.AttributeUrlPath, path);
Expand Down Expand Up @@ -226,8 +227,7 @@ public void OnStopActivity(Activity activity, object payload)
{
if (activity.IsAllDataRequested)
{
HttpContext context = payload as HttpContext;
if (context == null)
if (payload is not HttpContext context)
{
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStopActivity), activity.OperationName);
return;
Expand All @@ -239,7 +239,7 @@ public void OnStopActivity(Activity activity, object payload)
var routePattern = (context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText;
if (!string.IsNullOrEmpty(routePattern))
{
activity.DisplayName = GetDisplayName(context.Request.Method, routePattern);
activity.DisplayName = this.GetDisplayName(context.Request.Method, routePattern);
activity.SetTag(SemanticConventions.AttributeHttpRoute, routePattern);
}
#endif
Expand Down Expand Up @@ -382,9 +382,9 @@ private static void AddGrpcAttributes(Activity activity, string grpcMethod, Http
}
}

private static string GetDisplayName(string httpMethod, string httpRoute = null)
private string GetDisplayName(string httpMethod, string httpRoute = null)
{
var normalizedMethod = RequestMethodHelper.GetNormalizedHttpMethod(httpMethod);
var normalizedMethod = this.requestMethodHelper.GetNormalizedHttpMethod(httpMethod);

return string.IsNullOrEmpty(httpRoute)
? normalizedMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public static void OnStopEventWritten(string name, object payload)
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeUrlScheme, context.Request.Scheme));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(context.Response.StatusCode)));

var httpMethod = RequestMethodHelper.GetNormalizedHttpMethod(context.Request.Method);
var requestMethodHelper = new RequestMethodHelper(string.Empty);
var httpMethod = requestMethodHelper.GetNormalizedHttpMethod(context.Request.Method);
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpRequestMethod, httpMethod));

#if NET6_0_OR_GREATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ public static MeterProviderBuilder AddHttpClientInstrumentation(
.AddMeter("System.Net.Http")
.AddMeter("System.Net.NameResolution");
#else
// Note: Warm-up the status code and method mapping.
// Note: Warm-up the status code.
_ = TelemetryHelper.BoxedStatusCodes;
_ = RequestMethodHelper.KnownMethods;

#if NETFRAMEWORK
builder.AddMeter(HttpWebRequestActivitySource.MeterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(
{
Guard.ThrowIfNull(builder);

// Note: Warm-up the status code and method mapping.
// Note: Warm-up the status code.
_ = TelemetryHelper.BoxedStatusCodes;
_ = RequestMethodHelper.KnownMethods;

name ??= Options.DefaultName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif
using System.Diagnostics;
using System.Net;
#if NETFRAMEWORK
using System.Net.Http;
#endif
using System.Runtime.CompilerServices;
using OpenTelemetry.Instrumentation.Http.Implementation;
using OpenTelemetry.Internal;

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-report (windows-latest)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check warning on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-stable

Using directive is unnecessary.

Check warning on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-stable

Using directive is unnecessary.

Check warning on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-experimental

Using directive is unnecessary.

Check warning on line 14 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / check-format-experimental

Using directive is unnecessary.

namespace OpenTelemetry.Instrumentation.Http;

Expand Down Expand Up @@ -125,6 +129,12 @@ public class HttpClientTraceInstrumentationOptions
/// </remarks>
public bool RecordException { get; set; }

#if NET8_0_OR_GREATER
internal FrozenDictionary<string, string> KnownHttpMethods { get; set; }
#else
internal Dictionary<string, string> KnownHttpMethods { get; set; } = RequestMethodHelper.GetKnownMethods(null);

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-report (windows-latest)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net8.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net7.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level

Check failure on line 135 in src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net6.0)

'RequestMethodHelper.GetKnownMethods(string)' is inaccessible due to its protection level
#endif

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool EventFilterHttpRequestMessage(string activityName, object arg1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenTelemetry.Instrumentation.Http.Implementation;

internal sealed class HttpHandlerDiagnosticListener : ListenerHandler
internal sealed class HttpHandlerDiagnosticListener(HttpClientTraceInstrumentationOptions options) : ListenerHandler("HttpHandlerDiagnosticListener")
{
internal static readonly AssemblyName AssemblyName = typeof(HttpHandlerDiagnosticListener).Assembly.GetName();
internal static readonly bool IsNet7OrGreater;
Expand All @@ -34,7 +34,7 @@ internal sealed class HttpHandlerDiagnosticListener : ListenerHandler
private static readonly PropertyFetcher<HttpResponseMessage> StopResponseFetcher = new("Response");
private static readonly PropertyFetcher<Exception> StopExceptionFetcher = new("Exception");
private static readonly PropertyFetcher<TaskStatus> StopRequestStatusFetcher = new("RequestTaskStatus");
private readonly HttpClientTraceInstrumentationOptions options;
private readonly HttpClientTraceInstrumentationOptions options = options;

static HttpHandlerDiagnosticListener()
{
Expand All @@ -48,12 +48,6 @@ static HttpHandlerDiagnosticListener()
}
}

public HttpHandlerDiagnosticListener(HttpClientTraceInstrumentationOptions options)
: base("HttpHandlerDiagnosticListener")
{
this.options = options;
}

public override void OnEventWritten(string name, object payload)
{
switch (name)
Expand Down Expand Up @@ -135,7 +129,7 @@ public void OnStartActivity(Activity activity, object payload)
return;
}

RequestMethodHelper.SetHttpClientActivityDisplayName(activity, request.Method.Method);
RequestMethodHelper.SetHttpClientActivityDisplayName(activity, request.Method.Method, this.options.KnownHttpMethods);

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net7.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net7.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net6.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net7.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net7.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-report (windows-latest)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net7.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net7.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net6.0)

No overload for method 'SetHttpClientActivityDisplayName' takes 3 arguments

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 132 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

if (!IsNet7OrGreater)
{
Expand All @@ -144,7 +138,7 @@ public void OnStartActivity(Activity activity, object payload)
}

// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md
RequestMethodHelper.SetHttpMethodTag(activity, request.Method.Method);
RequestMethodHelper.SetHttpMethodTag(activity, request.Method.Method, this.options.KnownHttpMethods);

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (ubuntu-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-report (windows-latest)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 141 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

activity.SetTag(SemanticConventions.AttributeServerAddress, request.RequestUri.Host);
if (!request.RequestUri.IsDefaultPort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ internal static HttpClientTraceInstrumentationOptions TracingOptions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void AddRequestTagsAndInstrumentRequest(HttpWebRequest request, Activity activity)
{
RequestMethodHelper.SetHttpClientActivityDisplayName(activity, request.Method);
RequestMethodHelper.SetHttpClientActivityDisplayName(activity, request.Method, tracingOptions.KnownHttpMethods);

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net7.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net462)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-stable

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-report (windows-latest)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net462)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net8.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

Check failure on line 98 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net6.0)

An object reference is required for the non-static field, method, or property 'RequestMethodHelper.SetHttpClientActivityDisplayName(Activity, string, Dictionary<string, string>)'

if (activity.IsAllDataRequested)
{
// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md
RequestMethodHelper.SetHttpMethodTag(activity, request.Method);
RequestMethodHelper.SetHttpMethodTag(activity, request.Method, tracingOptions.KnownHttpMethods);

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net7.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test (ubuntu-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (ubuntu-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-stable

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-stable (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-report (windows-latest)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net462)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net8.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

Check failure on line 103 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs

View workflow job for this annotation

GitHub Actions / build-test-experimental (windows-latest, net6.0)

No overload for method 'SetHttpMethodTag' takes 3 arguments

activity.SetTag(SemanticConventions.AttributeServerAddress, request.RequestUri.Host);
if (!request.RequestUri.IsDefaultPort)
Expand Down
92 changes: 73 additions & 19 deletions src/Shared/RequestMethodHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@

namespace OpenTelemetry.Internal;

internal static class RequestMethodHelper
internal class RequestMethodHelper
{
// The value "_OTHER" is used for non-standard HTTP methods.
// https://github.com/open-telemetry/semantic-conventions/blob/v1.22.0/docs/http/http-spans.md#common-attributes
public const string OtherHttpMethod = "_OTHER";

#if NET8_0_OR_GREATER
internal static readonly FrozenDictionary<string, string> KnownMethods;
#else
internal static readonly Dictionary<string, string> KnownMethods;
#endif

static RequestMethodHelper()
{
var knownMethodSet = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
private static readonly Dictionary<string, string> DefaultKnownMethods = new(StringComparer.OrdinalIgnoreCase)
{
{ "GET", "GET" },
{ "PUT", "PUT" },
Expand All @@ -36,24 +28,45 @@ static RequestMethodHelper()
{ "CONNECT", "CONNECT" },
};

// KnownMethods ignores case. Use the value returned by the dictionary to have a consistent case.
#if NET8_0_OR_GREATER
KnownMethods = FrozenDictionary.ToFrozenDictionary(knownMethodSet, StringComparer.OrdinalIgnoreCase);
private readonly FrozenDictionary<string, string> knownMethods;
#else
KnownMethods = knownMethodSet;
private Dictionary<string, string> knownMethods;
#endif

public RequestMethodHelper(string configuredKnownMethods)
{
var splitArray = configuredKnownMethods.Split(',')
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToList();

this.knownMethods = GetKnownMethods(splitArray);
}

public RequestMethodHelper(List<string> configuredKnownMethods)
{
this.knownMethods = GetKnownMethods(configuredKnownMethods);
}

public static string GetNormalizedHttpMethod(string method)
#if NET8_0_OR_GREATER
public string GetNormalizedHttpMethod(string method)
#else
public string GetNormalizedHttpMethod(string method, Dictionary<string, string> knownMethods = null)
#endif
{
return KnownMethods.TryGetValue(method, out var normalizedMethod)
return this.knownMethods.TryGetValue(method, out var normalizedMethod)
? normalizedMethod
: OtherHttpMethod;
}

public static void SetHttpMethodTag(Activity activity, string method)
#if NET8_0_OR_GREATER
public void SetHttpMethodTag(Activity activity, string method)
#else
public void SetHttpMethodTag(Activity activity, string method)
#endif
{
if (KnownMethods.TryGetValue(method, out var normalizedMethod))
if (this.knownMethods.TryGetValue(method, out var normalizedMethod))
{
activity?.SetTag(SemanticConventions.AttributeHttpRequestMethod, normalizedMethod);
}
Expand All @@ -64,9 +77,50 @@ public static void SetHttpMethodTag(Activity activity, string method)
}
}

public static void SetHttpClientActivityDisplayName(Activity activity, string method)
#if NET8_0_OR_GREATER
public void SetHttpClientActivityDisplayName(Activity activity, string method)
#else
public void SetHttpClientActivityDisplayName(Activity activity, string method, Dictionary<string, string> knownMethods)
#endif
{
// https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md#name
activity.DisplayName = KnownMethods.TryGetValue(method, out var httpMethod) ? httpMethod : "HTTP";
activity.DisplayName = this.knownMethods.TryGetValue(method, out var httpMethod) ? httpMethod : "HTTP";
}

#if NET8_0_OR_GREATER
private static FrozenDictionary<string, string> GetKnownMethods(string configuredKnownMethods)
#else
private static Dictionary<string, string> GetKnownMethods(string configuredKnownMethods)
#endif
{
var splitArray = configuredKnownMethods.Split(',')
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToList();

return GetKnownMethods(splitArray);
}

#if NET8_0_OR_GREATER
private static FrozenDictionary<string, string> GetKnownMethods(List<string> configuredKnownMethods)
#else
private static Dictionary<string, string> GetKnownMethods(List<string> configuredKnownMethods)
#endif
{
IEnumerable<KeyValuePair<string, string>> knownMethods = DefaultKnownMethods;

if (configuredKnownMethods != null)
{
if (configuredKnownMethods.Count > 0)
{
knownMethods = DefaultKnownMethods.Where(x => configuredKnownMethods.Contains(x.Key, StringComparer.InvariantCultureIgnoreCase));
}
}

#if NET8_0_OR_GREATER
return FrozenDictionary.ToFrozenDictionary(knownMethods, StringComparer.OrdinalIgnoreCase);
#else
return knownMethods.ToDictionary(x => x.Key, x => x.Value);
#endif
}
}
Loading

0 comments on commit 81790f5

Please sign in to comment.