Skip to content

Conversation

antonfirsov
Copy link
Member

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 with http(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 where network.peer.address is available.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a 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 and DiagnosticsHelper.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 and DiagnosticsTests.cs to ensure server.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

Copy link
Member

@ManickaP ManickaP left a 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.

@antonfirsov
Copy link
Member Author

HTTP test failures are unrelated (#117484, #116695).

@antonfirsov
Copy link
Member Author

/ba-g The Microsoft.CSharp.RuntimeBinder.Tests failures are not related to the change

@antonfirsov antonfirsov requested a review from MihaZupan July 16, 2025 22:09
@antonfirsov
Copy link
Member Author

@MihaZupan PTAL in case you have time, otherwise I will just :shipit:

@antonfirsov
Copy link
Member Author

/ba-g CI timeouts are unrelated to the change

@antonfirsov antonfirsov merged commit a3f500f into dotnet:main Jul 18, 2025
81 of 87 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should the server.address tag in the HttpClient metric counters incorporate the Host header of the request?
4 participants