Implement IConnectionEndPointFeature in Kestrel, HttpSys, and IIS#62162
Implement IConnectionEndPointFeature in Kestrel, HttpSys, and IIS#62162
Conversation
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
IConnectionEndPointFeature|
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>
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 addressesI 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:
|
|
Can you refactor https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelMetrics.cs#L322 to use the |
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
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) |
|
Looks like there is a test failure:
Wonder if Http3 connections implement the feature collection differently |
…ion for HTTP/3 Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
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) |
|
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 |
…ignalR endpoint tags test Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
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) |
|
@copilot update the PR since it's been a while and the codebase has changed. Also double check the change to make sure it's good. |
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
…est compile errors Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/0a5a6edd-af5f-4fce-96d9-3d2ed8c69a2c Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Updated the PR:
|
|
@copilot undo the change to the submodule, and is it possible to implement the feature in httpsys and iis? |
Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/63be0905-83a8-4217-b93d-63c59108c821 Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Done in 93ed79f:
|
|
@copilot add a couple smoke tests for this in iis and httpsys. Looks like there might be a couple tests using |
Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/6555e55e-2ba8-4ee0-8af9-2a28cdf45b12 Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Added smoke tests in 49c4fd8:
|
There was a problem hiding this comment.
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
IConnectionEndPointFeaturein Kestrel transport connections, HttpSysRequestContext, and IISIISHttpContextfeature collections. - Introduce shared
ConnectionEndpointTagshelper 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. |
| var endPointFeature = httpContext.Features.Get<IConnectionEndPointFeature>(); | ||
| localEndPoint = endPointFeature.LocalEndPoint; | ||
| remoteEndPoint = endPointFeature.RemoteEndPoint; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); | ||
| httpContext.Response.Body.Write(body, 0, body.Length); | ||
| } | ||
| return Task.FromResult(0); |
There was a problem hiding this comment.
This test uses Exception and Task (catch (Exception ex) / Task.FromResult) but the file doesn’t import System / System.Threading.Tasks (and doesn’t fully qualify those types). This will fail to compile; add the missing using directives or fully qualify the types used in the callback.
| // There isn't an easy way to detect whether QUIC is the underlying transport from a feature collection alone. | ||
| // This code assumes that a multiplexed connection is QUIC. | ||
| // Improve in the future if there are additional multiplexed connection types. |
There was a problem hiding this comment.
The QUIC/multiplexed-transport comment here is misleading: this overload always passes networkTransport: "tcp", and it doesn’t attempt any QUIC detection. Please update/remove the comment (or adjust the logic) so the documented behavior matches the implementation.
| // There isn't an easy way to detect whether QUIC is the underlying transport from a feature collection alone. | |
| // This code assumes that a multiplexed connection is QUIC. | |
| // Improve in the future if there are additional multiplexed connection types. | |
| // This overload only has endpoint information from the feature collection and does not attempt | |
| // to infer whether the underlying transport is multiplexed or QUIC. For IP endpoints, it records | |
| // the transport as TCP. |
| using Microsoft.AspNetCore.Http.Features; | ||
|
|
||
| #nullable enable | ||
|
|
There was a problem hiding this comment.
This new shared utility is declared in the global namespace. In src/Shared, shared types are normally placed in an explicit namespace (e.g., Microsoft.AspNetCore.Shared in Diagnostics/ActivityCreator.cs), which helps avoid accidental collisions and keeps call sites consistent. Consider moving this type into an appropriate shared namespace and updating call sites accordingly.
| namespace Microsoft.AspNetCore.Shared; |
| private static readonly Type IHttpResponseTrailersFeature = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseTrailersFeature); | ||
| private static readonly Type IHttpResetFeature = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResetFeature); | ||
| private static readonly Type IConnectionLifetimeNotificationFeature = typeof(global::Microsoft.AspNetCore.Connections.Features.IConnectionLifetimeNotificationFeature); | ||
| private static readonly Type IConnectionEndPointFeatureType = typeof(global::Microsoft.AspNetCore.Connections.Features.IConnectionEndPointFeature); |
There was a problem hiding this comment.
Naming nit: the static Type field for the feature is IConnectionEndPointFeatureType, but the adjacent connection feature (IConnectionLifetimeNotificationFeature) doesn’t use the Type suffix. Consider renaming for consistency with the existing feature-type field naming in this file.
| private static readonly Type IConnectionEndPointFeatureType = typeof(global::Microsoft.AspNetCore.Connections.Features.IConnectionEndPointFeature); | |
| private static readonly Type IConnectionEndPointFeature = typeof(global::Microsoft.AspNetCore.Connections.Features.IConnectionEndPointFeature); |
Implements
IConnectionEndPointFeatureacross multiple server implementations (Kestrel, HttpSys, and IIS), refactors connection endpoint tagging into a shared utility, and extends the feature to SignalR'sHttpConnectionContext.Description
IConnectionEndPointFeaturewas previously only implemented inDefaultConnectionContext, 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
TransportConnectionandTransportMultiplexedConnection— AddedIConnectionEndPointFeaturesupport by updating the code generation configuration, regenerating the feature collection code, and implementing interface methods that delegate to the existingLocalEndPointandRemoteEndPointproperties. This covers both regular TCP connections (HTTP/1.x, HTTP/2) and multiplexed QUIC connections (HTTP/3).HttpSys(RequestContext+StandardFeatureCollection) — AddedIConnectionEndPointFeatureto theRequestContextpartial class andStandardFeatureCollectionfeature lookup. The implementation constructsIPEndPointon demand from the existing lazy-initializedIHttpConnectionFeatureproperties (LocalIpAddress/LocalPortandRemoteIpAddress/RemotePort).IIS(IISHttpContext) — AddedIConnectionEndPointFeaturetoIISHttpContext, including the full fast-path feature lookup support inFeatures.cs(static type field, backing field,Initialize(),FastFeatureGet,FastFeatureSet, andFastEnumerable). The implementation also delegates to the existingIHttpConnectionFeatureproperties.src/Shared/ConnectionEndpointTags.cs(new shared file) — Extracted the connection endpoint tag logic fromKestrelMetrics.csinto a shared internal utility usingIConnectionEndPointFeature. Exposes two overloads:AddConnectionEndpointTags(ref TagList, IFeatureCollection)— used by SignalRAddConnectionEndpointTags(ref TagList, BaseConnectionContext)— used by Kestrel metrics, includes QUIC/TCP detection viaMultiplexedConnectionContextA private
AddEndpointTagshelper eliminates duplication between overloads. Tags follow OTel semantic conventions (server.address,server.portasint,network.type,network.transport).KestrelMetrics.cs— UpdatedInitializeConnectionTagsto delegate to the shared utility.DefaultHubDispatcher.cs— UpdatedStartActivityto include connection endpoint tags in SignalR hub method activities.HttpConnectionContext— AddedIConnectionEndPointFeatureto the implemented interfaces list and registered it in the feature collection, making endpoint info accessible through the standard feature interface for SignalR connections.Tests:
TransportConnectionFeatureCollectionTests.cs— VerifiesIConnectionEndPointFeatureis present in the feature collection and correctly returns/setsLocalEndPointandRemoteEndPointfor bothTransportConnectionandTransportMultiplexedConnection.HubConnectionHandlerTests.Activity.cs— Verifies that SignalR hub activities includeserver.address,server.port,network.type, andnetwork.transporttags when endpoint information is available. Note:server.portis stored asintper OTel conventions and must be checked viaActivity.TagObjectsrather thanActivity.Tags.HttpSys/test/FunctionalTests/ConnectionEndPointFeatureTests.cs— Smoke test verifying thatIConnectionEndPointFeatureis available fromhttpContext.Featuresin an in-process HttpSys server and returns non-nullIPEndPointinstances for bothLocalEndPointandRemoteEndPoint.IIS/IIS/test/IIS.Tests/ConnectionEndPointFeatureTests.cs— Smoke test verifying thatIConnectionEndPointFeatureis available fromctx.Featuresin an in-process IIS test server and returns non-nullIPEndPointinstances for bothLocalEndPointandRemoteEndPoint.Usage
Notes
LocalEndPoint/RemoteEndPointproperties continues to work.Activity.Tagsonly enumerates string-valued tags. Integer-valued tags such asserver.portare only accessible viaActivity.TagObjects.