router
router copied to clipboard
Ability to include header as part of various log levels
Is your feature request related to a problem? Please describe. In our existing NodeJS gateway we have customised logger to include some non-sensitive headers as part of logs for various levels. Similar feature does not exist in Rust Gateway. This is very useful thing to have while debugging issues in production.
Describe the solution you'd like Inject headers based on separate logging header whitelisting config for given levels. For example
log:
levels:
all:
headers:
- propagate:
matching: (?i)(some-header|some-other-header)
Describe alternatives you've considered Rely on logging in subgraphs only instead of gateway. Needs to drill one level deeper to figure out issues.
This could end up as a configuration option (as described). It's hard to assess how generally applicable this is.
You can certainly do something like this right now with a simple rhai script. Something like:
fn router_service(service) {
const request_callback = Fn("process_request");
service.map_request(request_callback);
}
fn process_request(request) {
if "<my header>" in request.headers {
let header_value = request.headers["<my header>"];
log_info(`<my header>: ${header_value}`);
}
}
Where <my header> is whatever the name of your header is. Be aware of case requirements for matching header names.
@garypen Sorry for a newbie question. But is Rust with RHAI scripts equally performant as Rust gateway without it?
@vishvajeet-patil It's a good question. The short answer is that it depends what your rhai script is doing. In this case, not much, so the performance impact is likely to be minimal. You are basically formatting up a string (with some minimal branching logic) to write to a log and the time consuming part is going to be writing to the log, not formatting the string.
You did mention that this was for "debugging issues", so you could easily enable/disable the rhai script from your configuration as and when you need it..
A more general answer to your question: the router (it's a router, not a gateway) is high performance. Writing router plugins in rust will provide the highest performance and flexibility, but for many problems the slight trade-off in performance of writing a rhai extension offsets the complexity associated with writing a rust plugin and (more importantly) means you don't need to modify the base router that you are using.
We have many rhai examples in our repo which should help you get started. Documentation is also available.
I'll close this issue as accomplishing the requested behavior in Rhai will be performant, so the suggestion by @garypen is the best approach. Of course all logic (including logging!) has a cost to it at some point, and it's always good to measure the impact of your changes if you're particularly concerned. Thanks for opening this request originally!