[HttpClient] update `network.protocol.version` values as per specification (#5006)

This commit is contained in:
Vishwesh Bankwar 2023-11-10 14:29:55 -08:00 committed by GitHub
parent 4ccee25c9f
commit 66373082d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 4 deletions

View File

@ -41,6 +41,9 @@
([#5005](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5005))
([#5034](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5034))
* Fixed `network.protocol.version` attribute values to match the specification.
([#5006](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5006))
## 1.6.0-beta.2
Released 2023-Oct-26

View File

@ -205,7 +205,7 @@ internal sealed class HttpHandlerDiagnosticListener : ListenerHandler
}
activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri));
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.Version));
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.Version));
if (request.Headers.TryGetValues("User-Agent", out var userAgentValues))
{

View File

@ -130,7 +130,7 @@ internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler
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.AttributeNetworkProtocolVersion, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.Version)));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.Version)));
if (!request.RequestUri.IsDefaultPort)
{

View File

@ -78,6 +78,15 @@ internal static class HttpTagHelper
return string.Concat(uri.Scheme, Uri.SchemeDelimiter, uri.Authority, uri.PathAndQuery, uri.Fragment);
}
public static string GetProtocolVersionString(Version httpVersion) => (httpVersion.Major, httpVersion.Minor) switch
{
(1, 0) => "1.0",
(1, 1) => "1.1",
(2, 0) => "2",
(3, 0) => "3",
_ => httpVersion.ToString(),
};
private static string ConvertMethodToOperationName(string method) => $"HTTP {method}";
private static string ConvertHttpMethodToOperationName(HttpMethod method) => $"HTTP {method}";

View File

@ -173,7 +173,7 @@ internal static class HttpWebRequestActivitySource
}
activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri));
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.ProtocolVersion));
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.ProtocolVersion));
}
try
@ -531,7 +531,7 @@ internal static class HttpWebRequestActivitySource
tags.Add(SemanticConventions.AttributeServerAddress, request.RequestUri.Host);
tags.Add(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme);
tags.Add(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.ProtocolVersion));
tags.Add(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.ProtocolVersion));
if (!request.RequestUri.IsDefaultPort)
{
tags.Add(SemanticConventions.AttributeServerPort, request.RequestUri.Port);