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

[exporters/otlptracehttp] Do not log errors for 2XX response #3707

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixed

- Do not log errors for 2XX response for otlptracehttp exporter. (#3706)

### Added

- Semantic conventions of the `event` type are now generated. (#3697)
Expand Down
8 changes: 3 additions & 5 deletions exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ func (d *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc
}()
}

switch resp.StatusCode {
case http.StatusOK:
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
// Success, do not retry.
// Read the partial success message, if any.
var respData bytes.Buffer
Expand All @@ -189,14 +188,13 @@ func (d *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc
}
}
return nil

case http.StatusTooManyRequests, http.StatusServiceUnavailable:
} else if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable {
// Retry-able failures. Drain the body to reuse the connection.
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
otel.Handle(err)
}
return newResponseError(resp.Header)
default:
} else {
return fmt.Errorf("failed to send to %s: %s", request.URL, resp.Status)
}
})
Expand Down
6 changes: 6 additions & 0 deletions exporters/otlp/otlptrace/otlptracehttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func TestEndToEnd(t *testing.T) {
otlptracehttp.WithCompression(otlptracehttp.GzipCompression),
},
},
{
name: "no errors on 2XX Accepted",
mcCfg: mockCollectorConfig{
InjectHTTPStatus: []int{201, 202, 203, 204},
},
},
{
name: "retry",
opts: []otlptracehttp.Option{
Expand Down
11 changes: 8 additions & 3 deletions exporters/otlp/otlptrace/otlptracehttp/mock_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ func (c *mockCollector) serveTraces(w http.ResponseWriter, r *http.Request) {
return
}
h := c.getInjectResponseHeader()
if injectedStatus := c.getInjectHTTPStatus(); injectedStatus != 0 {
injectedStatus := c.getInjectHTTPStatus()
if injectedStatus != 0 {
writeReply(w, rawResponse, injectedStatus, c.injectContentType, h)
return
if injectedStatus < 200 || injectedStatus > 299 {
return
}
}
rawRequest, err := readRequest(r)
if err != nil {
Expand All @@ -118,7 +121,9 @@ func (c *mockCollector) serveTraces(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
return
}
writeReply(w, rawResponse, 0, c.injectContentType, h)
if injectedStatus == 0 {
writeReply(w, rawResponse, 0, c.injectContentType, h)
}
c.spanLock.Lock()
defer c.spanLock.Unlock()
c.spansStorage.AddSpans(request)
Expand Down