You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
package tracing
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
"github.com/go-kratos/kratos/v2/internal/testdata/binding"
|
|
)
|
|
|
|
func TestNewTracer(t *testing.T) {
|
|
tracer := NewTracer(trace.SpanKindClient, func(o *options) {
|
|
o.tracerProvider = trace.NewNoopTracerProvider()
|
|
})
|
|
|
|
if tracer.kind != trace.SpanKindClient {
|
|
t.Errorf("The tracer kind must be equal to trace.SpanKindClient, %v given.", tracer.kind)
|
|
}
|
|
|
|
defer func() {
|
|
if recover() == nil {
|
|
t.Error("The NewTracer with an invalid SpanKindMustCrash must panic")
|
|
}
|
|
}()
|
|
_ = NewTracer(666, func(o *options) {
|
|
o.tracerProvider = trace.NewNoopTracerProvider()
|
|
})
|
|
}
|
|
|
|
func TestTracer_End(_ *testing.T) {
|
|
tracer := NewTracer(trace.SpanKindClient, func(o *options) {
|
|
o.tracerProvider = trace.NewNoopTracerProvider()
|
|
})
|
|
ctx, span := trace.NewNoopTracerProvider().Tracer("noop").Start(context.Background(), "noopSpan")
|
|
|
|
// Handle with error case
|
|
tracer.End(ctx, span, nil, errors.New("dummy error"))
|
|
|
|
// Handle without error case
|
|
tracer.End(ctx, span, nil, nil)
|
|
|
|
m := &binding.HelloRequest{}
|
|
|
|
// Handle the trace KindServer
|
|
tracer = NewTracer(trace.SpanKindServer, func(o *options) {
|
|
o.tracerProvider = trace.NewNoopTracerProvider()
|
|
})
|
|
tracer.End(ctx, span, m, nil)
|
|
tracer = NewTracer(trace.SpanKindClient, func(o *options) {
|
|
o.tracerProvider = trace.NewNoopTracerProvider()
|
|
})
|
|
tracer.End(ctx, span, m, nil)
|
|
}
|
|
|