Skip to content

Implement IConnectionEndPointFeature in Kestrel, HttpSys, and IIS#62162

Merged
BrennanConroy merged 16 commits into
mainfrom
copilot/fix-43786
Apr 15, 2026
Merged

Implement IConnectionEndPointFeature in Kestrel, HttpSys, and IIS#62162
BrennanConroy merged 16 commits into
mainfrom
copilot/fix-43786

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2025

Implements IConnectionEndPointFeature across multiple server implementations (Kestrel, HttpSys, and IIS), refactors connection endpoint tagging into a shared utility, and extends the feature to SignalR via HttpConnectionDispatcher.

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

IConnectionEndPointFeature was previously only implemented in DefaultConnectionContext, which is primarily used in tests. This PR makes the feature available in production connections across Kestrel, HttpSys, and IIS, and consolidates endpoint tag logic into a shared utility.

Changes

  1. TransportConnection and TransportMultiplexedConnection — Added IConnectionEndPointFeature support by updating the code generation configuration, regenerating the feature collection code, and implementing interface methods that delegate to the existing LocalEndPoint and RemoteEndPoint properties. This covers both regular TCP connections (HTTP/1.x, HTTP/2) and multiplexed QUIC connections (HTTP/3).

  2. HttpSys (RequestContext + StandardFeatureCollection) — Added IConnectionEndPointFeature to the RequestContext partial class and StandardFeatureCollection feature lookup. The implementation constructs IPEndPoint on demand from the existing lazy-initialized IHttpConnectionFeature properties (LocalIpAddress/LocalPort and RemoteIpAddress/RemotePort).

  3. IIS (IISHttpContext) — Added IConnectionEndPointFeature to IISHttpContext, including the full fast-path feature lookup support in Features.cs (static type field, backing field, Initialize(), FastFeatureGet, FastFeatureSet, and FastEnumerable). The implementation also delegates to the existing IHttpConnectionFeature properties.

  4. src/Shared/ConnectionEndpointTags.cs (new shared file, Microsoft.AspNetCore.Shared namespace) — Extracted the connection endpoint tag logic from KestrelMetrics.cs into a shared internal utility using IConnectionEndPointFeature. Exposes two overloads:

    • AddConnectionEndpointTags(ref TagList, IFeatureCollection) — used by SignalR; records transport as TCP and does not attempt QUIC detection
    • AddConnectionEndpointTags(ref TagList, BaseConnectionContext) — used by Kestrel metrics; includes QUIC/TCP detection via MultiplexedConnectionContext

    A private AddEndpointTags helper eliminates duplication between overloads. Tags follow OTel semantic conventions (server.address, server.port as int, network.type, network.transport).

  5. KestrelMetrics.cs — Updated InitializeConnectionTags to delegate to the shared utility.

  6. DefaultHubDispatcher.cs — Updated StartActivity to include connection endpoint tags in SignalR hub method activities.

  7. HttpConnectionDispatcher — Added propagation of IConnectionEndPointFeature from the incoming HttpContext to the SignalR connection (alongside the existing IHttpConnectionFeature propagation), ensuring real LocalEndPoint/RemoteEndPoint values from Kestrel/HttpSys/IIS are available for telemetry. HttpConnectionContext no longer implements IConnectionEndPointFeature itself — the real endpoint feature from the underlying server is forwarded instead.

  8. Tests:

    • TransportConnectionFeatureCollectionTests.cs — Verifies IConnectionEndPointFeature is present in the feature collection and correctly returns/sets LocalEndPoint and RemoteEndPoint for both TransportConnection and TransportMultiplexedConnection.
    • HubConnectionHandlerTests.Activity.cs — Verifies that SignalR hub activities include server.address, server.port, network.type, and network.transport tags when endpoint information is available. Note: server.port is stored as int per OTel conventions and must be checked via Activity.TagObjects rather than Activity.Tags.
    • HttpSys/test/FunctionalTests/ConnectionEndPointFeatureTests.cs — Smoke test verifying that IConnectionEndPointFeature is available from httpContext.Features in an in-process HttpSys server and returns non-null IPEndPoint instances for both LocalEndPoint and RemoteEndPoint.
    • IIS/IIS/test/IIS.Tests/ConnectionEndPointFeatureTests.cs — Smoke test verifying that IConnectionEndPointFeature is available from ctx.Features in an in-process IIS test server and returns non-null IPEndPoint instances for both LocalEndPoint and RemoteEndPoint.
    • HubConnectionTests.Tracing.cs — E2E functional test (InvokeAsync_ServerActivityIncludesConnectionEndpointTags) using a real Kestrel-backed server that verifies server-side SignalR activities include server.address, server.port, network.type, and network.transport tags across all hub protocol/transport/path combinations.

Usage

var endpointFeature = connectionContext.Features.Get<IConnectionEndPointFeature>();
var localEndpoint = endpointFeature?.LocalEndPoint;
var remoteEndpoint = endpointFeature?.RemoteEndPoint;

Notes

  • No breaking changes; existing code using direct LocalEndPoint/RemoteEndPoint properties continues to work.
  • Activity.Tags only enumerates string-valued tags. Integer-valued tags such as server.port are only accessible via Activity.TagObjects.
  • ConnectionEndpointTags is placed in the Microsoft.AspNetCore.Shared namespace, consistent with other shared utilities in src/Shared/.

Fixes #43786

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copilot AI changed the title [WIP] What are we doing with IConnectionEndPointFeature Implement IConnectionEndPointFeature in Kestrel's TransportConnection May 29, 2025
Copilot AI requested a review from BrennanConroy May 29, 2025 20:43
@BrennanConroy
Copy link
Copy Markdown
Member

Looking good, can you add a test that verifies the feature is in the feature collection and has values?

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 30, 2025

Looking good, can you add a test that verifies the feature is in the feature collection and has values?

Added comprehensive tests in TransportConnectionFeatureCollectionTests.cs that verify IConnectionEndPointFeature is available in the feature collection and properly returns/sets endpoint values. The tests follow existing patterns and validate both getting and setting LocalEndPoint and RemoteEndPoint through the feature interface. (dbd9f49)

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

If you need me to access, download, or install something from one of these locations, you can either:

@BrennanConroy
Copy link
Copy Markdown
Member

Can you refactor https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelMetrics.cs#L322 to use the IConnectionEndPointFeature and put it in the src/Shared/ folder. Then update SignalR to use the shared code; see

// See https://github.com/dotnet/aspnetcore/blob/027c60168383421750f01e427e4f749d0684bc02/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelMetrics.cs#L308

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 7, 2025

Can you refactor https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelMetrics.cs#L322 to use the IConnectionEndPointFeature and put it in the sr...

Refactored the connection endpoint logic into a shared utility in src/Shared/ConnectionEndpointTags.cs that uses IConnectionEndPointFeature. Updated KestrelMetrics.cs to use the shared code and modified SignalR's DefaultHubDispatcher to include endpoint tags via the same shared utility. The SignalR server.address tag is now uncommented and working. (6c1244f)

@BrennanConroy
Copy link
Copy Markdown
Member

Looks like there is a test failure:

Error: The given key 'network.type' was not present in the dictionary.
Stack Trace:
at System.Collections.Generic.Dictionary2.get_Item(TKey key) /_/src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs(106,0): at Interop.FunctionalTests.Http3.Http3RequestTests.<>c__DisplayClass2_0.<GET_Metrics_HttpProtocolAndTlsSet>b__1(CollectedMeasurement1 m)

Wonder if Http3 connections implement the feature collection differently

…ion for HTTP/3

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 9, 2025

Looks like there is a test failure:

Error: The given key 'network.type' was not present in the dictionary.
Stack Trace:
...

Fixed the HTTP/3 test failure by adding IConnectionEndPointFeature support to TransportMultiplexedConnection. HTTP/3 connections use MultiplexedConnectionContext instead of regular TransportConnection, so the feature wasn't available. Added feature configuration, updated generated code, and improved shared utility with fallback logic. (45fbce8)

@BrennanConroy
Copy link
Copy Markdown
Member

Looks like the test fix worked, thanks! Can you add a test for the SignalR part now? I imagine we might need to add the IConnectionEndPointFeature to HttpConnectionContext.

…ignalR endpoint tags test

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 9, 2025

Looks like the test fix worked, thanks! Can you add a test for the SignalR part now? I imagine we might need to add the IConnectionEndPointFeature to HttpConnectionContext.

Added IConnectionEndPointFeature implementation to HttpConnectionContext and a comprehensive test that verifies SignalR activities include endpoint tags. The test validates server.address, server.port, network.type, and network.transport tags are properly added to both connect and disconnect activities. (630a05c)

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 5, 2026

@copilot undo the change to the submodule, and is it possible to implement the feature in httpsys and iis?

