exporter_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright The OpenTelemetry Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package otlptrace_test
  15. import (
  16. "context"
  17. "errors"
  18. "strings"
  19. "testing"
  20. "github.com/stretchr/testify/assert"
  21. "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
  22. "go.opentelemetry.io/otel/sdk/trace/tracetest"
  23. tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
  24. )
  25. type client struct {
  26. uploadErr error
  27. }
  28. var _ otlptrace.Client = &client{}
  29. func (c *client) Start(ctx context.Context) error {
  30. return nil
  31. }
  32. func (c *client) Stop(ctx context.Context) error {
  33. return nil
  34. }
  35. func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error {
  36. return c.uploadErr
  37. }
  38. func TestExporterClientError(t *testing.T) {
  39. ctx := context.Background()
  40. exp, err := otlptrace.New(ctx, &client{
  41. uploadErr: context.Canceled,
  42. })
  43. assert.NoError(t, err)
  44. spans := tracetest.SpanStubs{{Name: "Span 0"}}.Snapshots()
  45. err = exp.ExportSpans(ctx, spans)
  46. assert.Error(t, err)
  47. assert.True(t, errors.Is(err, context.Canceled))
  48. assert.True(t, strings.HasPrefix(err.Error(), "traces export: "), err)
  49. assert.NoError(t, exp.Shutdown(ctx))
  50. }