Skip to content

Commit

Permalink
Merge pull request #14 from FindHotel/sc-46342-recover-from-panic-in-…
Browse files Browse the repository at this point in the history
…analytics-go-internal

recover from panic in analytics go
  • Loading branch information
lev112 authored Mar 3, 2022
2 parents 96c221e + 9dfa3fd commit 8545abd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions report.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ func (dd *DatadogReporter) AddTags(tags ...string) {

// Flush flushes reported metrics.
func (dd *DatadogReporter) Flush() error {
metrics := dd.metrics // we need a copy since we can do many retries
dd.Lock()
metrics := dd.metrics
dd.metrics = []datadog.Metric{}
dd.Unlock()

err := retry.Do(
func() error {
return dd.Client.PostMetrics(metrics)
Expand All @@ -179,10 +183,6 @@ func (dd *DatadogReporter) Flush() error {
}),
)

dd.Lock()
dd.metrics = []datadog.Metric{}
dd.Unlock()

if err != nil {
return fmt.Errorf("submission metrics to DataDog failed for the last time, metrics are gone: %s", err)
}
Expand Down

0 comments on commit 8545abd

Please sign in to comment.