Tracing: Allow augmentation of context in IncomingRequestQueuedHook to bridge to data transfer.
hannahhoward opened this issue · 0 comments
hannahhoward commented
Goal
We want to link incoming request spans to data transfers. We don't yet have a way to do that, but we have a Hook that's positioned in the exact right place to do so -- the IncomingRequestQueuedHook
Implementation
The current implementation of IncomingRequestQueudHook is as follows:
// OnIncomingRequestQueuedHook is a hook that runs each time a new incoming request is added to the responder's task queue.
// It receives the peer that sent the request and all data about the request.
type OnIncomingRequestQueuedHook func(p peer.ID, request RequestData)
type GraphSyncExchange interface {
// ...
// RegisterIncomingRequestQueuedHook adds a hook that runs when a new incoming request is added to the responder's task queue.
RegisterIncomingRequestQueuedHook(hook OnIncomingRequestQueuedHook) UnregisterHookFunc
// ...
}
We're going to change it to:
// RequestQueuedHookActions are actions that can be taken in a request queued hook to
// change execution of the response
type RequestQueuedHookActions interface {
AugmentContext(func(reqCtx context.Context) context.Context)
}
// OnIncomingRequestQueuedHook is a hook that runs each time a new incoming request is added to the responder's task queue.
// It receives the peer that sent the request and all data about the request.
type OnIncomingRequestQueuedHook func(p peer.ID, request RequestData, hookActions RequestQueuedHookActions)
type GraphSyncExchange interface {
// ...
// RegisterIncomingRequestQueuedHook adds a hook that runs when a new incoming request is added to the responder's task queue.
RegisterIncomingRequestQueuedHook(hook OnIncomingRequestQueuedHook) UnregisterHookFunc
// ...
}
Why take a context augmentation function? So we can compose modifications on the off chance there are multiple instances of this hook register.
The idea here to make tracing work should be as follows:
- run ProcessRequestQueuedHooks, and modify it so it returns a result struct with all the context modification functions
- make a context for the request from the ResponseManager context (just a context.WithCancel)
- run the context modifications iteratively to get the final request context
- NOW create the request span, picking up any parent spans in the process