From 5863f8562bac642dc799d2b7f61fe08cafa210fa Mon Sep 17 00:00:00 2001 From: Igor German Date: Tue, 28 Apr 2020 21:35:34 +0300 Subject: [PATCH] Add jaeger option that allows to specify custom http client (#671) --- exporters/trace/jaeger/uploader.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/exporters/trace/jaeger/uploader.go b/exporters/trace/jaeger/uploader.go index 5b8233ae4..158d02d47 100644 --- a/exporters/trace/jaeger/uploader.go +++ b/exporters/trace/jaeger/uploader.go @@ -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 } } @@ -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. @@ -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 { @@ -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) @@ -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 }