Done in 93ed79f:

  1. Submodule reverted - restored src/submodules/googletest to d72f9c8a (main's version), undoing the accidental change from af13f19f.

  2. HttpSys - added IConnectionEndPointFeature to RequestContext (interface declaration + implementation that constructs IPEndPoint from the existing lazy-initialized IHttpConnectionFeature properties) and to StandardFeatureCollection._featureFuncLookup.

  3. IIS - added IConnectionEndPointFeature to IISHttpContext (interface declaration in FeatureCollection.cs, implementation using IHttpConnectionFeature properties, and full fast-path FastFeatureGet/FastFeatureSet/FastEnumerable support in Features.cs).

Copilot AI changed the title Implement IConnectionEndPointFeature in Kestrel's TransportConnection Implement IConnectionEndPointFeature in Kestrel, HttpSys, and IIS Apr 5, 2026
@BrennanConroy
Copy link
Copy Markdown
Member

@copilot add a couple smoke tests for this in iis and httpsys. Looks like there might be a couple tests using IHttpConnectionFeature, so can use those for inspiration.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 6, 2026

@copilot add a couple smoke tests for this in iis and httpsys. Looks like there might be a couple tests using IHttpConnectionFeature, so can use those for inspiration.

Added smoke tests in 49c4fd8:

  • HttpSys (src/Servers/HttpSys/test/FunctionalTests/ConnectionEndPointFeatureTests.cs): Request_ProvidesConnectionEndPointFeature — starts an in-process HttpSys server, retrieves IConnectionEndPointFeature from httpContext.Features, and asserts both LocalEndPoint and RemoteEndPoint are non-null IPEndPoint instances with non-zero ports.

  • IIS (src/Servers/IIS/IIS/test/IIS.Tests/ConnectionEndPointFeatureTests.cs): ProvidesLocalAndRemoteEndPoints — follows the same pattern as ConnectionIdFeatureTests, using TestServer.Create to retrieve IConnectionEndPointFeature and assert both endpoints are non-null IPEndPoint instances.

@BrennanConroy BrennanConroy marked this pull request as ready for review April 10, 2026 01:03
@BrennanConroy BrennanConroy requested a review from halter73 as a code owner April 10, 2026 01:03
Copilot AI review requested due to automatic review settings April 10, 2026 01:03
Copy link
Copy Markdown
Contributor

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

Adds production-server support for IConnectionEndPointFeature (Kestrel, HttpSys, IIS) and centralizes OTel connection endpoint tagging so SignalR and Kestrel metrics can attach consistent server.* / network.* tags.

Changes:

  • Implement/enable IConnectionEndPointFeature in Kestrel transport connections, HttpSys RequestContext, and IIS IISHttpContext feature collections.
  • Introduce shared ConnectionEndpointTags helper and wire it into Kestrel metrics + SignalR activities.
  • Add coverage tests across Kestrel, HttpSys, IIS, and SignalR activity tagging.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/SignalR/server/SignalR/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.Activity.cs Adds an activity-tagging test validating endpoint/network tags on hub activities.
src/SignalR/server/Core/src/Microsoft.AspNetCore.SignalR.Core.csproj Links the new shared ConnectionEndpointTags.cs into SignalR Core.
src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs Extends StartActivity to add endpoint tags when a connection is available.
src/SignalR/common/Http.Connections/src/Microsoft.AspNetCore.Http.Connections.csproj Links the new shared ConnectionEndpointTags.cs into Http.Connections.
src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs Registers IConnectionEndPointFeature on SignalR HttpConnectionContext.
src/Shared/ConnectionEndpointTags.cs New shared utility to add server.address, server.port, network.type, network.transport tags.
src/Servers/Kestrel/tools/CodeGenerator/TransportMultiplexedConnectionFeatureCollection.cs Updates codegen configuration to include IConnectionEndPointFeature for multiplexed connections.
src/Servers/Kestrel/tools/CodeGenerator/TransportConnectionFeatureCollection.cs Updates codegen configuration to include IConnectionEndPointFeature for transport connections.
src/Servers/Kestrel/shared/TransportMultiplexedConnection.Generated.cs Regenerated feature collection plumbing to support IConnectionEndPointFeature.
src/Servers/Kestrel/shared/TransportMultiplexedConnection.FeatureCollection.cs Implements IConnectionEndPointFeature by delegating to LocalEndPoint/RemoteEndPoint.
src/Servers/Kestrel/shared/TransportConnection.Generated.cs Regenerated feature collection plumbing to support IConnectionEndPointFeature.
src/Servers/Kestrel/shared/TransportConnection.FeatureCollection.cs Implements IConnectionEndPointFeature by delegating to LocalEndPoint/RemoteEndPoint.
src/Servers/Kestrel/Core/test/TransportConnectionFeatureCollectionTests.cs New tests validating presence and get/set behavior of IConnectionEndPointFeature.
src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj Links the new shared ConnectionEndpointTags.cs into Kestrel Core.
src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelMetrics.cs Replaces inline endpoint-tag logic with the shared helper.
src/Servers/IIS/IIS/test/IIS.Tests/ConnectionEndPointFeatureTests.cs Adds IIS functional smoke test for IConnectionEndPointFeature.
src/Servers/IIS/IIS/src/Core/IISHttpContext.Features.cs Adds fast-path feature lookup plumbing for IConnectionEndPointFeature.
src/Servers/IIS/IIS/src/Core/IISHttpContext.FeatureCollection.cs Implements IConnectionEndPointFeature on IIS via IHttpConnectionFeature values.
src/Servers/HttpSys/test/FunctionalTests/ConnectionEndPointFeatureTests.cs Adds HttpSys functional smoke test for IConnectionEndPointFeature.
src/Servers/HttpSys/src/StandardFeatureCollection.cs Registers IConnectionEndPointFeature in HttpSys standard feature lookup.
src/Servers/HttpSys/src/RequestProcessing/RequestContext.FeatureCollection.cs Implements IConnectionEndPointFeature on RequestContext via IHttpConnectionFeature values.

Comment thread src/Shared/ConnectionEndpointTags.cs Outdated
Comment thread src/Shared/ConnectionEndpointTags.cs
Comment thread src/Servers/IIS/IIS/src/Core/IISHttpContext.Features.cs Outdated
@BrennanConroy
Copy link
Copy Markdown
Member

@copilot react to the feedback above. Also, the SignalR change doesn't look like it would work outside of the test. It never sets the RemoteEndpoint or LocalEndpoint. Maybe it should be grabbing the IConnectionEndPointFeature from the HttpContext. For example, see connection.Features.Set(context.Features.Get<IHttpConnectionFeature>()); in HttpConnectionDispatcher. And we might want an E2E test in SignalR verifying the activities if possible.

…, E2E test

Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/70229d9d-6fe0-4d78-808d-3d63d8e637d6

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot react to the feedback above. Also, the SignalR change doesn't look like it would work outside of the test. It never sets the RemoteEndpoint or LocalEndpoint. Maybe it should be grabbing the `...

Addressed all feedback in 1358d26:

  1. Code review comments:

    • Added namespace Microsoft.AspNetCore.Shared; to ConnectionEndpointTags.cs and updated KestrelMetrics.cs to add using Microsoft.AspNetCore.Shared;
    • Fixed the misleading QUIC comment in the IFeatureCollection overload — it now says "does not attempt to infer whether the underlying transport is multiplexed or QUIC"
    • Renamed IConnectionEndPointFeatureTypeIConnectionEndPointFeature in IISHttpContext.Features.cs for consistency with the adjacent IConnectionLifetimeNotificationFeature pattern
  2. SignalR fix: Added connection.Features.Set(context.Features.Get<IConnectionEndPointFeature>()) in HttpConnectionDispatcher.ExecuteAsync right after the existing IHttpConnectionFeature propagation. This ensures that real connection endpoint information (from Kestrel/HttpSys/IIS) is available via IConnectionEndPointFeature on the SignalR connection.

  3. E2E test: Added InvokeAsync_ServerActivityIncludesConnectionEndpointTags to HubConnectionTests.Tracing.cs — uses StartServer<Startup>() (a real Kestrel-backed server) with all hub protocols/transport combinations and verifies server-side SignalR activities include server.address, server.port, network.type, and network.transport tags (24 passing test cases).

Comment thread src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs Outdated
…her provides it

Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/ab2d00c7-775a-4e62-90a6-24cf17db6af3

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@BrennanConroy BrennanConroy merged commit 71f7a4d into main Apr 15, 2026
24 checks passed
@BrennanConroy BrennanConroy deleted the copilot/fix-43786 branch April 15, 2026 21:36
@dotnet-policy-service dotnet-policy-service Bot added this to the 11.0-preview4 milestone Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Attention: Shared Code Modified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

What are we doing with IConnectionEndPointFeature

4 participants