-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
proposal: net/http: Transport tracing hooks #56241
Comments
cc @neild |
This proposal is for two unrelated things: A way to run per-request trace hooks for every request on an You need to separate these parts. Do you want to propose a way to run We don't want to have two entirely different per-request tracing mechanisms. Any new tracing hooks need to fit in with what exists already. |
Correct, this proposal was to introduce trace hooks that would run for all request (and connection) activities on an So basically I want to propose a way to run But I guess it is not possible to replace httptrace with the new mechanism as it is a part of the go library. And adding the remaining new hooks with an entirely new mechanism would leave us with two different mechanisms as you mentioned. Parts of the proposal that still fits into what exists already are per-request hooks that can be added to
PS. This is not a part of this proposal but the above hooks would also enable us to track the request's waiting time in i) getting a connection, ii) idleConnWait, and iii) connsPerHostWait. This could be done by adding a field |
@neild do the features mentioned later which adhere to the existing httptrace look worth adding to the library? |
This proposal has been added to the active column of the proposals project |
@neild any thoughts on the most recent messages? |
A mechanism to run the existing The proposed new hooks ( It would be reasonable to provide more detailed tracing about connection lifetimes. I'd want to make sure that whatever trace events we support work for HTTP/1 and HTTP/2, as well as potentially HTTP/3 at some time in the future. Before making any significant changes to HTTP tracing, I'd want to understand how this might interact with structured logging. If #56345 is accepted, we'll probably want to consider adding structured logging events to |
In my opinion, the I spoke about this at the end of my Capital Go 2017 talk "Go Kit Log Package" |
ISTM they are not entirely orthogonal. Tracing accumulates structure, while logging takes a snapshot of structure, but the snapshot might not be computed at one precise moment in time and #56345 is amenable to a few different ways of doing things here - there are tradeoffs. |
Suggestion is to put this on hold for structured logging because the trace messages themselves will be structured. |
Placed on hold. |
The current HTTP client instrumentation library httptrace tracks the life cycle of a single request with hooks present at different stages in the outgoing HTTP Request's journey. This limits the use of
httptrace
in many ways which we believe could be solved by having an instrumentation library which works at a “transport level”. This means instead of placing hooks in the request’s context, one defines these hooks for theTransport
. This would also support the current functionality ofhttptrace
.Proposal
Here is a basic example of the proposed change. Let’s take the example of the
GotConn
hook inhttptrace.ClientTrace
. The current method for adding and using this hook isWe propose restructuring
http.Transport
to contain the hooks instead ofClientTrace
.Transport
contains a new structStats
which contains the hooks and other data like counts of idle/active connections and waiting requests.And one would make a request in the following way:-
Within
Transport
, when a request has received a connection, theGotConn
hook would run as below. This is in contrast to extractingClientTrace
from theRequest
’s context and using its hooks.The above basic proposal can be extended to all the hooks already present in
httptrace
. We propose the following additional hooks to be added tohttp.Stats
above:-wantConn
) enters/exits theidleConnWait
andconnsPerHostWait
queues. For example -These hooks could take as parameters
connectMethodKey
of the queue, time of entry/exit, and the number of remaining activewantConns
in the queues after the event (an activewantConn
is one which has not been delivered apersistConn
yet and itscontext
has not exceeded its deadline. Note that this is not equal to the number ofwantConns
in the queues as some of them could have been delivered apersistConn
in another goroutine or their context could have exceeded its deadline.) TheIdleConnWaitOut
andConnsPerHostWaitOut
hooks could also have an extra parametererror
which isnil
if thewantConns
were removed from the queues because they were successfully delivered apersistConn
. If not,error
gives the reason for their removal from the queues, for example, if the request was cancelled or its context deadline expired.IdleConnIn, IdleConnOut -
IdleConnIn
serves the same purpose as the existingPutIdleConn
hook from thehttptrace
package.IdleConnOut
is the related hook for when a connection is removed from theidleConn
queue. These hooks could take as parametersconnectMethodKey
of the queue and time of entry/exit.IdleConnOut
could take an additional parameter error which is nil if the idle connection was delivered to awantConn
. If not, it represents the reason it was removed from the queue, for example, being too old to be reused.ConnReused - This hook is called after serving a request, if the connection is directly delivered to a
wantConn
waiting inidleConnWait
instead of being added to theidleConn
queue. Currently, there is only one hook related to connections,PutIdleConn
, which records the latter.ConnReused
could take as parametersconnectMethodKey
of thepersistConn
(cacheKey
field) and time of delivery.MaxIdleConnsHit, MaxIdleConnsPerHost, MaxConnsPerHostHit - When configured capacities of queues like
MaxIdleConns
,MaxIdleConnsPerHost
,MaxConnsPerHost
are hit, these hooks should be able to take a "snapshot of the state" of the HTTP Client. They could take as parameters the counts of activewantConns
inidleConnWait
andconnsPerHostWait
queues for eachconnectMethodKey
and the length ofidleConn
queues for eachconnectMethodKey
. They could also take as parameters the state of all active connections like their TCP connection state( this is an optional feature for which we may have to make external calls). These hooks are useful for the user to understand where their server's bottlenecks or the server they are connecting to.Note: I have already implemented this during an internship.
The text was updated successfully, but these errors were encountered: