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

OTLP traces export errors use a consistent error message prefix #3516

Merged
merged 12 commits into from
Jan 27, 2023
7 changes: 6 additions & 1 deletion exporters/otlp/otlptrace/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
import (
"context"
"errors"
"fmt"
"sync"

"go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform"
Expand Down Expand Up @@ -45,7 +46,11 @@ func (e *Exporter) ExportSpans(ctx context.Context, ss []tracesdk.ReadOnlySpan)
return nil
}

return e.client.UploadTraces(ctx, protoSpans)
err := e.client.UploadTraces(ctx, protoSpans)
if err != nil {
return fmt.Errorf("trace export: %w", err)
}
return nil
}

// Start establishes a connection to the receiving endpoint.
Expand Down
66 changes: 66 additions & 0 deletions exporters/otlp/otlptrace/exporter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package otlptrace_test

import (
"context"
"errors"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
)

type client struct {
uploadErr error
}

var _ otlptrace.Client = &client{}

func (c *client) Start(ctx context.Context) error {
return nil
}

func (c *client) Stop(ctx context.Context) error {
return nil
}

func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error {
return c.uploadErr
}

type span struct {
tracesdk.ReadOnlySpan
}

func TestExporterClientError(t *testing.T) {
ctx := context.Background()
exp, err := otlptrace.New(ctx, &client{
uploadErr: context.Canceled,
})
assert.NoError(t, err)

spans := tracetest.SpanStubs{{Name: "Span 0"}}.Snapshots()
err = exp.ExportSpans(ctx, spans)

assert.Error(t, err)
assert.True(t, errors.Is(err, context.Canceled))
assert.Contains(t, err.Error(), "trace export")

assert.NoError(t, exp.Shutdown(ctx))
}
5 changes: 2 additions & 3 deletions exporters/otlp/otlptrace/otlptracegrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/status"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -239,7 +237,8 @@ func TestExportSpansTimeoutHonored(t *testing.T) {
// Release the export so everything is cleaned up on shutdown.
close(exportBlock)

require.Equal(t, codes.DeadlineExceeded, status.Convert(err).Code())
dashpole marked this conversation as resolved.
Show resolved Hide resolved
require.Error(t, err)
require.Contains(t, err.Error(), "deadline exceeded")
}

func TestNewWithMultipleAttributeTypes(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (d *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc
}
return newResponseError(resp.Header)
default:
return fmt.Errorf("failed to send %s to %s: %s", d.name, request.URL, resp.Status)
return fmt.Errorf("failed to send to %s: %s", request.URL, resp.Status)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/otlptrace/otlptracehttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"net/http"
"os"
"testing"
"time"

Expand Down Expand Up @@ -219,7 +218,8 @@ func TestTimeout(t *testing.T) {
assert.NoError(t, exporter.Shutdown(ctx))
}()
err = exporter.ExportSpans(ctx, otlptracetest.SingleReadOnlySpan())
assert.Equalf(t, true, os.IsTimeout(err), "expected timeout error, got: %v", err)
jmacd marked this conversation as resolved.
Show resolved Hide resolved

assert.Contains(t, err.Error(), "deadline exceeded")
}

func TestNoRetry(t *testing.T) {
Expand All @@ -246,7 +246,7 @@ func TestNoRetry(t *testing.T) {
}()
err = exporter.ExportSpans(ctx, otlptracetest.SingleReadOnlySpan())
assert.Error(t, err)
assert.Equal(t, fmt.Sprintf("failed to send traces to http://%s/v1/traces: 400 Bad Request", mc.endpoint), err.Error())
assert.Equal(t, fmt.Sprintf("trace export: failed to send to http://%s/v1/traces: 400 Bad Request", mc.endpoint), err.Error())
assert.Empty(t, mc.GetSpans())
}

Expand Down