-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[HTTP Telemetry] Prioritize Host header when emitting server.address
#117540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tagging subscribers to this area: @dotnet/ncl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates HTTP telemetry to prioritize the Host
header when emitting the server.address
tag for both metrics and tracing, and adds tests to verify the new behavior.
- Introduces
HttpUtilities.ParseHostNameFromHeader
andDiagnosticsHelper.GetServerAddress
to centralize Host header parsing and selection logic. - Updates
MetricsHandler
,DiagnosticsHandler
, and connection pool/tracing components to use the new server address selection logic. - Adds functional tests in
MetricsTest.cs
andDiagnosticsTests.cs
to ensureserver.address
reflects the Host header when no proxy is used.
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
SocketsHttpHandler.cs | Passed IWebProxy into MetricsHandler and DiagnosticsHandler constructors |
SocketsHttpHandlerMetrics.cs | Changed server.address tag to use pool.TelemetryServerAddress |
HttpConnectionPoolManager.cs | Extracted ParseHostNameFromHeader into HttpUtilities |
HttpConnectionPool.cs | Added _telemetryServerAddress field and constructor parameter |
HttpConnectionBase.cs | Updated to emit TelemetryServerAddress for established connections |
HttpConnectionPool.Http3.cs | Updated tracing call to use _telemetryServerAddress |
ConnectionSetupDistributedTracing.cs | Changed StartConnectionSetupActivity to accept explicit host/port |
MetricsHandler.cs | Updated to use DiagnosticsHelper.GetServerAddress for server.address |
DiagnosticsHelper.cs | Added GetServerAddress to prefer Host header when no proxy |
DiagnosticsHandler.cs | Updated diagnostics tags to use DiagnosticsHelper.GetServerAddress |
HttpClientHandler.cs and AnyMobile variant | Passed proxy: null to new handler constructors |
HttpUtilities.cs and HttpUtilities.SocketsHttpHandler.cs | Introduced and wired up the partial class for header parsing |
System.Net.Http.csproj | Added new HttpUtilities.cs and updated the SocketsHttpHandler include |
MetricsTest.cs | New tests verifying that server.address comes from Host header |
DiagnosticsTests.cs | New tests verifying tracing tags reflect Host header |
.../System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHelper.cs
Outdated
Show resolved
Hide resolved
...p/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/ConnectionSetupDistributedTracing.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question, otherwise LGTM, thanks.
/ba-g The Microsoft.CSharp.RuntimeBinder.Tests failures are not related to the change |
@MihaZupan PTAL in case you have time, otherwise I will just |
...ibraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs
Outdated
Show resolved
Hide resolved
/ba-g CI timeouts are unrelated to the change |
Fixes #117049
With the merge of open-telemetry/semantic-conventions#2463, we are good to prioritize the contents of the
Host
header in cases no proxy is being used. The PR implements the change for both request and connection traces+metrics.There is a non-negligible risk: actually, we do not and (with the current code structure) can not emit
network.peer.address
for request telemetry, meaning that withhttp(s)://x.x.x.x/..
target Uri-s, IP information will be no longer present when a there is a Host header. I believe that most users would still prefer to see the contents of the Host header if there is a mismatch. Others can opt into connection metrics/traces wherenetwork.peer.address
is available.