| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package otlptrace_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"strings" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"github.com/stretchr/testify/assert" |
| 12 |
tracepb "go.opentelemetry.io/proto/otlp/trace/v1" |
| 13 |
|
| 14 |
"go.opentelemetry.io/otel/exporters/otlp/otlptrace" |
| 15 |
"go.opentelemetry.io/otel/sdk/trace/tracetest" |
| 16 |
) |
| 17 |
|
| 18 |
type client struct { |
| 19 |
uploadErr error |
| 20 |
} |
| 21 |
|
| 22 |
var _ otlptrace.Client = &client{} |
| 23 |
|
| 24 |
func (*client) Start(context.Context) error { |
| 25 |
return nil |
| 26 |
} |
| 27 |
|
| 28 |
func (*client) Stop(context.Context) error { |
| 29 |
return nil |
| 30 |
} |
| 31 |
|
| 32 |
func (c *client) UploadTraces(context.Context, []*tracepb.ResourceSpans) error { |
| 33 |
return c.uploadErr |
| 34 |
} |
| 35 |
|
| 36 |
func TestExporterClientError(t *testing.T) { |
| 37 |
ctx := t.Context() |
| 38 |
exp, err := otlptrace.New(ctx, &client{ |
| 39 |
uploadErr: context.Canceled, |
| 40 |
}) |
| 41 |
assert.NoError(t, err) |
| 42 |
|
| 43 |
spans := tracetest.SpanStubs{{Name: "Span 0"}}.Snapshots() |
| 44 |
err = exp.ExportSpans(ctx, spans) |
| 45 |
|
| 46 |
assert.Error(t, err) |
| 47 |
assert.ErrorIs(t, err, context.Canceled) |
| 48 |
assert.True(t, strings.HasPrefix(err.Error(), "traces export: "), "%+v", err) |
| 49 |
|
| 50 |
assert.NoError(t, exp.Shutdown(ctx)) |
| 51 |
} |