Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/datadog] Do not read response if nil on logs error #16390

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still want to log the error if r is nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still want to log the error if r is nil?

It will be logged by the exporterhelper since we bubble up the error :)

I think the real question is if we should be double logging when r is not nil, I feel like it's justified because we are adding some extra fields here, and it's hard to pass these as fields to the exporterhelper

return err
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the server is unreachable , i would expect this code to get hit. Shouldn't we retry in that case ?

}
return nil
}