cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

Router - Forward generated Request-Id to subgraph

Open oxyno-zeta opened this issue 1 year ago • 4 comments
trafficstars

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

oxyno-zeta avatar Feb 15 '24 12:02 oxyno-zeta

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.

github-actions[bot] avatar Feb 15 '24 12:02 github-actions[bot]

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)
		})
	})

oxyno-zeta avatar Feb 15 '24 13:02 oxyno-zeta

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 avatar Feb 15 '24 14:02 flymedllva

@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.

oxyno-zeta avatar Feb 15 '24 14:02 oxyno-zeta