Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Disable metrics tracking with no headers (part of #516) (#532)
Browse files Browse the repository at this point in the history
* Initial commit

* Fix build issue

* Remove testnet on metrics tracker.
  • Loading branch information
debnil authored Oct 14, 2020
1 parent 730c1da commit 411b795
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ func runTradeCmd(options inputs) {
botConfig.TickIntervalSeconds,
botConfig.TradingExchange,
botConfig.TradingPair(),
*options.noHeaders, // disable metrics if the CLI specified no headers
isTestnet,
)
if e != nil {
Expand Down
29 changes: 16 additions & 13 deletions support/metrics/metricsTracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ const (
// and can be used to directly send events to the
// Amplitude HTTP API.
type MetricsTracker struct {
client *http.Client
apiKey string
userID string
deviceID string
props commonProps
start time.Time
client *http.Client
apiKey string
userID string
deviceID string
props commonProps
start time.Time
isDisabled bool
}

// TODO DS Investigate other fields to add to this top-level event.
Expand Down Expand Up @@ -117,6 +118,7 @@ func MakeMetricsTracker(
updateTimeIntervalSeconds int32,
exchange string,
tradingPair string,
isDisabled bool,
isTestnet bool,
) (*MetricsTracker, error) {
props := commonProps{
Expand All @@ -133,12 +135,13 @@ func MakeMetricsTracker(
}

return &MetricsTracker{
client: client,
apiKey: apiKey,
userID: userID,
deviceID: deviceID,
props: props,
start: start,
client: client,
apiKey: apiKey,
userID: userID,
deviceID: deviceID,
props: props,
start: start,
isDisabled: isDisabled,
}, nil
}

Expand Down Expand Up @@ -173,7 +176,7 @@ func (mt *MetricsTracker) SendDeleteEvent(exit bool) error {
}

func (mt *MetricsTracker) sendEvent(eventType string, eventProps interface{}) error {
if mt.apiKey == "" || mt.userID == "-1" {
if mt.apiKey == "" || mt.userID == "-1" || mt.isDisabled {
log.Printf("metric - not sending event metric of type '%s' because metrics are disabled", eventType)
return nil
}
Expand Down

0 comments on commit 411b795

Please sign in to comment.