Skip to content

Commit 9dd152c

Browse files
authored
[HTTP] Remove peer.address from connection OTel counters (#128940)
OTel changed specification for these 2 tags to "Opt-In". We do not have any toggles for Opt-In tags and we simply omit them. Therefore, I'm removing them from the code. OTel change: open-telemetry/semantic-conventions#3759 Contributes to #122752
1 parent d2b5550 commit 9dd152c

3 files changed

Lines changed: 7 additions & 32 deletions

File tree

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ protected void MarkConnectionAsEstablished(Activity? connectionSetupActivity, IP
7575
protocol,
7676
_pool.IsSecure ? "https" : "http",
7777
_pool.TelemetryServerAddress,
78-
_pool.OriginAuthority.Port,
79-
remoteEndPoint?.Address?.ToString());
78+
_pool.OriginAuthority.Port);
8079

8180
_connectionMetrics.ConnectionEstablished();
8281
}

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Metrics/ConnectionMetrics.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ internal sealed class ConnectionMetrics
1414
private readonly object _schemeTag;
1515
private readonly object _hostTag;
1616
private readonly object _portTag;
17-
private readonly object? _peerAddressTag;
1817
private bool _currentlyIdle;
1918

20-
public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocolVersion, string scheme, string host, int port, string? peerAddress)
19+
public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocolVersion, string scheme, string host, int port)
2120
{
2221
_metrics = metrics;
2322
_openConnectionsEnabled = _metrics.OpenConnections.Enabled;
2423
_protocolVersionTag = protocolVersion;
2524
_schemeTag = scheme;
2625
_hostTag = host;
2726
_portTag = DiagnosticsHelper.GetBoxedInt32(port);
28-
_peerAddressTag = peerAddress;
2927
}
3028

3129
// TagList is a huge struct, so we avoid storing it in a field to reduce the amount we allocate on the heap.
@@ -38,11 +36,6 @@ private TagList GetTags()
3836
tags.Add("server.address", _hostTag);
3937
tags.Add("server.port", _portTag);
4038

41-
if (_peerAddressTag is not null)
42-
{
43-
tags.Add("network.peer.address", _peerAddressTag);
44-
}
45-
4639
return tags;
4740
}
4841

src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@ protected HttpMetricsTestBase(ITestOutputHelper output) : base(output)
7373
}
7474

7575

76-
private static void VerifyPeerAddress(KeyValuePair<string, object?>[] tags, IPAddress[] validPeerAddresses = null)
77-
{
78-
string ipString = (string)tags.Single(t => t.Key == "network.peer.address").Value;
79-
validPeerAddresses ??= [IPAddress.Loopback.MapToIPv6(), IPAddress.Loopback, IPAddress.IPv6Loopback];
80-
IPAddress ip = IPAddress.Parse(ipString);
81-
Assert.Contains(ip, validPeerAddresses);
82-
}
83-
84-
8576
protected static void VerifyRequestDuration(Measurement<double> measurement,
8677
Uri uri,
8778
Version? protocolVersion = null,
@@ -127,29 +118,23 @@ protected static void VerifyActiveRequests(string instrumentName, long measureme
127118
Assert.Equal(method, tags.Single(t => t.Key == "http.request.method").Value);
128119
}
129120

130-
protected static void VerifyOpenConnections(string actualName, object measurement, KeyValuePair<string, object?>[] tags, long expectedValue, Uri uri, Version? protocolVersion, string state, IPAddress[] validPeerAddresses = null)
121+
protected static void VerifyOpenConnections(string actualName, object measurement, KeyValuePair<string, object?>[] tags, long expectedValue, Uri uri, Version? protocolVersion, string state)
131122
{
132123
Assert.Equal(InstrumentNames.OpenConnections, actualName);
133124
Assert.Equal(expectedValue, Assert.IsType<long>(measurement));
134125
VerifySchemeHostPortTags(tags, uri);
135126
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
136127
VerifyTag(tags, "http.connection.state", state);
137-
VerifyPeerAddress(tags, validPeerAddresses);
138128
}
139129

140-
protected static void VerifyConnectionDuration(string instrumentName, object measurement, KeyValuePair<string, object?>[] tags, Uri uri, Version? protocolVersion, IPAddress[] validPeerAddresses = null)
130+
protected static void VerifyConnectionDuration(string instrumentName, object measurement, KeyValuePair<string, object?>[] tags, Uri uri, Version? protocolVersion)
141131
{
142132
Assert.Equal(InstrumentNames.ConnectionDuration, instrumentName);
143133
double value = Assert.IsType<double>(measurement);
144134

145-
// This flakes for remote requests on CI.
146-
if (validPeerAddresses is null)
147-
{
148-
Assert.InRange(value, double.Epsilon, 60);
149-
}
135+
Assert.InRange(value, double.Epsilon, 60);
150136
VerifySchemeHostPortTags(tags, uri);
151137
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
152-
VerifyPeerAddress(tags, validPeerAddresses);
153138
}
154139

155140
protected static void VerifyTimeInQueue(string instrumentName, object measurement, KeyValuePair<string, object?>[] tags, Uri uri, Version? protocolVersion, string method = "GET")
@@ -384,8 +369,6 @@ public async Task ExternalServer_DurationMetrics_Recorded()
384369
Uri uri = UseVersion == HttpVersion.Version11
385370
? Test.Common.Configuration.Http.RemoteHttp11Server.EchoUri
386371
: Test.Common.Configuration.Http.RemoteHttp2Server.EchoUri;
387-
IPAddress[] addresses = await Dns.GetHostAddressesAsync(uri.Host);
388-
addresses = addresses.Union(addresses.Select(a => a.MapToIPv6())).ToArray();
389372

390373
using (HttpMessageInvoker client = CreateHttpMessageInvoker())
391374
{
@@ -398,9 +381,9 @@ public async Task ExternalServer_DurationMetrics_Recorded()
398381

399382
VerifyRequestDuration(Assert.Single(requestDurationRecorder.GetMeasurements()), uri, UseVersion, 200, "GET");
400383
Measurement<double> cd = Assert.Single(connectionDurationRecorder.GetMeasurements());
401-
VerifyConnectionDuration(InstrumentNames.ConnectionDuration, cd.Value, cd.Tags.ToArray(), uri, UseVersion, addresses);
384+
VerifyConnectionDuration(InstrumentNames.ConnectionDuration, cd.Value, cd.Tags.ToArray(), uri, UseVersion);
402385
Measurement<long> oc = openConnectionsRecorder.GetMeasurements().First();
403-
VerifyOpenConnections(InstrumentNames.OpenConnections, oc.Value, oc.Tags.ToArray(), 1, uri, UseVersion, "idle", addresses);
386+
VerifyOpenConnections(InstrumentNames.OpenConnections, oc.Value, oc.Tags.ToArray(), 1, uri, UseVersion, "idle");
404387
}
405388

406389
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]

0 commit comments

Comments
 (0)