...

Source file src/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter_test.go

Documentation: go.opentelemetry.io/otel/exporters/otlp/otlptrace

     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  
    15  package otlptrace_test
    16  
    17  import (
    18  	"context"
    19  	"errors"
    20  	"strings"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  
    25  	"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
    26  	"go.opentelemetry.io/otel/sdk/trace/tracetest"
    27  	tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
    28  )
    29  
    30  type client struct {
    31  	uploadErr error
    32  }
    33  
    34  var _ otlptrace.Client = &client{}
    35  
    36  func (c *client) Start(ctx context.Context) error {
    37  	return nil
    38  }
    39  
    40  func (c *client) Stop(ctx context.Context) error {
    41  	return nil
    42  }
    43  
    44  func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error {
    45  	return c.uploadErr
    46  }
    47  
    48  func TestExporterClientError(t *testing.T) {
    49  	ctx := context.Background()
    50  	exp, err := otlptrace.New(ctx, &client{
    51  		uploadErr: context.Canceled,
    52  	})
    53  	assert.NoError(t, err)
    54  
    55  	spans := tracetest.SpanStubs{{Name: "Span 0"}}.Snapshots()
    56  	err = exp.ExportSpans(ctx, spans)
    57  
    58  	assert.Error(t, err)
    59  	assert.True(t, errors.Is(err, context.Canceled))
    60  	assert.True(t, strings.HasPrefix(err.Error(), "traces export: "), err)
    61  
    62  	assert.NoError(t, exp.Shutdown(ctx))
    63  }
    64  

View as plain text