From 966b5dbaab96708a7df8fc6016dac8f3a770381e Mon Sep 17 00:00:00 2001 From: Daria Bialobrzeska Date: Thu, 28 Nov 2024 14:50:54 +0100 Subject: [PATCH] Add Transport option in configuration --- bugsnag_performance.go | 2 ++ configuration.go | 9 +++++++++ delivery.go | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bugsnag_performance.go b/bugsnag_performance.go index db5a185..485fff0 100644 --- a/bugsnag_performance.go +++ b/bugsnag_performance.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "net/http" "os" "sync" @@ -26,6 +27,7 @@ func init() { ReleaseStage: "production", Logger: log.New(os.Stdout, "[BugsnagPerformance] ", log.LstdFlags), MainContext: context.TODO(), + Transport: http.DefaultTransport, } } diff --git a/configuration.go b/configuration.go index 72bc824..3fb1777 100644 --- a/configuration.go +++ b/configuration.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "net/http" "os" "strings" @@ -53,6 +54,11 @@ type Configuration struct { // if Distributed Tracing is used. ServiceName string + // The http Transport to use, defaults to the default http Transport. This + // can be configured if you are in an environment + // that has stringent conditions on making http requests. + Transport http.RoundTripper + // Logger to use for debug messages Logger *log.Logger } @@ -85,6 +91,9 @@ func (config *Configuration) update(other *Configuration) *Configuration { if other.ServiceName != "" { config.ServiceName = other.ServiceName } + if other.Transport != nil { + config.Transport = other.Transport + } if other.Logger != nil { config.Logger = other.Logger } diff --git a/delivery.go b/delivery.go index 8cb84f6..f28d5af 100644 --- a/delivery.go +++ b/delivery.go @@ -47,7 +47,8 @@ type delivery struct { func (d *delivery) sendPayload(headers map[string]string, payload []byte) (*http.Response, error) { client := http.Client{ - Timeout: 10 * time.Second, + Timeout: 10 * time.Second, + Transport: Config.Transport, } body := bytes.NewBuffer(payload)