mailgun / groupcache

Clone of golang/groupcache with TTL and Item Removal support
Apache License 2.0
484 stars 72 forks source link

[feature-request] Provide an option to set http client options, like headers or maybe update the http req. #35

Open mgale opened 2 years ago

mgale commented 2 years ago

I would like to pass contextual data to the Getter interface Get function via ctx.

For example, using tracing tools like Datadog, the client HTTP headers need to be added before the HTTP request is sent and pulled off when the loading function is run. That could allow complete application visibility: https://docs.datadoghq.com/tracing/setup_overview/custom_instrumentation/go/#distributed-tracing

It could also allow the caller to pass other context-related information into the fill function. It seems like receiving side is possible by providing a custom Context func: https://github.com/mailgun/groupcache/blob/master/http.go#L74

However, it does not look like there is any way currently to add onto the HTTP client request: https://github.com/mailgun/groupcache/blob/master/http.go#L244

thrawn01 commented 2 years ago

This would be a welcome addition, I'm not sure what is the best way to pass tracing data around, but I suspect it will be via some header in the request.

mgale commented 2 years ago

I create a PR here: https://github.com/mailgun/groupcache/pull/37 which I have not tested yet. Feedback welcome.