Skip to content

Commit

Permalink
[exporter/datadogexporter] Do not append duplicate ddtags on each log…
Browse files Browse the repository at this point in the history
… submission. (#16539)

* [exporter/datadogexporter] Do not append duplicate ddtags on each log submission.

* [exporter/datadogexporter] Create a fresh submit log options on each request, and append payload ddtags to that.

* [exporter/datadogexporter] Restore fmt import

* [exporter/datadogexporter] Move opts to a local variable in log sender
  • Loading branch information
sbracegirdle authored Dec 5, 2022
1 parent 4107c6a commit b2d2792
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .chloggen/unreleased/dd-exporter-duplicate-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Doesn't append duplicate ddtags on each log submission leading to 414 API errors."

# One or more tracking issues related to the change
issues: [16380]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
16 changes: 8 additions & 8 deletions exporter/datadogexporter/internal/logs/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
type Sender struct {
logger *zap.Logger
api *datadogV2.LogsApi
opts datadogV2.SubmitLogOptionalParameters
verbose bool // reports whether payload contents should be dumped when logging at debug level
}

Expand All @@ -52,12 +51,9 @@ func NewSender(endpoint string, logger *zap.Logger, s exporterhelper.TimeoutSett
cfg.HTTPClient = clientutil.NewHTTPClient(s, insecureSkipVerify)
cfg.AddDefaultHeader("DD-API-KEY", apiKey)
apiClient := datadog.NewAPIClient(cfg)
// enable sending gzip
opts := *datadogV2.NewSubmitLogOptionalParameters().WithContentEncoding(datadogV2.CONTENTENCODING_GZIP)
return &Sender{
api: datadogV2.NewLogsApi(apiClient),
logger: logger,
opts: opts,
verbose: verbose,
}
}
Expand All @@ -68,15 +64,19 @@ func (s *Sender) SubmitLogs(ctx context.Context, payload []datadogV2.HTTPLogItem
s.logger.Debug("Submitting logs", zap.Any("payload", payload))
}

// enable sending gzip
// Get a fresh opts for each request to avoid duplicating ddtags
opts := *datadogV2.NewSubmitLogOptionalParameters().WithContentEncoding(datadogV2.CONTENTENCODING_GZIP)

// Correctly sets apiSubmitLogRequest ddtags field based on tags from translator Transform method
if payload[0].HasDdtags() {
tags := datadog.PtrString(payload[0].GetDdtags())
if s.opts.Ddtags != nil {
tags = datadog.PtrString(fmt.Sprint(*s.opts.Ddtags, ",", payload[0].GetDdtags()))
if opts.Ddtags != nil {
tags = datadog.PtrString(fmt.Sprint(*opts.Ddtags, ",", payload[0].GetDdtags()))
}
s.opts.Ddtags = tags
opts.Ddtags = tags
}
_, r, err := s.api.SubmitLog(ctx, payload, s.opts)
_, r, err := s.api.SubmitLog(ctx, payload, opts)
if err != nil {
if r != nil {
b := make([]byte, 1024) // 1KB message max
Expand Down

0 comments on commit b2d2792

Please sign in to comment.