Skip to content

Commit

Permalink
Revert "fix(http): remove doubly injecting trace into client requests"
Browse files Browse the repository at this point in the history
This reverts commit 4527757.
  • Loading branch information
goller committed Jun 26, 2019
1 parent 4527757 commit ab46d28
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package http
import (
"net/http"
"net/url"

"github.com/influxdata/influxdb/kit/tracing"
)

// Service connects to an InfluxDB via HTTP.
Expand Down Expand Up @@ -52,7 +54,6 @@ func NewService(addr, token string) *Service {
}
}

// NewURL concats addr and path.
func NewURL(addr, path string) (*url.URL, error) {
u, err := url.Parse(addr)
if err != nil {
Expand All @@ -62,14 +63,27 @@ func NewURL(addr, path string) (*url.URL, error) {
return u, nil
}

// NewClient returns a pooling http.Client.
func NewClient(scheme string, insecure bool) *http.Client {
hc := &http.Client{
Transport: defaultTransport,
func NewClient(scheme string, insecure bool) *traceClient {
hc := &traceClient{
Client: http.Client{
Transport: defaultTransport,
},
}
if scheme == "https" && insecure {
hc.Transport = skipVerifyTransport
}

return hc
}

// traceClient always injects any opentracing trace into the client requests.
type traceClient struct {
http.Client
}

// Do injects the trace and then performs the request.
func (c *traceClient) Do(r *http.Request) (*http.Response, error) {
span, _ := tracing.StartSpanFromContext(r.Context())
tracing.InjectToHTTPRequest(span, r)
return c.Client.Do(r)
}

0 comments on commit ab46d28

Please sign in to comment.