-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASP.NET Core] Set
http.request.method
as per spec (#5001)
- Loading branch information
1 parent
b45b8a9
commit 5cb7a3f
Showing
11 changed files
with
265 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// <copyright file="RequestMethodHelper.cs" company="OpenTelemetry Authors"> | ||
// 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. | ||
// </copyright> | ||
|
||
#if NET8_0_OR_GREATER | ||
using System.Collections.Frozen; | ||
#endif | ||
|
||
namespace OpenTelemetry.Internal; | ||
|
||
internal static class RequestMethodHelper | ||
{ | ||
#if NET8_0_OR_GREATER | ||
internal static readonly FrozenDictionary<string, string> KnownMethods; | ||
#else | ||
internal static readonly Dictionary<string, string> KnownMethods; | ||
#endif | ||
|
||
static RequestMethodHelper() | ||
{ | ||
#if NET8_0_OR_GREATER | ||
KnownMethods = FrozenDictionary.ToFrozenDictionary( | ||
new[] | ||
{ | ||
KeyValuePair.Create("GET", "GET"), | ||
KeyValuePair.Create("PUT", "PUT"), | ||
KeyValuePair.Create("POST", "POST"), | ||
KeyValuePair.Create("DELETE", "DELETE"), | ||
KeyValuePair.Create("HEAD", "HEAD"), | ||
KeyValuePair.Create("OPTIONS", "OPTIONS"), | ||
KeyValuePair.Create("TRACE", "TRACE"), | ||
KeyValuePair.Create("PATCH", "PATCH"), | ||
KeyValuePair.Create("CONNECT", "CONNECT"), | ||
}, | ||
StringComparer.OrdinalIgnoreCase); | ||
#else | ||
KnownMethods = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) | ||
{ | ||
{ "GET", "GET" }, | ||
{ "PUT", "PUT" }, | ||
{ "POST", "POST" }, | ||
{ "DELETE", "DELETE" }, | ||
{ "HEAD", "HEAD" }, | ||
{ "OPTIONS", "OPTIONS" }, | ||
{ "TRACE", "TRACE" }, | ||
{ "PATCH", "PATCH" }, | ||
{ "CONNECT", "CONNECT" }, | ||
}; | ||
#endif | ||
} | ||
|
||
public static bool TryResolveHttpMethod(string method, out string resolvedMethod) | ||
{ | ||
if (KnownMethods.TryGetValue(method, out resolvedMethod)) | ||
{ | ||
// KnownMethods ignores case. Use the value returned by the dictionary to have a consistent case. | ||
return true; | ||
} | ||
|
||
// Set to default "_OTHER" as per spec. | ||
// https://github.com/open-telemetry/semantic-conventions/blob/v1.22.0/docs/http/http-spans.md#common-attributes | ||
resolvedMethod = "_OTHER"; | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters