Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ private static string GetErrorReason(Exception exception)
{
(1, 0) => "1.0",
(1, 1) => "1.1",
(2, 0) => "2.0",
(3, 0) => "3.0",
(2, 0) => "2",
(3, 0) => "3",
_ => httpVersion.ToString()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public HttpConnectionBase(HttpConnectionPool pool, IPEndPoint? remoteEndPoint)
// While requests may report HTTP/1.0 as the protocol, we treat all HTTP/1.X connections as HTTP/1.1.
string protocol =
this is HttpConnection ? "1.1" :
this is Http2Connection ? "2.0" :
"3.0";
this is Http2Connection ? "2" :
"3";

_connectionMetrics = new ConnectionMetrics(
metrics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void RequestLeftQueue(HttpRequestMessage request, HttpConnectionPool pool
tags.Add("network.protocol.version", versionMajor switch
{
1 => "1.1",
2 => "2.0",
_ => "3.0"
2 => "2",
_ => "3"
});

tags.Add("url.scheme", pool.IsSecure ? "https" : "http");
Expand Down
17 changes: 12 additions & 5 deletions src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ private static void VerifySchemeHostPortTags(KeyValuePair<string, object?>[] tag
VerifyTag(tags, "server.port", uri.Port);
}

private static string? GetVersionString(Version? version) => version == null ? null : version.Major switch
{
1 => "1.1",
2 => "2",
_ => "3"
};

protected static void VerifyRequestDuration(Measurement<double> measurement,
Uri uri,
Version? protocolVersion,
Expand All @@ -75,7 +82,7 @@ protected static void VerifyRequestDuration(string instrumentName,
double measurement,
KeyValuePair<string, object?>[] tags,
Uri uri,
Version? protocol,
Version? protocolVersion,
int? statusCode,
string method = "GET",
string[] acceptedErrorReasons = null)
Expand All @@ -84,7 +91,7 @@ protected static void VerifyRequestDuration(string instrumentName,
Assert.InRange(measurement, double.Epsilon, 60);
VerifySchemeHostPortTags(tags, uri);
VerifyTag(tags, "http.request.method", method);
VerifyTag(tags, "network.protocol.version", protocol?.ToString());
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
VerifyTag(tags, "http.response.status_code", statusCode);
if (acceptedErrorReasons == null)
{
Expand Down Expand Up @@ -113,7 +120,7 @@ protected static void VerifyOpenConnections(string actualName, object measuremen
Assert.Equal(InstrumentNames.OpenConnections, actualName);
Assert.Equal(expectedValue, Assert.IsType<long>(measurement));
VerifySchemeHostPortTags(tags, uri);
VerifyTag(tags, "network.protocol.version", protocolVersion.ToString());
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
VerifyTag(tags, "http.connection.state", state);
VerifySocketAddress(tags);
}
Expand All @@ -124,7 +131,7 @@ protected static void VerifyConnectionDuration(string instrumentName, object mea
double value = Assert.IsType<double>(measurement);
Assert.InRange(value, double.Epsilon, 60);
VerifySchemeHostPortTags(tags, uri);
VerifyTag(tags, "network.protocol.version", protocolVersion.ToString());
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
VerifySocketAddress(tags);
}

Expand All @@ -134,7 +141,7 @@ protected static void VerifyTimeInQueue(string instrumentName, object measuremen
double value = Assert.IsType<double>(measurement);
Assert.InRange(value, double.Epsilon, 60);
VerifySchemeHostPortTags(tags, uri);
VerifyTag(tags, "network.protocol.version", protocolVersion.ToString());
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
VerifyTag(tags, "http.request.method", method);
}

Expand Down