Skip to content

Commit

Permalink
Redact datadog API key in log output (influxdata#3420)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmshannon authored and Alain ROMEYER committed May 19, 2018
1 parent 1124f22 commit 690cfdf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions plugins/outputs/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"sort"
"strings"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
Expand Down Expand Up @@ -100,6 +101,7 @@ func (d *Datadog) Write(metrics []telegraf.Metric) error {
}
}

redactedApiKey := "****************"
ts.Series = make([]*Metric, metricCounter)
copy(ts.Series, tempSeries[0:])
tsBytes, err := json.Marshal(ts)
Expand All @@ -108,13 +110,13 @@ func (d *Datadog) Write(metrics []telegraf.Metric) error {
}
req, err := http.NewRequest("POST", d.authenticatedUrl(), bytes.NewBuffer(tsBytes))
if err != nil {
return fmt.Errorf("unable to create http.Request, %s\n", err.Error())
return fmt.Errorf("unable to create http.Request, %s\n", strings.Replace(err.Error(), d.Apikey, redactedApiKey, -1))
}
req.Header.Add("Content-Type", "application/json")

resp, err := d.client.Do(req)
if err != nil {
return fmt.Errorf("error POSTing metrics, %s\n", err.Error())
return fmt.Errorf("error POSTing metrics, %s\n", strings.Replace(err.Error(), d.Apikey, redactedApiKey, -1))
}
defer resp.Body.Close()

Expand Down

0 comments on commit 690cfdf

Please sign in to comment.