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

Add jaeger option that allows to specify custom http client #671

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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