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

RoundTripper should work out of the box. #29

Open
nmiculinic opened this issue Sep 1, 2018 · 1 comment
Open

RoundTripper should work out of the box. #29

nmiculinic opened this issue Sep 1, 2018 · 1 comment

Comments

@nmiculinic
Copy link

nmiculinic commented Sep 1, 2018

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

@yurishkuro
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants