[HTTP Telemetry] Prioritize Host header when emitting server.address#117540
Merged
antonfirsov merged 5 commits intodotnet:mainfrom Jul 18, 2025
Merged
[HTTP Telemetry] Prioritize Host header when emitting server.address#117540antonfirsov merged 5 commits intodotnet:mainfrom
server.address#117540antonfirsov merged 5 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/ncl |
Contributor
There was a problem hiding this comment.
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.ParseHostNameFromHeaderandDiagnosticsHelper.GetServerAddressto 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.csandDiagnosticsTests.csto ensureserver.addressreflects 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
antonfirsov
commented
Jul 11, 2025
...p/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/ConnectionSetupDistributedTracing.cs
Show resolved
Hide resolved
This was referenced Jul 11, 2025
ManickaP
approved these changes
Jul 16, 2025
Member
ManickaP
left a comment
There was a problem hiding this comment.
One question, otherwise LGTM, thanks.
Contributor
Author
Contributor
Author
|
/ba-g The Microsoft.CSharp.RuntimeBinder.Tests failures are not related to the change |
Contributor
Author
|
@MihaZupan PTAL in case you have time, otherwise I will just |
MihaZupan
reviewed
Jul 17, 2025
...ibraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs
Outdated
Show resolved
Hide resolved
MihaZupan
reviewed
Jul 17, 2025
Open
3 tasks
Contributor
Author
|
/ba-g CI timeouts are unrelated to the change |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #117049
With the merge of open-telemetry/semantic-conventions#2463, we are good to prioritize the contents of the
Hostheader 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.addressfor 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.addressis available.