[ASP.NET Core] replace http.target with http.route (#3903)

This commit is contained in:
rinat16 2022-11-18 23:50:30 +06:00 committed by GitHub
parent 50a2180e6e
commit 490b9b1ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -6,6 +6,10 @@
`net.host.name` and `net.host.port` attributes will be populated instead.
([#3858](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3858))
* The `http.server.duration` metric's `http.target` attribute is replaced
with `http.route` attribute.
([#3903](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3903))
## 1.0.0-rc9.9
Released 2022-Nov-07

View File

@ -70,11 +70,11 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
TagList tags;
#if NET6_0_OR_GREATER
var target = (context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText;
var route = (context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText;
// TODO: This is just a minimal set of attributes. See the spec for additional attributes:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#http-server
if (!string.IsNullOrEmpty(target))
if (!string.IsNullOrEmpty(route))
{
tags = new TagList
{
@ -82,7 +82,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
{ SemanticConventions.AttributeHttpScheme, context.Request.Scheme },
{ SemanticConventions.AttributeHttpMethod, context.Request.Method },
{ SemanticConventions.AttributeHttpHost, host },
{ SemanticConventions.AttributeHttpTarget, target },
{ SemanticConventions.AttributeHttpRoute, route },
{ SemanticConventions.AttributeHttpStatusCode, context.Response.StatusCode.ToString() },
};
}

View File

@ -120,13 +120,13 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
var statusCode = new KeyValuePair<string, object>(SemanticConventions.AttributeHttpStatusCode, "200");
var flavor = new KeyValuePair<string, object>(SemanticConventions.AttributeHttpFlavor, "1.1");
var host = new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHost, "localhost");
var target = new KeyValuePair<string, object>(SemanticConventions.AttributeHttpTarget, "api/Values");
var route = new KeyValuePair<string, object>(SemanticConventions.AttributeHttpRoute, "api/Values");
Assert.Contains(method, attributes);
Assert.Contains(scheme, attributes);
Assert.Contains(statusCode, attributes);
Assert.Contains(flavor, attributes);
Assert.Contains(host, attributes);
Assert.Contains(target, attributes);
Assert.Contains(route, attributes);
Assert.Equal(6, attributes.Length);
}