Skip to content

Commit

Permalink
flaps: add support for custom HTTP transports (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 authored Apr 26, 2024
1 parent 15be87a commit 8e8ef12
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions flaps/flaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type NewClientOpts struct {

// optional:
Logger fly.Logger

// optional, used to construct the underlying HTTP client
Transport http.RoundTripper
}

func NewWithOptions(ctx context.Context, opts NewClientOpts) (*Client, error) {
Expand Down Expand Up @@ -84,8 +87,13 @@ func NewWithOptions(ctx context.Context, opts NewClientOpts) (*Client, error) {
if err != nil {
return nil, fmt.Errorf("invalid FLY_FLAPS_BASE_URL '%s' with error: %w", flapsBaseURL, err)
}
transport := otelhttp.NewTransport(http.DefaultTransport)
httpClient, err := fly.NewHTTPClient(opts.Logger, transport)

transport := http.DefaultTransport
if opts.Transport != nil {
transport = opts.Transport
}
otelTransport := otelhttp.NewTransport(transport)
httpClient, err := fly.NewHTTPClient(opts.Logger, otelTransport)
if err != nil {
return nil, fmt.Errorf("flaps: can't setup HTTP client to %s: %w", flapsUrl.String(), err)
}
Expand Down

0 comments on commit 8e8ef12

Please sign in to comment.