-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Extend SocketsHttpHandler Connection and Request telemetry #88853
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
Changes from 1 commit
4409013
e8dfe2b
2c5136c
bb85d16
cdca548
80353d0
e4e88e2
bf5d1a7
d6ac30f
68a9e74
8a3fa5f
e2d86be
36e30df
066391d
91c54ed
0fa803e
86006f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,16 +91,16 @@ private void RequestFailed(string exceptionMessage) | |
| } | ||
|
|
||
| [NonEvent] | ||
| private void ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, Uri uri, IPEndPoint? remoteEndPoint) | ||
| private void ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, string scheme, string host, int port, IPEndPoint? remoteEndPoint) | ||
| { | ||
| string? remoteAddress = remoteEndPoint?.Address?.ToString(); | ||
| ConnectionEstablished(versionMajor, versionMinor, connectionId, uri.Scheme, uri.Host, uri.Port, remoteAddress); | ||
| string? socketAddress = remoteEndPoint?.Address?.ToString(); | ||
| ConnectionEstablished(versionMajor, versionMinor, connectionId, scheme, host, port, socketAddress); | ||
| } | ||
|
|
||
| [Event(4, Level = EventLevel.Informational)] | ||
| private void ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, string scheme, string host, int port, string? remoteAddress) | ||
| private void ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, string scheme, string host, int port, string? socketAddress) | ||
|
||
| { | ||
| WriteEvent(eventId: 4, versionMajor, versionMinor, connectionId, scheme, host, port, remoteAddress); | ||
| WriteEvent(eventId: 4, versionMajor, versionMinor, connectionId, scheme, host, port, socketAddress); | ||
| } | ||
|
|
||
| [Event(5, Level = EventLevel.Informational)] | ||
|
|
@@ -176,10 +176,10 @@ public void Redirect(string redirectUri) | |
| } | ||
|
|
||
| [NonEvent] | ||
| public void Http11ConnectionEstablished(long connectionId, Uri uri, IPEndPoint? remoteEndPoint) | ||
| public void Http11ConnectionEstablished(long connectionId, string scheme, string host, int port, IPEndPoint? remoteEndPoint) | ||
| { | ||
| Interlocked.Increment(ref _openedHttp11Connections); | ||
| ConnectionEstablished(versionMajor: 1, versionMinor: 1, connectionId, uri, remoteEndPoint); | ||
| ConnectionEstablished(versionMajor: 1, versionMinor: 1, connectionId, scheme, host, port, remoteEndPoint); | ||
| } | ||
|
|
||
| [NonEvent] | ||
|
|
@@ -191,10 +191,10 @@ public void Http11ConnectionClosed(long connectionId) | |
| } | ||
|
|
||
| [NonEvent] | ||
| public void Http20ConnectionEstablished(long connectionId, Uri uri, IPEndPoint? remoteEndPoint) | ||
| public void Http20ConnectionEstablished(long connectionId, string scheme, string host, int port, IPEndPoint? remoteEndPoint) | ||
| { | ||
| Interlocked.Increment(ref _openedHttp20Connections); | ||
| ConnectionEstablished(versionMajor: 2, versionMinor: 0, connectionId, uri, remoteEndPoint); | ||
| ConnectionEstablished(versionMajor: 2, versionMinor: 0, connectionId, scheme, host, port, remoteEndPoint); | ||
| } | ||
|
|
||
| [NonEvent] | ||
|
|
@@ -206,10 +206,10 @@ public void Http20ConnectionClosed(long connectionId) | |
| } | ||
|
|
||
| [NonEvent] | ||
| public void Http30ConnectionEstablished(long connectionId, Uri uri, IPEndPoint? remoteEndPoint) | ||
| public void Http30ConnectionEstablished(long connectionId, string scheme, string host, int port, IPEndPoint? remoteEndPoint) | ||
| { | ||
| Interlocked.Increment(ref _openedHttp30Connections); | ||
| ConnectionEstablished(versionMajor: 3, versionMinor: 0, connectionId, uri, remoteEndPoint); | ||
| ConnectionEstablished(versionMajor: 3, versionMinor: 0, connectionId, scheme, host, port, remoteEndPoint); | ||
| } | ||
|
|
||
| [NonEvent] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| using System.IO; | ||
| using System.Net.Http.Headers; | ||
| using System.Net.Http.HPack; | ||
| using System.Net.Http.Metrics; | ||
| using System.Net.Http.QPack; | ||
| using System.Net.Quic; | ||
| using System.Net.Security; | ||
|
|
@@ -955,7 +956,6 @@ private async ValueTask<Http3Connection> GetHttp3ConnectionAsync(HttpRequestMess | |
| #endif | ||
| // if the authority was sent as an option through alt-svc then include alt-used header | ||
| http3Connection = new Http3Connection(this, authority, quicConnection, includeAltUsedHeader: _http3Authority == authority); | ||
| http3Connection = new Http3Connection(this, _originAuthority, authority, quicConnection, request.RequestUri, includeAltUsedHeader: _http3Authority == authority); | ||
| _http3Connection = http3Connection; | ||
|
|
||
| if (NetEventSource.Log.IsEnabled()) | ||
|
|
@@ -1544,11 +1544,8 @@ public ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool | |
| case HttpConnectionKind.Https: | ||
| case HttpConnectionKind.ProxyConnect: | ||
| stream = await ConnectToTcpHostAsync(_originAuthority.IdnHost, _originAuthority.Port, request, async, cancellationToken).ConfigureAwait(false); | ||
| if (HttpTelemetry.Log.IsEnabled()) | ||
| { | ||
| // remoteEndPoint is returned optionally for diagnostic purposes. | ||
| remoteEndPoint = GetRemoteEndPoint(stream); | ||
| } | ||
| // remoteEndPoint is returned for diagnostic purposes. | ||
| remoteEndPoint = GetRemoteEndPoint(stream); | ||
| if (_kind == HttpConnectionKind.ProxyConnect && _sslOptionsProxy != null) | ||
| { | ||
| stream = await ConnectHelper.EstablishSslConnectionAsync(_sslOptionsProxy, request, async, stream, cancellationToken).ConfigureAwait(false); | ||
|
|
@@ -1557,11 +1554,8 @@ public ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool | |
|
|
||
| case HttpConnectionKind.Proxy: | ||
| stream = await ConnectToTcpHostAsync(_proxyUri!.IdnHost, _proxyUri.Port, request, async, cancellationToken).ConfigureAwait(false); | ||
| if (HttpTelemetry.Log.IsEnabled()) | ||
| { | ||
| // remoteEndPoint is returned optionally for diagnostic purposes. | ||
| remoteEndPoint = GetRemoteEndPoint(stream); | ||
| } | ||
| // remoteEndPoint is returned for diagnostic purposes. | ||
| remoteEndPoint = GetRemoteEndPoint(stream); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm no longer checking for any telemetry || metrics being enabled here, since |
||
| if (_sslOptionsProxy != null) | ||
| { | ||
| stream = await ConnectHelper.EstablishSslConnectionAsync(_sslOptionsProxy, request, async, stream, cancellationToken).ConfigureAwait(false); | ||
|
|
@@ -1735,16 +1729,14 @@ private async ValueTask<Stream> ApplyPlaintextFilterAsync(bool async, Stream str | |
| private async ValueTask<HttpConnection> ConstructHttp11ConnectionAsync(bool async, Stream stream, TransportContext? transportContext, HttpRequestMessage request, IPEndPoint? remoteEndPoint, CancellationToken cancellationToken) | ||
| { | ||
| Stream newStream = await ApplyPlaintextFilterAsync(async, stream, HttpVersion.Version11, request, cancellationToken).ConfigureAwait(false); | ||
| Debug.Assert(request.RequestUri != null); | ||
| return new HttpConnection(this, newStream, transportContext, request.RequestUri, remoteEndPoint); | ||
| return new HttpConnection(this, newStream, transportContext, remoteEndPoint); | ||
| } | ||
|
|
||
| private async ValueTask<Http2Connection> ConstructHttp2ConnectionAsync(Stream stream, HttpRequestMessage request, IPEndPoint? remoteEndPoint, CancellationToken cancellationToken) | ||
| { | ||
| stream = await ApplyPlaintextFilterAsync(async: true, stream, HttpVersion.Version20, request, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| Debug.Assert(request.RequestUri != null); | ||
| Http2Connection http2Connection = new Http2Connection(this, stream, request.RequestUri, remoteEndPoint); | ||
| Http2Connection http2Connection = new Http2Connection(this, stream, remoteEndPoint); | ||
| try | ||
| { | ||
| await http2Connection.SetupAsync(cancellationToken).ConfigureAwait(false); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,10 @@ internal sealed class ConnectionMetrics | |
| private readonly object _schemeTag; | ||
| private readonly object _hostTag; | ||
| private readonly object? _portTag; | ||
| private readonly string? _socketAddress; | ||
| private bool _currentlyIdle; | ||
|
|
||
| public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocol, string scheme, string host, int? port) | ||
| public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocol, string scheme, string host, int? port, string? socketAddress) | ||
| { | ||
| _metrics = metrics; | ||
| _currentConnectionsEnabled = _metrics.CurrentConnections.Enabled; | ||
|
|
@@ -25,6 +26,7 @@ public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocol, str | |
| _schemeTag = scheme; | ||
| _hostTag = host; | ||
| _portTag = port; | ||
| _socketAddress = socketAddress; | ||
| } | ||
|
|
||
| // TagList is a huge struct, so we avoid storing it in a field to reduce the amount we allocate on the heap. | ||
|
|
@@ -41,6 +43,11 @@ private TagList GetTags() | |
| tags.Add("port", _portTag); | ||
| } | ||
|
|
||
| if (_socketAddress is not null) | ||
| { | ||
| tags.Add("socket.address", _socketAddress); | ||
| } | ||
|
||
|
|
||
| return tags; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.