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

contrib/net/http: add a convenience WrapClient method #335

Merged
merged 2 commits into from
Sep 19, 2018
Merged

contrib/net/http: add a convenience WrapClient method #335

merged 2 commits into from
Sep 19, 2018

Conversation

gbbr
Copy link
Contributor

@gbbr gbbr commented Sep 19, 2018

This will facilitate integrating with libraries such as go-github

This will facilitate integrating with libraries such as `go-github` and
`go-cloud`
@gbbr gbbr added this to the next milestone Sep 19, 2018
// 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
Copy link
Contributor

@bmermet bmermet Sep 19, 2018

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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 👍

Copy link
Contributor

@dd-caleb dd-caleb left a 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
    }

@gbbr
Copy link
Contributor Author

gbbr commented Sep 19, 2018

@dd-caleb good idea, check the latest commit - that's what you mean, right?

@gbbr gbbr merged commit ba6650d into v1 Sep 19, 2018
@gbbr gbbr deleted the gbbr/client branch September 19, 2018 13:16
@dd-caleb
Copy link
Contributor

@gbbr yep, thanks. Should hopefully prevent double tracing.

@gbbr gbbr modified the milestones: next, 1.4.0 Sep 19, 2018
mingrammer pushed a commit to mingrammer/dd-trace-go that referenced this pull request Dec 22, 2020
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 this pull request may close these issues.

None yet

3 participants