RoundTripper should work out of the box.
nmiculinic opened this issue · 1 comments
In following example:
client := &http.Client{Transport: &nethttp.Transport{}}
req, err := http.NewRequest("GET", "http://google.com", nil)
if err != nil {
return err
}
req = req.WithContext(ctx) // extend existing trace, if any
req, ht := nethttp.TraceRequest(tracer, req)
defer ht.Finish()
res, err := client.Do(req)
if err != nil {
return err
}
res.Body.Close()
return nil
nethttp.TraceRequest is extra. It is ok for people wanting greater control, but it should default to using GlobalTracer().
Similar to opencensus variant, ochttp, https://github.com/census-instrumentation/opencensus-go/tree/master/plugin/ochttp, things work out of the box. Just using their server middleware and their roundtripper plus adding parent request headers to context (via req = req.WithContext(parent.Context())
)
However currently without req, ht := nethttp.TraceRequest(tracer, req)
parent span isn't correlated to the child span
nethttp.TraceRequest is extra. It is ok for people wanting greater control, but it should default to using GlobalTracer().
I don't recall the full interactions here, but I think ideally everything should work with just this:
client := &http.Client{Transport: &nethttp.Transport{Tracer: tracer}}
And if instead the transport is created without a tracer, then the global one is used.