Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions pkg/http/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func CaptureCommand(command string) ([]byte, Error) {
return nil, Error{Err: err, Message: "Unable to generate url"}
}

// Use shorter timeout for analytics to avoid blocking command execution
originalTimeout := TimeoutDuration
TimeoutDuration = AnalyticsTimeoutDuration
defer func() { TimeoutDuration = originalTimeout }()

_, _, resp, err := PostRequest(url, true, map[string]string{"Content-Type": "application/json"}, body)
if err != nil {
return nil, Error{Err: err, Message: "Unable to send anonymous analytics"}
Expand All @@ -60,6 +65,11 @@ func CaptureEvent(event string, metadata map[string]interface{}) ([]byte, Error)
return nil, Error{Err: err, Message: "Unable to generate url"}
}

// Use shorter timeout for analytics to avoid blocking command execution
originalTimeout := TimeoutDuration
TimeoutDuration = AnalyticsTimeoutDuration
defer func() { TimeoutDuration = originalTimeout }()

_, _, resp, err := PostRequest(url, true, map[string]string{"Content-Type": "application/json"}, body)
if err != nil {
return nil, Error{Err: err, Message: "Unable to send anonymous analytics"}
Expand Down
3 changes: 3 additions & 0 deletions pkg/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ var UseTimeout = true
// TimeoutDuration how long to wait for a request to complete before timing out
var TimeoutDuration = 10 * time.Second

// AnalyticsTimeoutDuration timeout for analytics requests (shorter to avoid blocking command execution)
var AnalyticsTimeoutDuration = 2 * time.Second

// RequestAttempts how many request attempts are made before giving up
var RequestAttempts = 5
Loading