diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index d3a6f7bd3f4..5b608371d46 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Fixed an issue for spans when `server.port` attribute was not set with + `server.address` when it has default values (`80` for `HTTP` and + `443` for `HTTPS` protocol). + ([#5419](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5419)) + ## 1.7.1 Released 2024-Feb-09 diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 97807d41512..a216a31d298 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -185,9 +185,9 @@ public void OnStartActivity(Activity activity, object payload) { activity.SetTag(SemanticConventions.AttributeServerAddress, request.Host.Host); - if (request.Host.Port is not null && request.Host.Port != 80 && request.Host.Port != 443) + if (request.Host.Port.HasValue) { - activity.SetTag(SemanticConventions.AttributeServerPort, request.Host.Port); + activity.SetTag(SemanticConventions.AttributeServerPort, request.Host.Port.Value); } } diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index b634f2b943a..9b7fa69f2f8 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Fixed an issue for spans when `server.port` attribute was not set with + `server.address` when it has default values (`80` for `HTTP` and + `443` for `HTTPS` protocol). + ([#5419](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5419)) + ## 1.7.1 Released 2024-Feb-09 diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs index e0625b420db..8132c92fa28 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs @@ -147,10 +147,7 @@ public void OnStartActivity(Activity activity, object payload) RequestMethodHelper.SetHttpMethodTag(activity, request.Method.Method); activity.SetTag(SemanticConventions.AttributeServerAddress, request.RequestUri.Host); - if (!request.RequestUri.IsDefaultPort) - { - activity.SetTag(SemanticConventions.AttributeServerPort, request.RequestUri.Port); - } + activity.SetTag(SemanticConventions.AttributeServerPort, request.RequestUri.Port); activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri)); diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs index c27bef64132..620cfcc75d0 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs @@ -103,10 +103,7 @@ private static void AddRequestTagsAndInstrumentRequest(HttpWebRequest request, A RequestMethodHelper.SetHttpMethodTag(activity, request.Method); activity.SetTag(SemanticConventions.AttributeServerAddress, request.RequestUri.Host); - if (!request.RequestUri.IsDefaultPort) - { - activity.SetTag(SemanticConventions.AttributeServerPort, request.RequestUri.Port); - } + activity.SetTag(SemanticConventions.AttributeServerPort, request.RequestUri.Port); activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri));