-
Notifications
You must be signed in to change notification settings - Fork 355
[Instrumentation.AspNet] Update semantic conventions for metrics #1429
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
Merged
utpilla
merged 21 commits into
open-telemetry:main
from
qhris:features/asp-metric-attributes
Dec 12, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
158d4de
Update metrics for ASP
qhris 1126f11
Update changelog links
qhris b8f19ad
Remove error.type
qhris b9b02a8
Remove network.protocol.name
qhris f14f43f
Fix minor suggested changes
qhris 22aaef2
Correctly handle http.request.method
qhris ec284b1
Merge branch 'main' into features/asp-metric-attributes
qhris 609bda5
Refactor RequetMethodHttpHelper
qhris 5c00e8e
Fix outdated comment
qhris d780ca6
Do not instantiate default http methods if env variable is used
qhris 0b04175
Fix http.server.request.duration buckets
qhris ec7158e
Update bucket boundaries and remove invalid dependency
qhris c444309
Merge branch 'main' into features/asp-metric-attributes
Kielek fc7e83f
Merge branch 'main' into features/asp-metric-attributes
qhris 4480d65
Update CHANGELOG.md
qhris 73b6759
Simplify copyright disclaimer
qhris 33c750e
Fix markdown line length
qhris 2a73a4b
Fix CA1861
qhris 706f14f
Ordering of fields
qhris e349bfb
Merge branch 'main' into features/asp-metric-attributes
cijothomas 3dd0fae
Merge branch 'main' into features/asp-metric-attributes
utpilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
48 changes: 48 additions & 0 deletions
48
src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpRequestRouteHelper.cs
This file contains hidden or 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,48 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using System; | ||
| using System.Web; | ||
| using System.Web.Routing; | ||
|
|
||
| namespace OpenTelemetry.Instrumentation.AspNet.Implementation; | ||
|
|
||
| /// <summary> | ||
| /// Helper class for processing http requests. | ||
| /// </summary> | ||
| internal sealed class HttpRequestRouteHelper | ||
| { | ||
| private readonly PropertyFetcher<object> routeFetcher = new("Route"); | ||
| private readonly PropertyFetcher<string> routeTemplateFetcher = new("RouteTemplate"); | ||
|
|
||
| /// <summary> | ||
| /// Extracts the route template from the <see cref="HttpRequest"/>. | ||
| /// </summary> | ||
| /// <param name="request">The <see cref="HttpRequest"/> being processed.</param> | ||
| /// <returns>The route template or <see langword="null"/>.</returns> | ||
| internal string? GetRouteTemplate(HttpRequest request) | ||
| { | ||
| var routeData = request.RequestContext.RouteData; | ||
|
|
||
| string? template = null; | ||
| if (routeData.Values.TryGetValue("MS_SubRoutes", out object msSubRoutes)) | ||
| { | ||
| // WebAPI attribute routing flows here. Use reflection to not take a dependency on microsoft.aspnet.webapi.core\[version]\lib\[framework]\System.Web.Http. | ||
|
|
||
| if (msSubRoutes is Array attributeRouting && attributeRouting.Length == 1) | ||
| { | ||
| var subRouteData = attributeRouting.GetValue(0); | ||
|
|
||
| _ = this.routeFetcher.TryFetch(subRouteData, out var route); | ||
| _ = this.routeTemplateFetcher.TryFetch(route, out template); | ||
| } | ||
| } | ||
| else if (routeData.Route is Route route) | ||
| { | ||
| // MVC + WebAPI traditional routing & MVC attribute routing flow here. | ||
| template = route.Url; | ||
| } | ||
|
|
||
| return template; | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/OpenTelemetry.Instrumentation.AspNet/Implementation/RequestMethodHelper.cs
This file contains hidden or 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,49 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace OpenTelemetry.Instrumentation.AspNet.Implementation; | ||
|
|
||
| internal sealed class RequestMethodHelper | ||
| { | ||
| private const string KnownHttpMethodsEnvironmentVariable = "OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS"; | ||
|
|
||
| // The value "_OTHER" is used for non-standard HTTP methods. | ||
| // https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md#common-attributes | ||
| private const string OtherHttpMethod = "_OTHER"; | ||
|
|
||
| private static readonly char[] SplitChars = new[] { ',' }; | ||
|
|
||
| // List of known HTTP methods as per spec. | ||
| private readonly Dictionary<string, string> knownHttpMethods; | ||
|
|
||
| public RequestMethodHelper() | ||
| { | ||
| var suppliedKnownMethods = Environment.GetEnvironmentVariable(KnownHttpMethodsEnvironmentVariable) | ||
| ?.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); | ||
| this.knownHttpMethods = suppliedKnownMethods?.Length > 0 | ||
| ? suppliedKnownMethods.ToDictionary(x => x, x => x, StringComparer.OrdinalIgnoreCase) | ||
| : new(StringComparer.OrdinalIgnoreCase) | ||
| { | ||
| ["GET"] = "GET", | ||
| ["POST"] = "POST", | ||
| ["PUT"] = "PUT", | ||
| ["DELETE"] = "DELETE", | ||
| ["HEAD"] = "HEAD", | ||
| ["OPTIONS"] = "OPTIONS", | ||
| ["TRACE"] = "TRACE", | ||
| ["PATCH"] = "PATCH", | ||
| ["CONNECT"] = "CONNECT", | ||
| }; | ||
| } | ||
|
|
||
| public string GetNormalizedHttpMethod(string method) | ||
qhris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return this.knownHttpMethods.TryGetValue(method, out var normalizedMethod) | ||
| ? normalizedMethod | ||
| : OtherHttpMethod; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.