From e7d10532d2b97788b095a83785dc2860d2d65785 Mon Sep 17 00:00:00 2001 From: Sina Date: Fri, 26 Aug 2022 15:01:04 +0200 Subject: [PATCH] fix: data race in datadog reporter --- report.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/report.go b/report.go index 253664c..c7e3f08 100644 --- a/report.go +++ b/report.go @@ -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, @@ -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...) }