Skip to content

Commit

Permalink
handle no content responses for otlptraces http exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jul 26, 2023
1 parent d223aab commit 1c626d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/otlptracehttp/client.go
Expand Up @@ -166,7 +166,7 @@ func (d *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc
}

switch resp.StatusCode {
case http.StatusOK:
case http.StatusOK, http.StatusNoContent:
// Success, do not retry.
// Read the partial success message, if any.
var respData bytes.Buffer
Expand Down
27 changes: 27 additions & 0 deletions exporters/otlp/otlptrace/otlptracehttp/client_test.go
Expand Up @@ -401,3 +401,30 @@ func TestPartialSuccess(t *testing.T) {
require.Contains(t, errs[0].Error(), "partially successful")
require.Contains(t, errs[0].Error(), "2 spans rejected")
}

func TestNoContent(t *testing.T) {
mcCfg := mockCollectorConfig{
InjectHTTPStatus: []int{204},
}
mc := runMockCollector(t, mcCfg)
defer mc.MustStop(t)
driver := otlptracehttp.NewClient(
otlptracehttp.WithEndpoint(mc.Endpoint()),
otlptracehttp.WithInsecure(),
)
ctx := context.Background()
exporter, err := otlptrace.New(ctx, driver)
require.NoError(t, err)
defer func() {
assert.NoError(t, exporter.Shutdown(context.Background()))
}()

errs := []error{}
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
errs = append(errs, err)
}))
err = exporter.ExportSpans(ctx, otlptracetest.SingleReadOnlySpan())
assert.NoError(t, err)

require.Equal(t, 0, len(errs))
}

0 comments on commit 1c626d0

Please sign in to comment.