DataDog / dd-trace-go

Datadog Go Library including APM tracing, profiling, and security monitoring.
https://docs.datadoghq.com/tracing/
Other
662 stars 435 forks source link

propose: contrib/net/http: add conditional propagation logic to roundTripper configuration #2823

Open eyasy1217 opened 2 months ago

eyasy1217 commented 2 months ago

I want to determine whether to propagate or not for each api I call. For example, when calling a external api, no propagation is performed. I assume the following code.

// https://github.com/DataDog/dd-trace-go/blob/e4985df5f9ef6a5b1f5cc9f72b03ddddcb4af0bc/contrib/net/http/option.go#L138
type roundTripperConfig struct {
    // ...
+   propagationFunc func(*http.Request) bool
    // ...
}

func (rt *roundTripper) RoundTrip(req *http.Request) (res *http.Response, err error) {
    // ...

    // https://github.com/DataDog/dd-trace-go/blob/e4985df5f9ef6a5b1f5cc9f72b03ddddcb4af0bc/contrib/net/http/roundtripper.go#L73
-   if rt.cfg.propagation {
+   if rt.cfg.propagation && rt.cfg.propagationFunc(r2) {
darccio commented 2 months ago

Hello @eyasy1217, thanks for reaching out. We'll review this during our next gardening session.

darccio commented 1 month ago

@eyasy1217 What would be the use case? We found it interesting and we are willing to implement it, but we would like to understand the use case. For instance, is it to avoid sending propagation headers to a third party API that isn't able to handle correctly unknown headers?

eyasy1217 commented 1 month ago

It's not such a big use case. Same reason as https://github.com/DataDog/dd-trace-go/issues/1166 .