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
  • Loading branch information
Kielek committed Mar 6, 2024
1 parent bae8a6b commit 69cc79a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* `server.port` attribute is set even if 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
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* `server.port` attribute is set even if 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 @@ -50,12 +50,9 @@ public static void OnStopEventWritten(Activity activity, object payload)
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpRequestMethod, httpMethod));

tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeServerAddress, request.RequestUri.Host));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeServerPort, request.RequestUri.Port));

if (!request.RequestUri.IsDefaultPort)
{
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeServerPort, request.RequestUri.Port));
}
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme));

if (TryFetchResponse(payload, out HttpResponseMessage response))
{
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 Expand Up @@ -429,17 +426,14 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpRequestMethod, httpMethod));

tags.Add(SemanticConventions.AttributeServerAddress, request.RequestUri.Host);
tags.Add(SemanticConventions.AttributeServerPort, request.RequestUri.Port);

tags.Add(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme);
if (protocolVersion != null)
{
tags.Add(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(protocolVersion));
}

if (!request.RequestUri.IsDefaultPort)
{
tags.Add(SemanticConventions.AttributeServerPort, request.RequestUri.Port);
}

if (httpStatusCode.HasValue)
{
tags.Add(SemanticConventions.AttributeHttpResponseStatusCode, (int)httpStatusCode.Value);
Expand Down

0 comments on commit 69cc79a

Please sign in to comment.