cosmo
cosmo copied to clipboard
Router - Forward generated Request-Id to subgraph
Component(s)
router
Is your feature request related to a problem? Please describe.
As an operation team member, I would like to forward the generated request-id (generated by chi middleware if request doesn't have it) to subgraph.
Describe the solution you'd like
In configuration and using the "Header manipulation" feature, I would like to be able to forward X-Request-Id (even if it is generated by router backend) to subgraph backends.
Something like this:
headers:
all: # Header rules for all origin requests.
request:
- op: "propagate"
named: X-Request-Id
Describe alternatives you've considered
No response
Additional context
No response
WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.
I have something working on my computer, I'm just lacking time to make tests for the moment.
Moreover, can you tell me where I can add tests for this ?
I've started modifying the router.go file in core package with this:
(start at line 776)
httpRouter.Use(middleware.RequestID)
// Rewrite request id in request header to allow "simple" forward to subgraph
httpRouter.Use(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Get request id
reqID := middleware.GetReqID(r.Context())
// Save it in request header
// Note: if it wasn't generated by middleware, it will override with the same value
// Note: so nothing important is made in this case
r.Header.Set(middleware.RequestIDHeader, reqID)
// Next
h.ServeHTTP(w, r)
})
})
I think being able to write my own
func newHTTPTransport(opts *SubgraphTransportOptions) http.RoundTripper {
with its own http.RoundTripper chain would solve this problem.
I need this for writing my own transportation metrics, among other things
As I understand the authors intended that https://cosmo-docs.wundergraph.com/router/custom-modules could be used to solve your problem.
@flymedllva : Yes custom modules can help for this but I proposed this because I can imagine multiple people wanted the same thing. If this is rejected by maintainers, that won't a problem for me, I will try to do it only via custom modules.