Skip to content

Commit

Permalink
Merge pull request #17 from FindHotel/sina-fix-data-race
Browse files Browse the repository at this point in the history
fix: data race in datadog reporter
  • Loading branch information
xesina authored Aug 26, 2022
2 parents a4500ec + e7d1053 commit d3d5b31
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions report.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func newHTTPTransport() *http.Transport {
func NewDatadogReporter(apiKey, appKey string, tags ...string) *DatadogReporter {
dr := DatadogReporter{
Client: datadog.NewClient(apiKey, appKey),
Mutex: &sync.Mutex{},
}
dr.Client.HttpClient = &http.Client{
Timeout: time.Second * 30,
Expand All @@ -152,11 +151,13 @@ type DatadogReporter struct {
logger Logger
metrics []datadog.Metric
tags []string
*sync.Mutex
sync.Mutex
}

// AddTags adds tags to be added to each metric reported.
func (dd *DatadogReporter) AddTags(tags ...string) {
dd.Lock()
defer dd.Unlock()
dd.tags = append(dd.tags, tags...)
}

Expand Down

0 comments on commit d3d5b31

Please sign in to comment.