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

Commit

Permalink
do not crash bot when we encounter a startup event error from Amplitu…
Browse files Browse the repository at this point in the history
…de (closes #651) (#653)

* 1 - metrics tracker does not error when it fails to send startup event

* 2 - prefix delete event metric log
  • Loading branch information
nikhilsaraf authored Feb 8, 2021
1 parent 89f3d31 commit eb1142d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func runTradeCmd(options inputs) {

e = metricsTracker.SendStartupEvent(time.Now())
if e != nil {
logger.Fatal(l, fmt.Errorf("could not send startup event metric: %s", e))
l.Infof("metric - could not send startup event metric: %s", e)
}

// --- start initialization of objects ----
Expand Down Expand Up @@ -988,7 +988,7 @@ func deleteAllOffersAndExit(
e := metricsTracker.SendDeleteEvent(true)
if e != nil {
// We don't want to crash upon failure, so offers will be deleted regardless of metric send.
l.Infof("could not send delete event metric: %s", e)
l.Infof("metric - could not send delete event metric: %s", e)
}

l.Info("")
Expand Down
13 changes: 12 additions & 1 deletion plugins/metricsTracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type MetricsTracker struct {
isDisabled bool
updateEventSentTime *time.Time
cliVersion string
failedStartupSend bool
}

// TODO DS Investigate other fields to add to this top-level event.
Expand Down Expand Up @@ -261,6 +262,7 @@ func MakeMetricsTracker(
isDisabled: isDisabled,
updateEventSentTime: nil,
cliVersion: commonProps.CliVersion,
failedStartupSend: false,
}, nil
}

Expand All @@ -271,7 +273,12 @@ func (mt *MetricsTracker) GetUpdateEventSentTime() *time.Time {

// SendStartupEvent sends the startup Amplitude event.
func (mt *MetricsTracker) SendStartupEvent(now time.Time) error {
return mt.SendEvent(startupEventName, mt.eventProps, now)
e := mt.SendEvent(startupEventName, mt.eventProps, now)
if e != nil {
mt.failedStartupSend = true
return fmt.Errorf("metric - failed to send startup event: %s", e)
}
return nil
}

// SendUpdateEvent sends the update Amplitude event.
Expand Down Expand Up @@ -319,6 +326,10 @@ func (mt *MetricsTracker) SendEvent(eventType string, eventPropsInterface interf
return nil
}

if mt.failedStartupSend {
return fmt.Errorf("metric - not sending event metric of type '%s' because we failed to send startup event", eventType)
}

trackerProps := mt.eventProps
trackerProps[secondsSinceStartKey] = now.Sub(mt.botStartTime).Seconds()

Expand Down

0 comments on commit eb1142d

Please sign in to comment.