mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-18 03:22:12 +02:00
Make oteltest.SpanRecorder into a concrete type (#1542)
* Make oteltest.SpanRecorder into a concrete time * Fixes * Fix PR # * Re-run Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
parent
7d0e3e52b6
commit
0b1a1c7237
@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Replaced interface `oteltest.SpanRecorder` with its existing implementation
|
||||||
|
`StandardSpanRecorder` (#1542).
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Added `resource.Default()` for use with meter and tracer providers. (#1507)
|
- Added `resource.Default()` for use with meter and tracer providers. (#1507)
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMixedAPIs(t *testing.T) {
|
func TestMixedAPIs(t *testing.T) {
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
tracer := tp.Tracer("mixedapitracer")
|
tracer := tp.Tracer("mixedapitracer")
|
||||||
octrace.DefaultTracer = NewTracer(tracer)
|
octrace.DefaultTracer = NewTracer(tracer)
|
||||||
@ -74,7 +74,7 @@ func TestMixedAPIs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStartOptions(t *testing.T) {
|
func TestStartOptions(t *testing.T) {
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
octrace.DefaultTracer = NewTracer(tp.Tracer("startoptionstracer"))
|
octrace.DefaultTracer = NewTracer(tp.Tracer("startoptionstracer"))
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func TestStartOptions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStartSpanWithRemoteParent(t *testing.T) {
|
func TestStartSpanWithRemoteParent(t *testing.T) {
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
tracer := tp.Tracer("remoteparent")
|
tracer := tp.Tracer("remoteparent")
|
||||||
octrace.DefaultTracer = NewTracer(tracer)
|
octrace.DefaultTracer = NewTracer(tracer)
|
||||||
@ -117,7 +117,7 @@ func TestStartSpanWithRemoteParent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestToFromContext(t *testing.T) {
|
func TestToFromContext(t *testing.T) {
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
tracer := tp.Tracer("tofromcontext")
|
tracer := tp.Tracer("tofromcontext")
|
||||||
octrace.DefaultTracer = NewTracer(tracer)
|
octrace.DefaultTracer = NewTracer(tracer)
|
||||||
@ -158,7 +158,7 @@ func TestToFromContext(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIsRecordingEvents(t *testing.T) {
|
func TestIsRecordingEvents(t *testing.T) {
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
octrace.DefaultTracer = NewTracer(tp.Tracer("isrecordingevents"))
|
octrace.DefaultTracer = NewTracer(tp.Tracer("isrecordingevents"))
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ func TestIsRecordingEvents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSetThings(t *testing.T) {
|
func TestSetThings(t *testing.T) {
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
octrace.DefaultTracer = NewTracer(tp.Tracer("setthings"))
|
octrace.DefaultTracer = NewTracer(tp.Tracer("setthings"))
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func TestTraceWithSDK(t *testing.T) {
|
|||||||
// This is started before an SDK was registered and should be dropped.
|
// This is started before an SDK was registered and should be dropped.
|
||||||
_, span1 := tracer1.Start(ctx, "span1")
|
_, span1 := tracer1.Start(ctx, "span1")
|
||||||
|
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
otel.SetTracerProvider(tp)
|
otel.SetTracerProvider(tp)
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ type config struct {
|
|||||||
SpanContextFunc func(context.Context) trace.SpanContext
|
SpanContextFunc func(context.Context) trace.SpanContext
|
||||||
|
|
||||||
// SpanRecorder keeps track of spans.
|
// SpanRecorder keeps track of spans.
|
||||||
SpanRecorder SpanRecorder
|
SpanRecorder *SpanRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfig(opts ...Option) config {
|
func newConfig(opts ...Option) config {
|
||||||
@ -80,7 +80,7 @@ func WithSpanContextFunc(f func(context.Context) trace.SpanContext) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type spanRecorderOption struct {
|
type spanRecorderOption struct {
|
||||||
SpanRecorder SpanRecorder
|
SpanRecorder *SpanRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o spanRecorderOption) Apply(c *config) {
|
func (o spanRecorderOption) Apply(c *config) {
|
||||||
@ -89,22 +89,13 @@ func (o spanRecorderOption) Apply(c *config) {
|
|||||||
|
|
||||||
// WithSpanRecorder sets the SpanRecorder to use with the TracerProvider for
|
// WithSpanRecorder sets the SpanRecorder to use with the TracerProvider for
|
||||||
// testing.
|
// testing.
|
||||||
func WithSpanRecorder(sr SpanRecorder) Option {
|
func WithSpanRecorder(sr *SpanRecorder) Option {
|
||||||
return spanRecorderOption{sr}
|
return spanRecorderOption{sr}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpanRecorder performs operations to record a span as it starts and ends.
|
// SpanRecorder performs operations to record a span as it starts and ends.
|
||||||
type SpanRecorder interface {
|
// It is designed to be concurrent safe and can by used by multiple goroutines.
|
||||||
// OnStart is called by the Tracer when it starts a Span.
|
type SpanRecorder struct {
|
||||||
OnStart(span *Span)
|
|
||||||
// OnEnd is called by the Span when it ends.
|
|
||||||
OnEnd(span *Span)
|
|
||||||
}
|
|
||||||
|
|
||||||
// StandardSpanRecorder is a SpanRecorder that records all started and ended
|
|
||||||
// spans in an ordered recording. StandardSpanRecorder is designed to be
|
|
||||||
// concurrent safe and can by used by multiple goroutines.
|
|
||||||
type StandardSpanRecorder struct {
|
|
||||||
startedMu sync.RWMutex
|
startedMu sync.RWMutex
|
||||||
started []*Span
|
started []*Span
|
||||||
|
|
||||||
@ -113,21 +104,21 @@ type StandardSpanRecorder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnStart records span as started.
|
// OnStart records span as started.
|
||||||
func (ssr *StandardSpanRecorder) OnStart(span *Span) {
|
func (ssr *SpanRecorder) OnStart(span *Span) {
|
||||||
ssr.startedMu.Lock()
|
ssr.startedMu.Lock()
|
||||||
defer ssr.startedMu.Unlock()
|
defer ssr.startedMu.Unlock()
|
||||||
ssr.started = append(ssr.started, span)
|
ssr.started = append(ssr.started, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnEnd records span as completed.
|
// OnEnd records span as completed.
|
||||||
func (ssr *StandardSpanRecorder) OnEnd(span *Span) {
|
func (ssr *SpanRecorder) OnEnd(span *Span) {
|
||||||
ssr.doneMu.Lock()
|
ssr.doneMu.Lock()
|
||||||
defer ssr.doneMu.Unlock()
|
defer ssr.doneMu.Unlock()
|
||||||
ssr.done = append(ssr.done, span)
|
ssr.done = append(ssr.done, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Started returns a copy of all started Spans in the order they were started.
|
// Started returns a copy of all started Spans in the order they were started.
|
||||||
func (ssr *StandardSpanRecorder) Started() []*Span {
|
func (ssr *SpanRecorder) Started() []*Span {
|
||||||
ssr.startedMu.RLock()
|
ssr.startedMu.RLock()
|
||||||
defer ssr.startedMu.RUnlock()
|
defer ssr.startedMu.RUnlock()
|
||||||
started := make([]*Span, len(ssr.started))
|
started := make([]*Span, len(ssr.started))
|
||||||
@ -138,7 +129,7 @@ func (ssr *StandardSpanRecorder) Started() []*Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Completed returns a copy of all ended Spans in the order they were ended.
|
// Completed returns a copy of all ended Spans in the order they were ended.
|
||||||
func (ssr *StandardSpanRecorder) Completed() []*Span {
|
func (ssr *SpanRecorder) Completed() []*Span {
|
||||||
ssr.doneMu.RLock()
|
ssr.doneMu.RLock()
|
||||||
defer ssr.doneMu.RUnlock()
|
defer ssr.doneMu.RUnlock()
|
||||||
done := make([]*Span, len(ssr.done))
|
done := make([]*Span, len(ssr.done))
|
||||||
|
@ -45,7 +45,7 @@ introspection of their state and history. Additionally, a SpanRecorder can be
|
|||||||
provided to the TracerProvider to record all Spans started and ended by the
|
provided to the TracerProvider to record all Spans started and ended by the
|
||||||
testing structures.
|
testing structures.
|
||||||
|
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr))
|
||||||
*/
|
*/
|
||||||
package oteltest // import "go.opentelemetry.io/otel/oteltest"
|
package oteltest // import "go.opentelemetry.io/otel/oteltest"
|
||||||
|
@ -295,7 +295,7 @@ func testTracedSpan(t *testing.T, fn func(tracer trace.Tracer, name string) (tra
|
|||||||
|
|
||||||
e := matchers.NewExpecter(t)
|
e := matchers.NewExpecter(t)
|
||||||
|
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
subject := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)).Tracer(t.Name())
|
subject := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)).Tracer(t.Name())
|
||||||
subject.Start(context.Background(), "span1")
|
subject.Start(context.Background(), "span1")
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ func testTracedSpan(t *testing.T, fn func(tracer trace.Tracer, name string) (tra
|
|||||||
|
|
||||||
e := matchers.NewExpecter(t)
|
e := matchers.NewExpecter(t)
|
||||||
|
|
||||||
sr := new(oteltest.StandardSpanRecorder)
|
sr := new(oteltest.SpanRecorder)
|
||||||
subject := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)).Tracer(t.Name())
|
subject := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)).Tracer(t.Name())
|
||||||
|
|
||||||
numSpans := 2
|
numSpans := 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user