You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(trace): add concurrent-safe Reset method to SpanRecorder - #5994
package main
import (
"context""testing""github.com/stretchr/testify/assert""go.opentelemetry.io/otel/sdk/trace""go.opentelemetry.io/otel/sdk/trace/tracetest"
)
funcTestReset(t*testing.T) {
sr:=tracetest.NewSpanRecorder()
tp:=trace.NewTracerProvider(trace.WithSpanProcessor(sr))
ctx:=context.Background()
tracer:=tp.Tracer("test")
// test one:_, span:=tracer.Start(ctx, "one")
span.End()
assert.Len(t, sr.Ended(), 1)
t.Logf("the one span length: %d", len(sr.Ended()))
// test two:sr.Reset() // <=== I don't want the result to be affected by one._, span=tracer.Start(ctx, "two")
span.End()
assert.Len(t, sr.Ended(), 1) // <=== I don't want the result to be affected by one.t.Logf("the two span length: %d", len(sr.Ended()))
}
output:
=== RUN TestReset
main_test.go:24: the one span length: 1
main_test.go:32: the two span length: 1
--- PASS: TestReset (0.00s)
PASS
Because it is a tool used for testing, I think such operations may occur.
We probably need a Reset method to reuse it for testing. Just like
InMemoryExporter.opentelemetry-go/sdk/trace/tracetest/exporter.go
Lines 61 to 65 in b99d2b8
ex:
output: