Skip to content
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

Router - Forward generated Request-Id to subgraph #534

Open
oxyno-zeta opened this issue Feb 15, 2024 · 4 comments
Open

Router - Forward generated Request-Id to subgraph #534

oxyno-zeta opened this issue Feb 15, 2024 · 4 comments
Labels
enhancement New feature or request internally-reviewed The issue has been reviewed internally.

Comments

@oxyno-zeta
Copy link

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 oxyno-zeta added the enhancement New feature or request label Feb 15, 2024
Copy link

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.

@oxyno-zeta
Copy link
Author

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

@flymedllva
Copy link
Contributor

flymedllva commented Feb 15, 2024

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.

@oxyno-zeta
Copy link
Author

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

@StarpTech StarpTech added the internally-reviewed The issue has been reviewed internally. label Feb 19, 2024
oxyno-zeta added a commit to oxyno-zeta/cosmo that referenced this issue Feb 19, 2024
oxyno-zeta added a commit to oxyno-zeta/cosmo that referenced this issue Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request internally-reviewed The issue has been reviewed internally.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants