Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Apr 12, 2023
1 parent ecea1ba commit 9be0a1e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ddspanname

import (
"context"
"testing"

"github.com/stretchr/testify/require"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
)

func TestProvider(t *testing.T) {
sr := tracetest.NewSpanRecorder()
tracerProvider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr))

ddprovider := NewTracerProvider("ddspanname.operation",
WithTracerProvider(tracerProvider))
ddtracer := ddprovider.Tracer("ddspanname.instrument")

require.IsType(t, &tracer{}, ddtracer)

_, span := ddtracer.Start(context.Background(), "ddspanname.span")
span.End()

spans := sr.Ended()
require.Len(t, spans, 1)

require.Equal(t, "ddspanname.span", spans[0].Name())
require.Contains(t, spans[0].Attributes(), DDOperationNameKey.String("ddspanname.operation"))
require.Contains(t, spans[0].Attributes(), DDResourceNameKey.String("ddspanname.span"))

}

0 comments on commit 9be0a1e

Please sign in to comment.