Skip to content

Extend SocketsHttpHandler Connection and Request telemetry - #88853

Merged
antonfirsov merged 17 commits into
dotnet:mainfrom
antonfirsov:extend-request-telemetry-01
Jul 18, 2023
Merged

Extend SocketsHttpHandler Connection and Request telemetry#88853
antonfirsov merged 17 commits into
dotnet:mainfrom
antonfirsov:extend-request-telemetry-01

Conversation

@antonfirsov

@antonfirsovantonfirsov commented Jul 13, 2023

Copy link
Copy Markdown
Contributor

Fixes#63159, fixes#85729.

Add the telemetry events proposed in #85729 and #63159 (comment), with a difference that we log remoteAddress instead of remoteEndPoint since port is already logged as a separate parameter.

I think the changes will not prevent us from implementing #66223, since we can move the logging out of connection constructors.

Full event diff:

- ConnectionEstablished(byte versionMajor, byte versionMinor)+ ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, string scheme, string host, int port, string? remoteAddress)- ConnectionClosed(byte versionMajor, byte versionMinor)+ ConnectionClosed(byte versionMajor, byte versionMinor, long connectionId)- RequestHeadersStart()+ RequestHeadersStart(long connectionId)-void Redirect();+void Redirect(string redirectUri);

@ghost

Copy link
Copy Markdown

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

Issue Details

Fixes #63159, fixes #85729.

Add the telemetry events proposed in #85729 and #63159 (comment), with a difference that we log remoteAddress instead of remoteEndPoint since port is already logged as a separate parameter.

I think the changes will not prevent us from implementing #66223, since we can move the logging out of connection constructors.

Full event diff:

- ConnectionEstablished(byte versionMajor, byte versionMinor)+ ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, string scheme, string host, int port, string? remoteAddress)- ConnectionClosed(byte versionMajor, byte versionMinor)+ ConnectionClosed(byte versionMajor, byte versionMinor, long connectionId)- RequestHeadersStart()+ RequestHeadersStart(long connectionId)-void Redirect();+void Redirect(string redirectUri);
Author:antonfirsov
Assignees:-
Labels:

area-System.Net.Http

Milestone:-

@antonfirsov

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

azure-pipelinesBot commented Jul 13, 2023

Copy link
Copy Markdown

🤡 No commit pushedDate could be found for PR 88853 in repo dotnet/runtime 🤡

@antonfirsov

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment threadsrc/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs Outdated
Comment threadsrc/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs Outdated
@MihaZupanMihaZupan added this to the 8.0.0 milestone Jul 14, 2023
@antonfirsov

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@antonfirsovantonfirsov left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +46 to +49
if (_socketAddress is not null)
{
tags.Add("socket.address", _socketAddress);
}

@antonfirsovantonfirsovJul 16, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: Reverted this to simplify Metrics naming discussions. If this is interesting enough to be added after platform complete, we can do it in a follow-up PR.

Given it's available, it looks like it makes make sense to log this also on connection metrics, unless we think it's sensitive info. With the name I'm following OTel recommendation proactively using dot notation with the assumption that we will also change the instrument names by midnight of the 17th.

@davidfowl@noahfalk any objections?

case HttpConnectionKind.Proxy:
stream = await ConnectToTcpHostAsync(_proxyUri!.IdnHost, _proxyUri.Port, request, async, cancellationToken).ConfigureAwait(false);
// remoteEndPoint is returned for diagnostic purposes.
remoteEndPoint = GetRemoteEndPoint(stream);

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The 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 GetRemoteEndpoint is relatively cheap to run per-connection and likely almost as expensive as the check would be.

}

[Event(4, Level = EventLevel.Informational, Version = 1)]
private void ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, string scheme, string host, int port, string? socketAddress)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also going with the socketAddress name here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more generic remoteEndPoint may be better if we do decide to allow users to customize the string that is logged here (e.g. they give us a custom stream via ConnectCallback that may not be backed by a socket at all).

}

[Event(4, Level = EventLevel.Informational, Version = 1)]
private void ConnectionEstablished(byte versionMajor, byte versionMinor, long connectionId, string scheme, string host, int port, string? socketAddress)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more generic remoteEndPoint may be better if we do decide to allow users to customize the string that is logged here (e.g. they give us a custom stream via ConnectCallback that may not be backed by a socket at all).

@antonfirsov

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@dotnetdotnet deleted a comment from azure-pipelinesBotJul 17, 2023
@dotnetdotnet deleted a comment from azure-pipelinesBotJul 17, 2023
@antonfirsov

antonfirsov commented Jul 17, 2023

Copy link
Copy Markdown
ContributorAuthor

Since we know that (at least for now), a CONNECT request will be done over HTTP/1.1 without a TLS layer

Not since #87638. Anyways, I pushed detection of the address for the non TLS-case in 066391d, but not sure if turning this many privates to internal was worth the feature.

A more generic remoteEndPoint may be better

Switched back the name to remoteAddress. We will have a naming dilemma if we decide to implement this in metrics, since OTel recommends the name server.socket.address.

@antonfirsov

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@dotnetdotnet deleted a comment from azure-pipelinesBotJul 17, 2023
@dotnetdotnet deleted a comment from azure-pipelinesBotJul 17, 2023
@antonfirsov

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@dotnetdotnet deleted a comment from azure-pipelinesBotJul 17, 2023
@antonfirsov
antonfirsov merged commit 1db1ba4 into dotnet:mainJul 18, 2023
@ghostghost locked as resolved and limited conversation to collaborators Aug 17, 2023
Sign up for freeto 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.

Adding more information and events to System.Net.Http telemetry How to get the socket information from HttpClient request?

2 participants

@antonfirsov@MihaZupan