Skip to content

Commit

Permalink
[exporter/datadog] Do not read response if nil on logs error (open-te…
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi authored and shalper2 committed Dec 6, 2022
1 parent 2a8edc4 commit a5c13b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .chloggen/mx-psi_logs-exporter-crash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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: Fixes crash when logging error on logs exporter

# One or more tracking issues related to the change
issues: [16077]
15 changes: 11 additions & 4 deletions exporter/datadogexporter/internal/logs/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/zap"

Expand Down Expand Up @@ -73,10 +74,16 @@ func (s *Sender) SubmitLogs(ctx context.Context, payload []datadogV2.HTTPLogItem
}
_, r, err := s.api.SubmitLog(ctx, payload, s.opts)
if err != nil {
b := make([]byte, 1024) // 1KB message max
n, _ := r.Body.Read(b) // ignore any error
s.logger.Error("Failed to send logs", zap.Error(err), zap.String("msg", string(b[:n])), zap.String("status_code", r.Status))
return err
if r != nil {
b := make([]byte, 1024) // 1KB message max
n, _ := r.Body.Read(b) // ignore any error
s.logger.Error("Failed to send logs", zap.Error(err), zap.String("msg", string(b[:n])), zap.String("status_code", r.Status))
return err
}

// If response is nil assume permanent error.
// The error will be logged by the exporter helper.
return consumererror.NewPermanent(err)
}
return nil
}

0 comments on commit a5c13b5

Please sign in to comment.