Skip to content

Commit

Permalink
Add jaeger option that allows to specify custom http client (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
namreg authored Apr 28, 2020
1 parent 2265395 commit 5863f85
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions exporters/trace/jaeger/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ func WithCollectorEndpoint(collectorEndpoint string, options ...CollectorEndpoin
return nil, errors.New("collectorEndpoint must not be empty")
}

o := &CollectorEndpointOptions{}
o := &CollectorEndpointOptions{
httpClient: http.DefaultClient,
}
for _, opt := range options {
opt(o)
}

return &collectorUploader{
endpoint: collectorEndpoint,
username: o.username,
password: o.password,
endpoint: collectorEndpoint,
username: o.username,
password: o.password,
httpClient: o.httpClient,
}, nil
}
}
Expand All @@ -80,6 +83,9 @@ type CollectorEndpointOptions struct {

// password to be used if basic auth is required.
password string

// httpClient to be used to make requests to the collector endpoint.
httpClient *http.Client
}

// WithUsername sets the username to be used if basic auth is required.
Expand All @@ -96,6 +102,13 @@ func WithPassword(password string) CollectorEndpointOption {
}
}

// WithHTTPClient sets the http client to be used to make request to the collector endpoint.
func WithHTTPClient(client *http.Client) CollectorEndpointOption {
return func(o *CollectorEndpointOptions) {
o.httpClient = client
}
}

// agentUploader implements batchUploader interface sending batches to
// Jaeger through the UDP agent.
type agentUploader struct {
Expand All @@ -111,9 +124,10 @@ func (a *agentUploader) upload(batch *gen.Batch) error {
// collectorUploader implements batchUploader interface sending batches to
// Jaeger through the collector http endpoint.
type collectorUploader struct {
endpoint string
username string
password string
endpoint string
username string
password string
httpClient *http.Client
}

var _ batchUploader = (*collectorUploader)(nil)
Expand All @@ -132,7 +146,7 @@ func (c *collectorUploader) upload(batch *gen.Batch) error {
}
req.Header.Set("Content-Type", "application/x-thrift")

resp, err := http.DefaultClient.Do(req)
resp, err := c.httpClient.Do(req)
if err != nil {
return err
}
Expand Down

0 comments on commit 5863f85

Please sign in to comment.