Skip to content

Commit

Permalink
[Instrumentation.Http, Instrumentation.AspNetCore] Always set server.…
Browse files Browse the repository at this point in the history
…port attribute for spans (open-telemetry#5419)
  • Loading branch information
Kielek authored Mar 12, 2024
1 parent ff6725f commit 4cccb09
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 4cccb09

Please sign in to comment.