feat(trace): add trace test helpers (#3108)

This commit is contained in:
cong
2023-04-08 22:52:25 +08:00
committed by GitHub
parent 189e9bd9da
commit 22fad4bb9c
6 changed files with 217 additions and 32 deletions

View File

@@ -0,0 +1,20 @@
package tracetest
import (
"testing"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
)
// NewInMemoryExporter returns a new InMemoryExporter
// and sets it as the global for tests.
func NewInMemoryExporter(t *testing.T) *tracetest.InMemoryExporter {
me := tracetest.NewInMemoryExporter()
t.Cleanup(func() {
me.Reset()
})
otel.SetTracerProvider(trace.NewTracerProvider(trace.WithSyncer(me)))
return me
}