-
Notifications
You must be signed in to change notification settings - Fork 419
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
contrib/net/http: add a convenience WrapClient method #335
Conversation
This will facilitate integrating with libraries such as `go-github` and `go-cloud`
// WrapClient modifies the given client's transport to augment it with tracing and returns it. | ||
func WrapClient(c *http.Client, opts ...RoundTripperOption) *http.Client { | ||
if c.Transport == nil { | ||
c.Transport = http.DefaultTransport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is http.DefaultTransport
automatically wrapped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure I understand the question. If you're wondering if calling WrapClient
will accidentally wrap the default transport, the answer is no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I misread the code. My question doesn't make much sense.
Everything looks good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A possible improvement to WrapRoundTripper
would be to detect if its already wrapped and just return.
if wrapped, ok := rt.(*roundTripper); ok {
rt = wrapped.base
}
@dd-caleb good idea, check the latest commit - that's what you mean, right? |
@gbbr yep, thanks. Should hopefully prevent double tracing. |
This will facilitate integrating with libraries such as
go-github