1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-15 01:04:25 +02:00

Rename *Provider names (#1190)

* Rename *Provider names

There is overlap in naming with MeterProviders and TracerProviders. This
is means the specification is not implemented and these types can not
exist in the same package (#1179). This makes each type and related
functions and types explicit.

* Add changes to CHANGELOG
This commit is contained in:
Tyler Yahn
2020-09-23 15:16:13 -07:00
committed by GitHub
parent 5dd2962202
commit 7d71867644
49 changed files with 276 additions and 256 deletions

View File

@ -46,6 +46,23 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Rename `go.opentelemetry.io/otel/api/metric.ConfigureInstrument` to `NewInstrumentConfig` and - Rename `go.opentelemetry.io/otel/api/metric.ConfigureInstrument` to `NewInstrumentConfig` and
`go.opentelemetry.io/otel/api/metric.ConfigureMeter` to `NewMeterConfig`. `go.opentelemetry.io/otel/api/metric.ConfigureMeter` to `NewMeterConfig`.
- Move the `go.opentelemetry.io/otel/api/unit` package to `go.opentelemetry.io/otel/unit`. (#1185) - Move the `go.opentelemetry.io/otel/api/unit` package to `go.opentelemetry.io/otel/unit`. (#1185)
- Rename `Provider` to `MeterProvider` in the `go.opentelemetry.io/otel/api/metric` package. (#1190)
- Rename `NoopProvider` to `NoopMeterProvider` in the `go.opentelemetry.io/otel/api/metric` package. (#1190)
- Rename `NewProvider` to `NewMeterProvider` in the `go.opentelemetry.io/otel/api/metric/metrictest` package. (#1190)
- Rename `Provider` to `MeterProvider` in the `go.opentelemetry.io/otel/api/metric/registry` package. (#1190)
- Rename `NewProvider` to `NewMeterProvider` in the `go.opentelemetry.io/otel/api/metri/registryc` package. (#1190)
- Rename `Provider` to `TracerProvider` in the `go.opentelemetry.io/otel/api/trace` package. (#1190)
- Rename `NoopProvider` to `NoopTracerProvider` in the `go.opentelemetry.io/otel/api/trace` package. (#1190)
- Rename `Provider` to `TracerProvider` in the `go.opentelemetry.io/otel/api/trace/tracetest` package. (#1190)
- Rename `NewProvider` to `NewTracerProvider` in the `go.opentelemetry.io/otel/api/trace/tracetest` package. (#1190)
- Rename `WrapperProvider` to `WrapperTracerProvider` in the `go.opentelemetry.io/otel/bridge/opentracing` package. (#1190)
- Rename `NewWrapperProvider` to `NewWrapperTracerProvider` in the `go.opentelemetry.io/otel/bridge/opentracing` package. (#1190)
- Rename `Provider` method of the pull controller to `MeterProvider` in the `go.opentelemetry.io/otel/sdk/metric/controller/pull` package. (#1190)
- Rename `Provider` method of the push controller to `MeterProvider` in the `go.opentelemetry.io/otel/sdk/metric/controller/push` package. (#1190)
- Rename `ProviderOptions` to `TracerProviderConfig` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190)
- Rename `ProviderOption` to `TracerProviderOption` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190)
- Rename `Provider` to `TracerProvider` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190)
- Rename `NewProvider` to `NewTracerProvider` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190)
- Renamed `SamplingDecision` values to comply with OpenTelemetry specification change. (#1192) - Renamed `SamplingDecision` values to comply with OpenTelemetry specification change. (#1192)
### Removed ### Removed

View File

@ -25,19 +25,19 @@ import (
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/label"
) )
// This file contains the forwarding implementation of metric.Provider // This file contains the forwarding implementation of MeterProvider used as
// used as the default global instance. Metric events using instruments // the default global instance. Metric events using instruments provided by
// provided by this implementation are no-ops until the first Meter // this implementation are no-ops until the first Meter implementation is set
// implementation is set as the global provider. // as the global provider.
// //
// The implementation here uses Mutexes to maintain a list of active // The implementation here uses Mutexes to maintain a list of active Meters in
// Meters in the Provider and Instruments in each Meter, under the // the MeterProvider and Instruments in each Meter, under the assumption that
// assumption that these interfaces are not performance-critical. // these interfaces are not performance-critical.
// //
// We have the invariant that setDelegate() will be called before a // We have the invariant that setDelegate() will be called before a new
// new metric.Provider implementation is registered as the global // MeterProvider implementation is registered as the global provider. Mutexes
// provider. Mutexes in the Provider and Meters ensure that each // in the MeterProvider and Meters ensure that each instrument has a delegate
// instrument has a delegate before the global provider is set. // before the global provider is set.
// //
// Bound instrument operations are implemented by delegating to the // Bound instrument operations are implemented by delegating to the
// instrument after it is registered, with a sync.Once initializer to // instrument after it is registered, with a sync.Once initializer to
@ -51,7 +51,7 @@ type meterKey struct {
} }
type meterProvider struct { type meterProvider struct {
delegate metric.Provider delegate metric.MeterProvider
// lock protects `delegate` and `meters`. // lock protects `delegate` and `meters`.
lock sync.Mutex lock sync.Mutex
@ -113,7 +113,7 @@ type syncHandle struct {
initialize sync.Once initialize sync.Once
} }
var _ metric.Provider = &meterProvider{} var _ metric.MeterProvider = &meterProvider{}
var _ metric.MeterImpl = &meterImpl{} var _ metric.MeterImpl = &meterImpl{}
var _ metric.InstrumentImpl = &syncImpl{} var _ metric.InstrumentImpl = &syncImpl{}
var _ metric.BoundSyncImpl = &syncHandle{} var _ metric.BoundSyncImpl = &syncHandle{}
@ -123,7 +123,7 @@ func (inst *instrument) Descriptor() metric.Descriptor {
return inst.descriptor return inst.descriptor
} }
// Provider interface and delegation // MeterProvider interface and delegation
func newMeterProvider() *meterProvider { func newMeterProvider() *meterProvider {
return &meterProvider{ return &meterProvider{
@ -131,7 +131,7 @@ func newMeterProvider() *meterProvider {
} }
} }
func (p *meterProvider) setDelegate(provider metric.Provider) { func (p *meterProvider) setDelegate(provider metric.MeterProvider) {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
@ -166,7 +166,7 @@ func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOp
// Meter interface and delegation // Meter interface and delegation
func (m *meterImpl) setDelegate(name, version string, provider metric.Provider) { func (m *meterImpl) setDelegate(name, version string, provider metric.MeterProvider) {
m.lock.Lock() m.lock.Lock()
defer m.lock.Unlock() defer m.lock.Unlock()

View File

@ -65,7 +65,7 @@ func TestDirect(t *testing.T) {
second.Record(ctx, 1, labels3...) second.Record(ctx, 1, labels3...)
second.Record(ctx, 2, labels3...) second.Record(ctx, 2, labels3...)
mock, provider := metrictest.NewProvider() mock, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider) global.SetMeterProvider(provider)
counter.Add(ctx, 1, labels1...) counter.Add(ctx, 1, labels1...)
@ -150,7 +150,7 @@ func TestBound(t *testing.T) {
boundM.Record(ctx, 1) boundM.Record(ctx, 1)
boundM.Record(ctx, 2) boundM.Record(ctx, 2)
mock, provider := metrictest.NewProvider() mock, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider) global.SetMeterProvider(provider)
boundC.Add(ctx, 1) boundC.Add(ctx, 1)
@ -198,7 +198,7 @@ func TestUnbindThenRecordOne(t *testing.T) {
internal.ResetForTest() internal.ResetForTest()
ctx := context.Background() ctx := context.Background()
mock, provider := metrictest.NewProvider() mock, provider := metrictest.NewMeterProvider()
meter := global.Meter("test") meter := global.Meter("test")
counter := Must(meter).NewInt64Counter("test.counter") counter := Must(meter).NewInt64Counter("test.counter")
@ -213,7 +213,7 @@ func TestUnbindThenRecordOne(t *testing.T) {
} }
type meterProviderWithConstructorError struct { type meterProviderWithConstructorError struct {
metric.Provider metric.MeterProvider
} }
type meterWithConstructorError struct { type meterWithConstructorError struct {
@ -221,7 +221,7 @@ type meterWithConstructorError struct {
} }
func (m *meterProviderWithConstructorError) Meter(iName string, opts ...metric.MeterOption) metric.Meter { func (m *meterProviderWithConstructorError) Meter(iName string, opts ...metric.MeterOption) metric.Meter {
return metric.WrapMeterImpl(&meterWithConstructorError{m.Provider.Meter(iName, opts...).MeterImpl()}, iName, opts...) return metric.WrapMeterImpl(&meterWithConstructorError{m.MeterProvider.Meter(iName, opts...).MeterImpl()}, iName, opts...)
} }
func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) { func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) {
@ -237,7 +237,7 @@ func TestErrorInDeferredConstructor(t *testing.T) {
c1 := Must(meter).NewInt64Counter("test") c1 := Must(meter).NewInt64Counter("test")
c2 := Must(meter).NewInt64Counter("test") c2 := Must(meter).NewInt64Counter("test")
_, provider := metrictest.NewProvider() _, provider := metrictest.NewMeterProvider()
sdk := &meterProviderWithConstructorError{provider} sdk := &meterProviderWithConstructorError{provider}
require.Panics(t, func() { require.Panics(t, func() {
@ -279,7 +279,7 @@ func TestImplementationIndirection(t *testing.T) {
require.False(t, ok) require.False(t, ok)
// Register the SDK // Register the SDK
_, provider := metrictest.NewProvider() _, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider) global.SetMeterProvider(provider)
// Repeat the above tests // Repeat the above tests
@ -308,7 +308,7 @@ func TestRecordBatchMock(t *testing.T) {
meter.RecordBatch(context.Background(), nil, counter.Measurement(1)) meter.RecordBatch(context.Background(), nil, counter.Measurement(1))
mock, provider := metrictest.NewProvider() mock, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider) global.SetMeterProvider(provider)
meter.RecordBatch(context.Background(), nil, counter.Measurement(1)) meter.RecordBatch(context.Background(), nil, counter.Measurement(1))

View File

@ -27,11 +27,11 @@ import (
type ( type (
tracerProviderHolder struct { tracerProviderHolder struct {
tp trace.Provider tp trace.TracerProvider
} }
meterProviderHolder struct { meterProviderHolder struct {
mp metric.Provider mp metric.MeterProvider
} }
propagatorsHolder struct { propagatorsHolder struct {
@ -49,19 +49,19 @@ var (
) )
// TracerProvider is the internal implementation for global.TracerProvider. // TracerProvider is the internal implementation for global.TracerProvider.
func TracerProvider() trace.Provider { func TracerProvider() trace.TracerProvider {
return globalTracer.Load().(tracerProviderHolder).tp return globalTracer.Load().(tracerProviderHolder).tp
} }
// SetTracerProvider is the internal implementation for global.SetTracerProvider. // SetTracerProvider is the internal implementation for global.SetTracerProvider.
func SetTracerProvider(tp trace.Provider) { func SetTracerProvider(tp trace.TracerProvider) {
delegateTraceOnce.Do(func() { delegateTraceOnce.Do(func() {
current := TracerProvider() current := TracerProvider()
if current == tp { if current == tp {
// Setting the provider to the prior default is nonsense, panic. // Setting the provider to the prior default is nonsense, panic.
// Panic is acceptable because we are likely still early in the // Panic is acceptable because we are likely still early in the
// process lifetime. // process lifetime.
panic("invalid Provider, the global instance cannot be reinstalled") panic("invalid TracerProvider, the global instance cannot be reinstalled")
} else if def, ok := current.(*tracerProvider); ok { } else if def, ok := current.(*tracerProvider); ok {
def.setDelegate(tp) def.setDelegate(tp)
} }
@ -71,12 +71,12 @@ func SetTracerProvider(tp trace.Provider) {
} }
// MeterProvider is the internal implementation for global.MeterProvider. // MeterProvider is the internal implementation for global.MeterProvider.
func MeterProvider() metric.Provider { func MeterProvider() metric.MeterProvider {
return globalMeter.Load().(meterProviderHolder).mp return globalMeter.Load().(meterProviderHolder).mp
} }
// SetMeterProvider is the internal implementation for global.SetMeterProvider. // SetMeterProvider is the internal implementation for global.SetMeterProvider.
func SetMeterProvider(mp metric.Provider) { func SetMeterProvider(mp metric.MeterProvider) {
delegateMeterOnce.Do(func() { delegateMeterOnce.Do(func() {
current := MeterProvider() current := MeterProvider()
@ -84,7 +84,7 @@ func SetMeterProvider(mp metric.Provider) {
// Setting the provider to the prior default is nonsense, panic. // Setting the provider to the prior default is nonsense, panic.
// Panic is acceptable because we are likely still early in the // Panic is acceptable because we are likely still early in the
// process lifetime. // process lifetime.
panic("invalid Provider, the global instance cannot be reinstalled") panic("invalid MeterProvider, the global instance cannot be reinstalled")
} else if def, ok := current.(*meterProvider); ok { } else if def, ok := current.(*meterProvider); ok {
def.setDelegate(mp) def.setDelegate(mp)
} }

View File

@ -15,15 +15,15 @@
package internal package internal
/* /*
This file contains the forwarding implementation of the trace.Provider used as This file contains the forwarding implementation of the TracerProvider used as
the default global instance. Prior to initialization of an SDK, Tracers the default global instance. Prior to initialization of an SDK, Tracers
returned by the global Provider will provide no-op functionality. This means returned by the global TracerProvider will provide no-op functionality. This
that all Span created prior to initialization are no-op Spans. means that all Span created prior to initialization are no-op Spans.
Once an SDK has been initialized, all provided no-op Tracers are swapped for Once an SDK has been initialized, all provided no-op Tracers are swapped for
Tracers provided by the SDK defined Provider. However, any Span started prior Tracers provided by the SDK defined TracerProvider. However, any Span started
to this initialization does not change its behavior. Meaning, the Span remains prior to this initialization does not change its behavior. Meaning, the Span
a no-op Span. remains a no-op Span.
The implementation to track and swap Tracers locks all new Tracer creation The implementation to track and swap Tracers locks all new Tracer creation
until the swap is complete. This assumes that this operation is not until the swap is complete. This assumes that this operation is not
@ -39,27 +39,30 @@ import (
"go.opentelemetry.io/otel/internal/trace/noop" "go.opentelemetry.io/otel/internal/trace/noop"
) )
// tracerProvider is a placeholder for a configured SDK Provider. // tracerProvider is a placeholder for a configured SDK TracerProvider.
// //
// All Provider functionality is forwarded to a delegate once configured. // All TracerProvider functionality is forwarded to a delegate once
// configured.
type tracerProvider struct { type tracerProvider struct {
mtx sync.Mutex mtx sync.Mutex
tracers []*tracer tracers []*tracer
delegate trace.Provider delegate trace.TracerProvider
} }
// Compile-time guarantee that tracerProvider implements the trace.Provider interface. // Compile-time guarantee that tracerProvider implements the TracerProvider
var _ trace.Provider = &tracerProvider{} // interface.
var _ trace.TracerProvider = &tracerProvider{}
// setDelegate configures p to delegate all Provider functionality to provider. // setDelegate configures p to delegate all TracerProvider functionality to
// provider.
// //
// All Tracers provided prior to this function call are switched out to be // All Tracers provided prior to this function call are switched out to be
// Tracers provided by provider. // Tracers provided by provider.
// //
// Delegation only happens on the first call to this method. All subsequent // Delegation only happens on the first call to this method. All subsequent
// calls result in no delegation changes. // calls result in no delegation changes.
func (p *tracerProvider) setDelegate(provider trace.Provider) { func (p *tracerProvider) setDelegate(provider trace.TracerProvider) {
if p.delegate != nil { if p.delegate != nil {
return return
} }
@ -75,7 +78,7 @@ func (p *tracerProvider) setDelegate(provider trace.Provider) {
p.tracers = nil p.tracers = nil
} }
// Tracer implements trace.Provider. // Tracer implements TracerProvider.
func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer { func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
p.mtx.Lock() p.mtx.Lock()
defer p.mtx.Unlock() defer p.mtx.Unlock()
@ -111,7 +114,7 @@ var _ trace.Tracer = &tracer{}
// //
// Delegation only happens on the first call to this method. All subsequent // Delegation only happens on the first call to this method. All subsequent
// calls result in no delegation changes. // calls result in no delegation changes.
func (t *tracer) setDelegate(provider trace.Provider) { func (t *tracer) setDelegate(provider trace.TracerProvider) {
t.once.Do(func() { t.delegate = provider.Tracer(t.name, t.opts...) }) t.once.Do(func() { t.delegate = provider.Tracer(t.name, t.opts...) })
} }

View File

@ -35,7 +35,7 @@ func TestTraceWithSDK(t *testing.T) {
_, span1 := tracer1.Start(ctx, "span1") _, span1 := tracer1.Start(ctx, "span1")
sr := new(tracetest.StandardSpanRecorder) sr := new(tracetest.StandardSpanRecorder)
tp := tracetest.NewProvider(tracetest.WithSpanRecorder(sr)) tp := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(sr))
global.SetTracerProvider(tp) global.SetTracerProvider(tp)
// This span was started before initialization, it is expected to be dropped. // This span was started before initialization, it is expected to be dropped.
@ -45,7 +45,7 @@ func TestTraceWithSDK(t *testing.T) {
_, span2 := tracer1.Start(ctx, "span2") _, span2 := tracer1.Start(ctx, "span2")
span2.End() span2.End()
// The global trace Provider should now create Tracers that also use the newly configured SDK. // The global TracerProvider should now create Tracers that also use the newly configured SDK.
tracer2 := gtp.Tracer("post") tracer2 := gtp.Tracer("post")
_, span3 := tracer2.Start(ctx, "span3") _, span3 := tracer2.Start(ctx, "span3")
span3.End() span3.End()

View File

@ -20,7 +20,7 @@ import (
) )
// Meter creates an implementation of the Meter interface from the global // Meter creates an implementation of the Meter interface from the global
// Provider. The instrumentationName must be the name of the library // MeterProvider. The instrumentationName must be the name of the library
// providing instrumentation. This name may be the same as the instrumented // providing instrumentation. This name may be the same as the instrumented
// code only if that code provides built-in instrumentation. If the // code only if that code provides built-in instrumentation. If the
// instrumentationName is empty, then a implementation defined default name // instrumentationName is empty, then a implementation defined default name
@ -39,11 +39,11 @@ func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter
// meter := global.MeterProvider().Meter("example.com/foo") // meter := global.MeterProvider().Meter("example.com/foo")
// or // or
// meter := global.Meter("example.com/foo") // meter := global.Meter("example.com/foo")
func MeterProvider() metric.Provider { func MeterProvider() metric.MeterProvider {
return internal.MeterProvider() return internal.MeterProvider()
} }
// SetMeterProvider registers `mp` as the global meter provider. // SetMeterProvider registers `mp` as the global meter provider.
func SetMeterProvider(mp metric.Provider) { func SetMeterProvider(mp metric.MeterProvider) {
internal.SetMeterProvider(mp) internal.SetMeterProvider(mp)
} }

View File

@ -23,7 +23,7 @@ import (
type testMeterProvider struct{} type testMeterProvider struct{}
var _ metric.Provider = &testMeterProvider{} var _ metric.MeterProvider = &testMeterProvider{}
func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter { func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter {
return metric.Meter{} return metric.Meter{}
@ -31,13 +31,13 @@ func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter
func TestMultipleGlobalMeterProvider(t *testing.T) { func TestMultipleGlobalMeterProvider(t *testing.T) {
p1 := testMeterProvider{} p1 := testMeterProvider{}
p2 := metric.NoopProvider{} p2 := metric.NoopMeterProvider{}
global.SetMeterProvider(&p1) global.SetMeterProvider(&p1)
global.SetMeterProvider(&p2) global.SetMeterProvider(&p2)
got := global.MeterProvider() got := global.MeterProvider()
want := &p2 want := &p2
if got != want { if got != want {
t.Fatalf("Provider: got %p, want %p\n", got, want) t.Fatalf("MeterProvider: got %p, want %p\n", got, want)
} }
} }

View File

@ -28,17 +28,17 @@ func Tracer(name string) trace.Tracer {
} }
// TracerProvider returns the registered global trace provider. // TracerProvider returns the registered global trace provider.
// If none is registered then an instance of trace.NoopProvider is returned. // If none is registered then an instance of NoopTracerProvider is returned.
// //
// Use the trace provider to create a named tracer. E.g. // Use the trace provider to create a named tracer. E.g.
// tracer := global.TracerProvider().Tracer("example.com/foo") // tracer := global.TracerProvider().Tracer("example.com/foo")
// or // or
// tracer := global.Tracer("example.com/foo") // tracer := global.Tracer("example.com/foo")
func TracerProvider() trace.Provider { func TracerProvider() trace.TracerProvider {
return internal.TracerProvider() return internal.TracerProvider()
} }
// SetTracerProvider registers `tp` as the global trace provider. // SetTracerProvider registers `tp` as the global trace provider.
func SetTracerProvider(tp trace.Provider) { func SetTracerProvider(tp trace.TracerProvider) {
internal.SetTracerProvider(tp) internal.SetTracerProvider(tp)
} }

View File

@ -24,7 +24,7 @@ import (
type testTracerProvider struct{} type testTracerProvider struct{}
var _ trace.Provider = &testTracerProvider{} var _ trace.TracerProvider = &testTracerProvider{}
func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer { func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
return noop.Tracer return noop.Tracer
@ -32,13 +32,13 @@ func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Trace
func TestMultipleGlobalTracerProvider(t *testing.T) { func TestMultipleGlobalTracerProvider(t *testing.T) {
p1 := testTracerProvider{} p1 := testTracerProvider{}
p2 := trace.NoopProvider() p2 := trace.NoopTracerProvider()
global.SetTracerProvider(&p1) global.SetTracerProvider(&p1)
global.SetTracerProvider(p2) global.SetTracerProvider(p2)
got := global.TracerProvider() got := global.TracerProvider()
want := p2 want := p2
if got != want { if got != want {
t.Fatalf("Provider: got %p, want %p\n", got, want) t.Fatalf("TracerProvider: got %p, want %p\n", got, want)
} }
} }

View File

@ -42,9 +42,9 @@
// //
// The Meter interface supports allocating new instruments as well as // The Meter interface supports allocating new instruments as well as
// interfaces for recording batches of synchronous measurements or // interfaces for recording batches of synchronous measurements or
// asynchronous observations. To obtain a Meter, use a Provider. // asynchronous observations. To obtain a Meter, use a MeterProvider.
// //
// The Provider interface supports obtaining a named Meter interface. // The MeterProvider interface supports obtaining a named Meter interface. To
// To obtain a Provider implementation, initialize and configure any // obtain a MeterProvider implementation, initialize and configure any
// compatible SDK. // compatible SDK.
package metric // import "go.opentelemetry.io/otel/api/metric" package metric // import "go.opentelemetry.io/otel/api/metric"

View File

@ -22,7 +22,7 @@ import (
// The file is organized as follows: // The file is organized as follows:
// //
// - Provider interface // - MeterProvider interface
// - Meter struct // - Meter struct
// - RecordBatch // - RecordBatch
// - BatchObserver // - BatchObserver
@ -31,8 +31,8 @@ import (
// - Batch asynchronous constructors (1 x int64,float64) // - Batch asynchronous constructors (1 x int64,float64)
// - Internals // - Internals
// Provider supports named Meter instances. // MeterProvider supports named Meter instances.
type Provider interface { type MeterProvider interface {
// Meter creates an implementation of the Meter interface. // Meter creates an implementation of the Meter interface.
// The instrumentationName must be the name of the library providing // The instrumentationName must be the name of the library providing
// instrumentation. This name may be the same as the instrumented code // instrumentation. This name may be the same as the instrumented code

View File

@ -113,15 +113,15 @@ func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []label.KeyValue,
}}) }})
} }
func NewProvider() (*MeterImpl, apimetric.Provider) { func NewMeterProvider() (*MeterImpl, apimetric.MeterProvider) {
impl := &MeterImpl{ impl := &MeterImpl{
asyncInstruments: NewAsyncInstrumentState(), asyncInstruments: NewAsyncInstrumentState(),
} }
return impl, registry.NewProvider(impl) return impl, registry.NewMeterProvider(impl)
} }
func NewMeter() (*MeterImpl, apimetric.Meter) { func NewMeter() (*MeterImpl, apimetric.Meter) {
impl, p := NewProvider() impl, p := NewMeterProvider()
return impl, p.Meter("mock") return impl, p.Meter("mock")
} }

View File

@ -20,19 +20,19 @@ import (
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/label"
) )
type NoopProvider struct{} type NoopMeterProvider struct{}
type noopInstrument struct{} type noopInstrument struct{}
type noopBoundInstrument struct{} type noopBoundInstrument struct{}
type NoopSync struct{ noopInstrument } type NoopSync struct{ noopInstrument }
type NoopAsync struct{ noopInstrument } type NoopAsync struct{ noopInstrument }
var _ Provider = NoopProvider{} var _ MeterProvider = NoopMeterProvider{}
var _ SyncImpl = NoopSync{} var _ SyncImpl = NoopSync{}
var _ BoundSyncImpl = noopBoundInstrument{} var _ BoundSyncImpl = noopBoundInstrument{}
var _ AsyncImpl = NoopAsync{} var _ AsyncImpl = NoopAsync{}
func (NoopProvider) Meter(_ string, _ ...MeterOption) Meter { func (NoopMeterProvider) Meter(_ string, _ ...MeterOption) Meter {
return Meter{} return Meter{}
} }

View File

@ -23,12 +23,12 @@ import (
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/label"
) )
// Provider is a standard metric.Provider for wrapping `MeterImpl` // MeterProvider is a standard MeterProvider for wrapping `MeterImpl`
type Provider struct { type MeterProvider struct {
impl metric.MeterImpl impl metric.MeterImpl
} }
var _ metric.Provider = (*Provider)(nil) var _ metric.MeterProvider = (*MeterProvider)(nil)
// uniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding // uniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding
// uniqueness checking for instrument descriptors. Use NewUniqueInstrumentMeter // uniqueness checking for instrument descriptors. Use NewUniqueInstrumentMeter
@ -47,16 +47,16 @@ type key struct {
InstrumentationVersion string InstrumentationVersion string
} }
// NewProvider returns a new provider that implements instrument // NewMeterProvider returns a new provider that implements instrument
// name-uniqueness checking. // name-uniqueness checking.
func NewProvider(impl metric.MeterImpl) *Provider { func NewMeterProvider(impl metric.MeterImpl) *MeterProvider {
return &Provider{ return &MeterProvider{
impl: NewUniqueInstrumentMeterImpl(impl), impl: NewUniqueInstrumentMeterImpl(impl),
} }
} }
// Meter implements metric.Provider. // Meter implements MeterProvider.
func (p *Provider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { func (p *MeterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
return metric.WrapMeterImpl(p.impl, instrumentationName, opts...) return metric.WrapMeterImpl(p.impl, instrumentationName, opts...)
} }

View File

@ -72,7 +72,7 @@ func unwrap(impl interface{}, err error) (metric.InstrumentImpl, error) {
func TestRegistrySameInstruments(t *testing.T) { func TestRegistrySameInstruments(t *testing.T) {
for _, nf := range allNew { for _, nf := range allNew {
_, provider := mockTest.NewProvider() _, provider := mockTest.NewMeterProvider()
meter := provider.Meter("meter") meter := provider.Meter("meter")
inst1, err1 := nf(meter, "this") inst1, err1 := nf(meter, "this")
@ -86,7 +86,7 @@ func TestRegistrySameInstruments(t *testing.T) {
func TestRegistryDifferentNamespace(t *testing.T) { func TestRegistryDifferentNamespace(t *testing.T) {
for _, nf := range allNew { for _, nf := range allNew {
_, provider := mockTest.NewProvider() _, provider := mockTest.NewMeterProvider()
meter1 := provider.Meter("meter1") meter1 := provider.Meter("meter1")
meter2 := provider.Meter("meter2") meter2 := provider.Meter("meter2")
@ -101,7 +101,7 @@ func TestRegistryDifferentNamespace(t *testing.T) {
func TestRegistryDiffInstruments(t *testing.T) { func TestRegistryDiffInstruments(t *testing.T) {
for origName, origf := range allNew { for origName, origf := range allNew {
_, provider := mockTest.NewProvider() _, provider := mockTest.NewMeterProvider()
meter := provider.Meter("meter") meter := provider.Meter("meter")
_, err := origf(meter, "this") _, err := origf(meter, "this")
@ -120,9 +120,9 @@ func TestRegistryDiffInstruments(t *testing.T) {
} }
} }
func TestProvider(t *testing.T) { func TestMeterProvider(t *testing.T) {
impl, _ := mockTest.NewMeter() impl, _ := mockTest.NewMeter()
p := registry.NewProvider(impl) p := registry.NewMeterProvider(impl)
m1 := p.Meter("m1") m1 := p.Meter("m1")
m1p := p.Meter("m1") m1p := p.Meter("m1")
m2 := p.Meter("m2") m2 := p.Meter("m2")

View File

@ -22,7 +22,8 @@ import (
"go.opentelemetry.io/otel/label" "go.opentelemetry.io/otel/label"
) )
type Provider interface { // TracerProvider provides access to instrumentation Tracers.
type TracerProvider interface {
// Tracer creates an implementation of the Tracer interface. // Tracer creates an implementation of the Tracer interface.
// The instrumentationName must be the name of the library providing // The instrumentationName must be the name of the library providing
// instrumentation. This name may be the same as the instrumented code // instrumentation. This name may be the same as the instrumented code

View File

@ -14,18 +14,17 @@
package trace package trace
type noopProvider struct{} type noopTracerProvider struct{}
var _ Provider = noopProvider{} var _ TracerProvider = noopTracerProvider{}
// Tracer returns noop implementation of Tracer. // Tracer returns noop implementation of Tracer.
func (p noopProvider) Tracer(_ string, _ ...TracerOption) Tracer { func (p noopTracerProvider) Tracer(_ string, _ ...TracerOption) Tracer {
return noopTracer{} return noopTracer{}
} }
// NoopProvider returns a noop implementation of Provider. // NoopTracerProvider returns a noop implementation of TracerProvider. The
// The Tracer and Spans created from the noop provider will // Tracer and Spans created from the noop provider will also be noop.
// also be noop. func NoopTracerProvider() TracerProvider {
func NoopProvider() Provider { return noopTracerProvider{}
return noopProvider{}
} }

View File

@ -20,17 +20,17 @@ import (
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
) )
type Provider struct { type TracerProvider struct {
config config config config
tracersMu sync.Mutex tracersMu sync.Mutex
tracers map[instrumentation]*Tracer tracers map[instrumentation]*Tracer
} }
var _ trace.Provider = (*Provider)(nil) var _ trace.TracerProvider = (*TracerProvider)(nil)
func NewProvider(opts ...Option) *Provider { func NewTracerProvider(opts ...Option) *TracerProvider {
return &Provider{ return &TracerProvider{
config: newConfig(opts...), config: newConfig(opts...),
tracers: make(map[instrumentation]*Tracer), tracers: make(map[instrumentation]*Tracer),
} }
@ -40,7 +40,7 @@ type instrumentation struct {
Name, Version string Name, Version string
} }
func (p *Provider) Tracer(instName string, opts ...trace.TracerOption) trace.Tracer { func (p *TracerProvider) Tracer(instName string, opts ...trace.TracerOption) trace.Tracer {
conf := trace.NewTracerConfig(opts...) conf := trace.NewTracerConfig(opts...)
inst := instrumentation{ inst := instrumentation{

View File

@ -32,7 +32,7 @@ import (
func TestSpan(t *testing.T) { func TestSpan(t *testing.T) {
t.Run("#Tracer", func(t *testing.T) { t.Run("#Tracer", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns the tracer used to start the span", func(t *testing.T) { t.Run("returns the tracer used to start the span", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -46,7 +46,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#End", func(t *testing.T) { t.Run("#End", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("ends the span", func(t *testing.T) { t.Run("ends the span", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -125,7 +125,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#RecordError", func(t *testing.T) { t.Run("#RecordError", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("records an error", func(t *testing.T) { t.Run("records an error", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -236,7 +236,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#IsRecording", func(t *testing.T) { t.Run("#IsRecording", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns true", func(t *testing.T) { t.Run("returns true", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -250,7 +250,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#SpanContext", func(t *testing.T) { t.Run("#SpanContext", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns a valid SpanContext", func(t *testing.T) { t.Run("returns a valid SpanContext", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -275,7 +275,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#Name", func(t *testing.T) { t.Run("#Name", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns the most recently set name on the span", func(t *testing.T) { t.Run("returns the most recently set name on the span", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -319,7 +319,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#Attributes", func(t *testing.T) { t.Run("#Attributes", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns an empty map by default", func(t *testing.T) { t.Run("returns an empty map by default", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -415,7 +415,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#Links", func(t *testing.T) { t.Run("#Links", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns an empty map by default", func(t *testing.T) { t.Run("returns an empty map by default", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -432,7 +432,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#Events", func(t *testing.T) { t.Run("#Events", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns an empty slice by default", func(t *testing.T) { t.Run("returns an empty slice by default", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -526,7 +526,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#Status", func(t *testing.T) { t.Run("#Status", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("defaults to OK", func(t *testing.T) { t.Run("defaults to OK", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -608,7 +608,7 @@ func TestSpan(t *testing.T) {
}) })
t.Run("#SpanKind", func(t *testing.T) { t.Run("#SpanKind", func(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("returns the value given at start", func(t *testing.T) { t.Run("returns the value given at start", func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -30,10 +30,10 @@ import (
) )
func TestTracer(t *testing.T) { func TestTracer(t *testing.T) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
apitest.NewHarness(t).TestTracer(func() func() trace.Tracer { apitest.NewHarness(t).TestTracer(func() func() trace.Tracer {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
var i uint64 var i uint64
return func() trace.Tracer { return func() trace.Tracer {
return tp.Tracer(fmt.Sprintf("tracer %d", atomic.AddUint64(&i, 1))) return tp.Tracer(fmt.Sprintf("tracer %d", atomic.AddUint64(&i, 1)))
@ -259,7 +259,7 @@ func TestTracer(t *testing.T) {
} }
func testTracedSpan(t *testing.T, fn func(tracer trace.Tracer, name string) (trace.Span, error)) { func testTracedSpan(t *testing.T, fn func(tracer trace.Tracer, name string) (trace.Span, error)) {
tp := tracetest.NewProvider() tp := tracetest.NewTracerProvider()
t.Run("starts a span with the expected name", func(t *testing.T) { t.Run("starts a span with the expected name", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -304,7 +304,7 @@ func testTracedSpan(t *testing.T, fn func(tracer trace.Tracer, name string) (tra
e := matchers.NewExpecter(t) e := matchers.NewExpecter(t)
sr := new(tracetest.StandardSpanRecorder) sr := new(tracetest.StandardSpanRecorder)
subject := tracetest.NewProvider(tracetest.WithSpanRecorder(sr)).Tracer(t.Name()) subject := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(sr)).Tracer(t.Name())
subject.Start(context.Background(), "span1") subject.Start(context.Background(), "span1")
e.Expect(len(sr.Started())).ToEqual(1) e.Expect(len(sr.Started())).ToEqual(1)
@ -324,7 +324,7 @@ func testTracedSpan(t *testing.T, fn func(tracer trace.Tracer, name string) (tra
e := matchers.NewExpecter(t) e := matchers.NewExpecter(t)
sr := new(tracetest.StandardSpanRecorder) sr := new(tracetest.StandardSpanRecorder)
subject := tracetest.NewProvider(tracetest.WithSpanRecorder(sr)).Tracer(t.Name()) subject := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(sr)).Tracer(t.Name())
numSpans := 2 numSpans := 2

View File

@ -20,20 +20,20 @@ import (
oteltrace "go.opentelemetry.io/otel/api/trace" oteltrace "go.opentelemetry.io/otel/api/trace"
) )
// NewTracerPair is a utility function that creates a BridgeTracer // NewTracerPair is a utility function that creates a BridgeTracer and a
// and a WrapperProvider. WrapperProvider creates a single instance of // WrapperTracerProvider. WrapperTracerProvider creates a single instance of
// WrapperTracer. The BridgeTracer forwards the calls to the WrapperTracer // WrapperTracer. The BridgeTracer forwards the calls to the WrapperTracer
// that wraps the passed tracer. BridgeTracer and WrapperProvider are returned to // that wraps the passed tracer. BridgeTracer and WrapperTracerProvider are
// the caller and the caller is expected to register BridgeTracer with opentracing and // returned to the caller and the caller is expected to register BridgeTracer
// WrapperProvider with opentelemetry. // with opentracing and WrapperTracerProvider with opentelemetry.
func NewTracerPair(tracer oteltrace.Tracer) (*BridgeTracer, *WrapperProvider) { func NewTracerPair(tracer oteltrace.Tracer) (*BridgeTracer, *WrapperTracerProvider) {
bridgeTracer := NewBridgeTracer() bridgeTracer := NewBridgeTracer()
wrapperProvider := NewWrappedProvider(bridgeTracer, tracer) wrapperProvider := NewWrappedTracerProvider(bridgeTracer, tracer)
bridgeTracer.SetOpenTelemetryTracer(wrapperProvider.Tracer("")) bridgeTracer.SetOpenTelemetryTracer(wrapperProvider.Tracer(""))
return bridgeTracer, wrapperProvider return bridgeTracer, wrapperProvider
} }
func NewTracerPairWithContext(ctx context.Context, tracer oteltrace.Tracer) (context.Context, *BridgeTracer, *WrapperProvider) { func NewTracerPairWithContext(ctx context.Context, tracer oteltrace.Tracer) (context.Context, *BridgeTracer, *WrapperTracerProvider) {
bridgeTracer, wrapperProvider := NewTracerPair(tracer) bridgeTracer, wrapperProvider := NewTracerPair(tracer)
ctx = bridgeTracer.NewHookedContext(ctx) ctx = bridgeTracer.NewHookedContext(ctx)
return ctx, bridgeTracer, wrapperProvider return ctx, bridgeTracer, wrapperProvider

View File

@ -22,21 +22,21 @@ import (
"go.opentelemetry.io/otel/bridge/opentracing/migration" "go.opentelemetry.io/otel/bridge/opentracing/migration"
) )
type WrapperProvider struct { type WrapperTracerProvider struct {
wTracer *WrapperTracer wTracer *WrapperTracer
} }
var _ oteltrace.Provider = (*WrapperProvider)(nil) var _ oteltrace.TracerProvider = (*WrapperTracerProvider)(nil)
// Tracer returns the WrapperTracer associated with the WrapperProvider. // Tracer returns the WrapperTracer associated with the WrapperTracerProvider.
func (p *WrapperProvider) Tracer(_ string, _ ...oteltrace.TracerOption) oteltrace.Tracer { func (p *WrapperTracerProvider) Tracer(_ string, _ ...oteltrace.TracerOption) oteltrace.Tracer {
return p.wTracer return p.wTracer
} }
// NewWrappedProvider creates a new trace provider that creates a single // NewWrappedTracerProvider creates a new trace provider that creates a single
// instance of WrapperTracer that wraps OpenTelemetry tracer. // instance of WrapperTracer that wraps OpenTelemetry tracer.
func NewWrappedProvider(bridge *BridgeTracer, tracer oteltrace.Tracer) *WrapperProvider { func NewWrappedTracerProvider(bridge *BridgeTracer, tracer oteltrace.Tracer) *WrapperTracerProvider {
return &WrapperProvider{ return &WrapperTracerProvider{
wTracer: NewWrapperTracer(bridge, tracer), wTracer: NewWrapperTracer(bridge, tracer),
} }
} }

View File

@ -33,7 +33,7 @@ var (
anotherKey = label.Key("ex.com/another") anotherKey = label.Key("ex.com/another")
) )
var tp *sdktrace.Provider var tp *sdktrace.TracerProvider
// initTracer creates and registers trace provider instance. // initTracer creates and registers trace provider instance.
func initTracer() { func initTracer() {
@ -43,7 +43,7 @@ func initTracer() {
log.Panicf("failed to initialize stdout exporter %v\n", err) log.Panicf("failed to initialize stdout exporter %v\n", err)
return return
} }
tp = sdktrace.NewProvider( tp = sdktrace.NewTracerProvider(
sdktrace.WithConfig( sdktrace.WithConfig(
sdktrace.Config{ sdktrace.Config{
DefaultSampler: sdktrace.AlwaysSample(), DefaultSampler: sdktrace.AlwaysSample(),

View File

@ -55,7 +55,7 @@ func initProvider() func() {
handleErr(err, "failed to create exporter") handleErr(err, "failed to create exporter")
bsp := sdktrace.NewBatchSpanProcessor(exp) bsp := sdktrace.NewBatchSpanProcessor(exp)
tracerProvider := sdktrace.NewProvider( tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithResource(resource.New( sdktrace.WithResource(resource.New(
// the service name used to display traces in backends // the service name used to display traces in backends
@ -74,7 +74,7 @@ func initProvider() func() {
) )
global.SetTracerProvider(tracerProvider) global.SetTracerProvider(tracerProvider)
global.SetMeterProvider(pusher.Provider()) global.SetMeterProvider(pusher.MeterProvider())
pusher.Start() pusher.Start()
return func() { return func() {

View File

@ -45,7 +45,7 @@ func ExampleNewExportPipeline() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
meter := exporter.Provider().Meter("example") meter := exporter.MeterProvider().Meter("example")
ctx := context.Background() ctx := context.Background()
// Use two instruments // Use two instruments

View File

@ -134,7 +134,7 @@ func InstallNewPipeline(config Config, options ...pull.Option) (*Exporter, error
if err != nil { if err != nil {
return nil, err return nil, err
} }
global.SetMeterProvider(exp.Provider()) global.SetMeterProvider(exp.MeterProvider())
return exp, nil return exp, nil
} }
@ -154,9 +154,9 @@ func (e *Exporter) SetController(config Config, options ...pull.Option) {
) )
} }
// Provider returns the metric.Provider of this exporter. // MeterProvider returns the MeterProvider of this exporter.
func (e *Exporter) Provider() metric.Provider { func (e *Exporter) MeterProvider() metric.MeterProvider {
return e.controller.Provider() return e.controller.MeterProvider()
} }
// Controller returns the controller object that coordinates collection for the SDK. // Controller returns the controller object that coordinates collection for the SDK.

View File

@ -43,7 +43,7 @@ func TestPrometheusExporter(t *testing.T) {
) )
require.NoError(t, err) require.NoError(t, err)
meter := exporter.Provider().Meter("test") meter := exporter.MeterProvider().Meter("test")
counter := metric.Must(meter).NewFloat64Counter("counter") counter := metric.Must(meter).NewFloat64Counter("counter")
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder") valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")
@ -105,7 +105,7 @@ func TestPrometheusStatefulness(t *testing.T) {
) )
require.NoError(t, err) require.NoError(t, err)
meter := exporter.Provider().Meter("test") meter := exporter.MeterProvider().Meter("test")
// GET the HTTP endpoint // GET the HTTP endpoint
scrape := func() string { scrape := func() string {

View File

@ -41,16 +41,16 @@ func main() {
}() }()
// Note: The exporter can also be used as a Batcher. E.g. // Note: The exporter can also be used as a Batcher. E.g.
// tracerProvider := sdktrace.NewProvider( // tracerProvider := sdktrace.NewTracerProvider(
// sdktrace.WithBatcher(exporter, // sdktrace.WithBatcher(exporter,
// sdktrace.WithBatchTimeout(time.Second*15), // sdktrace.WithBatchTimeout(time.Second*15),
// sdktrace.WithMaxExportBatchSize(100), // sdktrace.WithMaxExportBatchSize(100),
// ), // ),
// ) // )
tracerProvider := sdktrace.NewProvider(sdktrace.WithBatcher(exporter)) tracerProvider := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
pusher := push.New(simple.NewWithExactDistribution(), exporter) pusher := push.New(simple.NewWithExactDistribution(), exporter)
pusher.Start() pusher.Start()
metricProvider := pusher.Provider() metricProvider := pusher.MeterProvider()
// Your code here ... // Your code here ...
} }

View File

@ -40,7 +40,7 @@ func Example_insecure() {
} }
}() }()
tp := sdktrace.NewProvider( tp := sdktrace.NewTracerProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher( sdktrace.WithBatcher(
exp, exp,
@ -84,7 +84,7 @@ func Example_withTLS() {
} }
}() }()
tp := sdktrace.NewProvider( tp := sdktrace.NewTracerProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher( sdktrace.WithBatcher(
exp, exp,

View File

@ -86,7 +86,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
} }
}() }()
pOpts := []sdktrace.ProviderOption{ pOpts := []sdktrace.TracerProviderOption{
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher( sdktrace.WithBatcher(
exp, exp,
@ -95,13 +95,13 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
sdktrace.WithMaxExportBatchSize(10), sdktrace.WithMaxExportBatchSize(10),
), ),
} }
tp1 := sdktrace.NewProvider(append(pOpts, tp1 := sdktrace.NewTracerProvider(append(pOpts,
sdktrace.WithResource(resource.New( sdktrace.WithResource(resource.New(
label.String("rk1", "rv11)"), label.String("rk1", "rv11)"),
label.Int64("rk2", 5), label.Int64("rk2", 5),
)))...) )))...)
tp2 := sdktrace.NewProvider(append(pOpts, tp2 := sdktrace.NewTracerProvider(append(pOpts,
sdktrace.WithResource(resource.New( sdktrace.WithResource(resource.New(
label.String("rk1", "rv12)"), label.String("rk1", "rv12)"),
label.Float32("rk3", 6.5), label.Float32("rk3", 6.5),
@ -127,7 +127,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
pusher.Start() pusher.Start()
ctx := context.Background() ctx := context.Background()
meter := pusher.Provider().Meter("test-meter") meter := pusher.MeterProvider().Meter("test-meter")
labels := []label.KeyValue{label.Bool("test", true)} labels := []label.KeyValue{label.Bool("test", true)}
type data struct { type data struct {
@ -462,7 +462,7 @@ func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
_ = exp.Shutdown(context.Background()) _ = exp.Shutdown(context.Background())
}() }()
tp := sdktrace.NewProvider( tp := sdktrace.NewTracerProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher( sdktrace.WithBatcher(
exp, exp,

View File

@ -50,13 +50,13 @@ func NewExporter(options ...Option) (*Exporter, error) {
// NewExportPipeline creates a complete export pipeline with the default // NewExportPipeline creates a complete export pipeline with the default
// selectors, processors, and trace registration. It is the responsibility // selectors, processors, and trace registration. It is the responsibility
// of the caller to stop the returned push Controller. // of the caller to stop the returned push Controller.
func NewExportPipeline(exportOpts []Option, pushOpts []push.Option) (apitrace.Provider, *push.Controller, error) { func NewExportPipeline(exportOpts []Option, pushOpts []push.Option) (apitrace.TracerProvider, *push.Controller, error) {
exporter, err := NewExporter(exportOpts...) exporter, err := NewExporter(exportOpts...)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
tp := sdktrace.NewProvider(sdktrace.WithBatcher(exporter)) tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
pusher := push.New( pusher := push.New(
basic.New( basic.New(
simple.NewWithExactDistribution(), simple.NewWithExactDistribution(),
@ -88,6 +88,6 @@ func InstallNewPipeline(exportOpts []Option, pushOpts []push.Option) (*push.Cont
return controller, err return controller, err
} }
global.SetTracerProvider(tracerProvider) global.SetTracerProvider(tracerProvider)
global.SetMeterProvider(controller.Provider()) global.SetMeterProvider(controller.MeterProvider())
return controller, err return controller, err
} }

View File

@ -151,14 +151,14 @@ func NewRawExporter(endpointOption EndpointOption, opts ...Option) (*Exporter, e
// NewExportPipeline sets up a complete export pipeline // NewExportPipeline sets up a complete export pipeline
// with the recommended setup for trace provider // with the recommended setup for trace provider
func NewExportPipeline(endpointOption EndpointOption, opts ...Option) (apitrace.Provider, func(), error) { func NewExportPipeline(endpointOption EndpointOption, opts ...Option) (apitrace.TracerProvider, func(), error) {
o := options{} o := options{}
opts = append(opts, WithDisabledFromEnv()) opts = append(opts, WithDisabledFromEnv())
for _, opt := range opts { for _, opt := range opts {
opt(&o) opt(&o)
} }
if o.Disabled { if o.Disabled {
return apitrace.NoopProvider(), func() {}, nil return apitrace.NoopTracerProvider(), func() {}, nil
} }
exporter, err := NewRawExporter(endpointOption, opts...) exporter, err := NewRawExporter(endpointOption, opts...)
@ -166,11 +166,11 @@ func NewExportPipeline(endpointOption EndpointOption, opts ...Option) (apitrace.
return nil, nil, err return nil, nil, err
} }
pOpts := []sdktrace.ProviderOption{sdktrace.WithSyncer(exporter)} pOpts := []sdktrace.TracerProviderOption{sdktrace.WithSyncer(exporter)}
if exporter.o.Config != nil { if exporter.o.Config != nil {
pOpts = append(pOpts, sdktrace.WithConfig(*exporter.o.Config)) pOpts = append(pOpts, sdktrace.WithConfig(*exporter.o.Config))
} }
tp := sdktrace.NewProvider(pOpts...) tp := sdktrace.NewTracerProvider(pOpts...)
return tp, exporter.Flush, nil return tp, exporter.Flush, nil
} }

View File

@ -51,17 +51,17 @@ func TestInstallNewPipeline(t *testing.T) {
name string name string
endpoint EndpointOption endpoint EndpointOption
options []Option options []Option
expectedProvider trace.Provider expectedProvider trace.TracerProvider
}{ }{
{ {
name: "simple pipeline", name: "simple pipeline",
endpoint: WithCollectorEndpoint(collectorEndpoint), endpoint: WithCollectorEndpoint(collectorEndpoint),
expectedProvider: &sdktrace.Provider{}, expectedProvider: &sdktrace.TracerProvider{},
}, },
{ {
name: "with agent endpoint", name: "with agent endpoint",
endpoint: WithAgentEndpoint(agentEndpoint), endpoint: WithAgentEndpoint(agentEndpoint),
expectedProvider: &sdktrace.Provider{}, expectedProvider: &sdktrace.TracerProvider{},
}, },
{ {
name: "with disabled", name: "with disabled",
@ -69,7 +69,7 @@ func TestInstallNewPipeline(t *testing.T) {
options: []Option{ options: []Option{
WithDisabled(true), WithDisabled(true),
}, },
expectedProvider: apitrace.NoopProvider(), expectedProvider: apitrace.NoopTracerProvider(),
}, },
} }
@ -94,13 +94,13 @@ func TestNewExportPipeline(t *testing.T) {
name string name string
endpoint EndpointOption endpoint EndpointOption
options []Option options []Option
expectedProviderType trace.Provider expectedProviderType trace.TracerProvider
testSpanSampling, spanShouldBeSampled bool testSpanSampling, spanShouldBeSampled bool
}{ }{
{ {
name: "simple pipeline", name: "simple pipeline",
endpoint: WithCollectorEndpoint(collectorEndpoint), endpoint: WithCollectorEndpoint(collectorEndpoint),
expectedProviderType: &sdktrace.Provider{}, expectedProviderType: &sdktrace.TracerProvider{},
}, },
{ {
name: "with disabled", name: "with disabled",
@ -108,7 +108,7 @@ func TestNewExportPipeline(t *testing.T) {
options: []Option{ options: []Option{
WithDisabled(true), WithDisabled(true),
}, },
expectedProviderType: apitrace.NoopProvider(), expectedProviderType: apitrace.NoopTracerProvider(),
}, },
{ {
name: "always on", name: "always on",
@ -118,7 +118,7 @@ func TestNewExportPipeline(t *testing.T) {
DefaultSampler: sdktrace.AlwaysSample(), DefaultSampler: sdktrace.AlwaysSample(),
}), }),
}, },
expectedProviderType: &sdktrace.Provider{}, expectedProviderType: &sdktrace.TracerProvider{},
testSpanSampling: true, testSpanSampling: true,
spanShouldBeSampled: true, spanShouldBeSampled: true,
}, },
@ -130,7 +130,7 @@ func TestNewExportPipeline(t *testing.T) {
DefaultSampler: sdktrace.NeverSample(), DefaultSampler: sdktrace.NeverSample(),
}), }),
}, },
expectedProviderType: &sdktrace.Provider{}, expectedProviderType: &sdktrace.TracerProvider{},
testSpanSampling: true, testSpanSampling: true,
spanShouldBeSampled: false, spanShouldBeSampled: false,
}, },
@ -173,7 +173,7 @@ func TestNewExportPipelineWithDisabledFromEnv(t *testing.T) {
) )
defer fn() defer fn()
assert.NoError(t, err) assert.NoError(t, err)
assert.IsType(t, apitrace.NoopProvider(), tp) assert.IsType(t, apitrace.NoopTracerProvider(), tp)
} }
func TestNewRawExporter(t *testing.T) { func TestNewRawExporter(t *testing.T) {
@ -339,7 +339,7 @@ func TestExporter_ExportSpan(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
tp := sdktrace.NewProvider( tp := sdktrace.NewTracerProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithSyncer(exp), sdktrace.WithSyncer(exp),
) )

View File

@ -111,13 +111,13 @@ func NewRawExporter(collectorURL, serviceName string, opts ...Option) (*Exporter
// NewExportPipeline sets up a complete export pipeline // NewExportPipeline sets up a complete export pipeline
// with the recommended setup for trace provider // with the recommended setup for trace provider
func NewExportPipeline(collectorURL, serviceName string, opts ...Option) (*sdktrace.Provider, error) { func NewExportPipeline(collectorURL, serviceName string, opts ...Option) (*sdktrace.TracerProvider, error) {
exp, err := NewRawExporter(collectorURL, serviceName, opts...) exp, err := NewRawExporter(collectorURL, serviceName, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
tp := sdktrace.NewProvider(sdktrace.WithBatcher(exp)) tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exp))
if exp.o.config != nil { if exp.o.config != nil {
tp.ApplyConfig(*exp.o.config) tp.ApplyConfig(*exp.o.config)
} }

View File

@ -48,7 +48,7 @@ func TestInstallNewPipeline(t *testing.T) {
serviceName, serviceName,
) )
assert.NoError(t, err) assert.NoError(t, err)
assert.IsType(t, &sdktrace.Provider{}, global.TracerProvider()) assert.IsType(t, &sdktrace.TracerProvider{}, global.TracerProvider())
} }
func TestNewExportPipeline(t *testing.T) { func TestNewExportPipeline(t *testing.T) {

View File

@ -30,6 +30,6 @@ var (
) )
func init() { func init() {
Tracer = trace.NoopProvider().Tracer("") Tracer = trace.NoopTracerProvider().Tracer("")
_, Span = Tracer.Start(context.Background(), "") _, Span = Tracer.Start(context.Background(), "")
} }

View File

@ -30,13 +30,13 @@ import (
// will be returned without gathering metric data again. // will be returned without gathering metric data again.
const DefaultCachePeriod time.Duration = 10 * time.Second const DefaultCachePeriod time.Duration = 10 * time.Second
// Controller manages access to a *sdk.Accumulator and // Controller manages access to a *sdk.Accumulator and *basic.Processor. Use
// *basic.Processor. Use Provider() for obtaining Meters. Use // MeterProvider() for obtaining Meters. Use Foreach() for accessing current
// Foreach() for accessing current records. // records.
type Controller struct { type Controller struct {
accumulator *sdk.Accumulator accumulator *sdk.Accumulator
checkpointer export.Checkpointer checkpointer export.Checkpointer
provider *registry.Provider provider *registry.MeterProvider
period time.Duration period time.Duration
lastCollect time.Time lastCollect time.Time
clock controllerTime.Clock clock controllerTime.Clock
@ -65,7 +65,7 @@ func New(checkpointer export.Checkpointer, options ...Option) *Controller {
return &Controller{ return &Controller{
accumulator: accum, accumulator: accum,
checkpointer: checkpointer, checkpointer: checkpointer,
provider: registry.NewProvider(accum), provider: registry.NewMeterProvider(accum),
period: config.CachePeriod, period: config.CachePeriod,
checkpoint: checkpointer.CheckpointSet(), checkpoint: checkpointer.CheckpointSet(),
clock: controllerTime.RealClock{}, clock: controllerTime.RealClock{},
@ -79,9 +79,9 @@ func (c *Controller) SetClock(clock controllerTime.Clock) {
c.clock = clock c.clock = clock
} }
// Provider returns a metric.Provider for the implementation managed // MeterProvider returns a MeterProvider for the implementation managed by
// by this controller. // this controller.
func (c *Controller) Provider() metric.Provider { func (c *Controller) MeterProvider() metric.MeterProvider {
return c.provider return c.provider
} }

View File

@ -43,7 +43,7 @@ func TestPullNoCache(t *testing.T) {
) )
ctx := context.Background() ctx := context.Background()
meter := puller.Provider().Meter("nocache") meter := puller.MeterProvider().Meter("nocache")
counter := metric.Must(meter).NewInt64Counter("counter.sum") counter := metric.Must(meter).NewInt64Counter("counter.sum")
counter.Add(ctx, 10, label.String("A", "B")) counter.Add(ctx, 10, label.String("A", "B"))
@ -80,7 +80,7 @@ func TestPullWithCache(t *testing.T) {
puller.SetClock(mock) puller.SetClock(mock)
ctx := context.Background() ctx := context.Background()
meter := puller.Provider().Meter("nocache") meter := puller.MeterProvider().Meter("nocache")
counter := metric.Must(meter).NewInt64Counter("counter.sum") counter := metric.Must(meter).NewInt64Counter("counter.sum")
counter.Add(ctx, 10, label.String("A", "B")) counter.Add(ctx, 10, label.String("A", "B"))

View File

@ -34,7 +34,7 @@ const DefaultPushPeriod = 10 * time.Second
type Controller struct { type Controller struct {
lock sync.Mutex lock sync.Mutex
accumulator *sdk.Accumulator accumulator *sdk.Accumulator
provider *registry.Provider provider *registry.MeterProvider
checkpointer export.Checkpointer checkpointer export.Checkpointer
exporter export.Exporter exporter export.Exporter
wg sync.WaitGroup wg sync.WaitGroup
@ -45,9 +45,9 @@ type Controller struct {
ticker controllerTime.Ticker ticker controllerTime.Ticker
} }
// New constructs a Controller, an implementation of metric.Provider, // New constructs a Controller, an implementation of MeterProvider, using the
// using the provided checkpointer, exporter, and options to configure // provided checkpointer, exporter, and options to configure an SDK with
// an SDK with periodic collection. // periodic collection.
func New(checkpointer export.Checkpointer, exporter export.Exporter, opts ...Option) *Controller { func New(checkpointer export.Checkpointer, exporter export.Exporter, opts ...Option) *Controller {
c := &Config{ c := &Config{
Period: DefaultPushPeriod, Period: DefaultPushPeriod,
@ -64,7 +64,7 @@ func New(checkpointer export.Checkpointer, exporter export.Exporter, opts ...Opt
sdk.WithResource(c.Resource), sdk.WithResource(c.Resource),
) )
return &Controller{ return &Controller{
provider: registry.NewProvider(impl), provider: registry.NewMeterProvider(impl),
accumulator: impl, accumulator: impl,
checkpointer: checkpointer, checkpointer: checkpointer,
exporter: exporter, exporter: exporter,
@ -83,8 +83,8 @@ func (c *Controller) SetClock(clock controllerTime.Clock) {
c.clock = clock c.clock = clock
} }
// Provider returns a metric.Provider instance for this controller. // MeterProvider returns a MeterProvider instance for this controller.
func (c *Controller) Provider() metric.Provider { func (c *Controller) MeterProvider() metric.MeterProvider {
return c.provider return c.provider
} }

View File

@ -107,7 +107,7 @@ func TestPushTicker(t *testing.T) {
push.WithPeriod(time.Second), push.WithPeriod(time.Second),
push.WithResource(testResource), push.WithResource(testResource),
) )
meter := p.Provider().Meter("name") meter := p.MeterProvider().Meter("name")
mock := controllertest.NewMockClock() mock := controllertest.NewMockClock()
p.SetClock(mock) p.SetClock(mock)
@ -193,7 +193,7 @@ func TestPushExportError(t *testing.T) {
ctx := context.Background() ctx := context.Background()
meter := p.Provider().Meter("name") meter := p.MeterProvider().Meter("name")
counter1 := metric.Must(meter).NewInt64Counter("counter1.sum") counter1 := metric.Must(meter).NewInt64Counter("counter1.sum")
counter2 := metric.Must(meter).NewInt64Counter("counter2.sum") counter2 := metric.Must(meter).NewInt64Counter("counter2.sum")

View File

@ -153,7 +153,7 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
for _, option := range options { for _, option := range options {
t.Run(option.name, func(t *testing.T) { t.Run(option.name, func(t *testing.T) {
te := testBatchExporter{} te := testBatchExporter{}
tp := basicProvider(t) tp := basicTracerProvider(t)
ssp := createAndRegisterBatchSP(option, &te) ssp := createAndRegisterBatchSP(option, &te)
if ssp == nil { if ssp == nil {
t.Fatalf("%s: Error creating new instance of BatchSpanProcessor\n", option.name) t.Fatalf("%s: Error creating new instance of BatchSpanProcessor\n", option.name)

View File

@ -166,6 +166,6 @@ func traceBenchmark(b *testing.B, name string, fn func(*testing.B, apitrace.Trac
} }
func tracer(b *testing.B, name string, sampler sdktrace.Sampler) apitrace.Tracer { func tracer(b *testing.B, name string, sampler sdktrace.Sampler) apitrace.Tracer {
tp := sdktrace.NewProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sampler})) tp := sdktrace.NewTracerProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sampler}))
return tp.Tracer(name) return tp.Tracer(name)
} }

View File

@ -33,34 +33,34 @@ const (
// TODO (MrAlias): unify this API option design: // TODO (MrAlias): unify this API option design:
// https://github.com/open-telemetry/opentelemetry-go/issues/536 // https://github.com/open-telemetry/opentelemetry-go/issues/536
// ProviderOptions // TracerProviderConfig
type ProviderOptions struct { type TracerProviderConfig struct {
processors []SpanProcessor processors []SpanProcessor
config Config config Config
} }
type ProviderOption func(*ProviderOptions) type TracerProviderOption func(*TracerProviderConfig)
type Provider struct { type TracerProvider struct {
mu sync.Mutex mu sync.Mutex
namedTracer map[instrumentation.Library]*tracer namedTracer map[instrumentation.Library]*tracer
spanProcessors atomic.Value spanProcessors atomic.Value
config atomic.Value // access atomically config atomic.Value // access atomically
} }
var _ apitrace.Provider = &Provider{} var _ apitrace.TracerProvider = &TracerProvider{}
// NewProvider creates an instance of trace provider. Optional // NewTracerProvider creates an instance of trace provider. Optional
// parameter configures the provider with common options applicable // parameter configures the provider with common options applicable
// to all tracer instances that will be created by this provider. // to all tracer instances that will be created by this provider.
func NewProvider(opts ...ProviderOption) *Provider { func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider {
o := &ProviderOptions{} o := &TracerProviderConfig{}
for _, opt := range opts { for _, opt := range opts {
opt(o) opt(o)
} }
tp := &Provider{ tp := &TracerProvider{
namedTracer: make(map[instrumentation.Library]*tracer), namedTracer: make(map[instrumentation.Library]*tracer),
} }
tp.config.Store(&Config{ tp.config.Store(&Config{
@ -82,7 +82,7 @@ func NewProvider(opts ...ProviderOption) *Provider {
// Tracer with the given name. If a tracer for the given name does not exist, // Tracer with the given name. If a tracer for the given name does not exist,
// it is created first. If the name is empty, DefaultTracerName is used. // it is created first. If the name is empty, DefaultTracerName is used.
func (p *Provider) Tracer(name string, opts ...apitrace.TracerOption) apitrace.Tracer { func (p *TracerProvider) Tracer(name string, opts ...apitrace.TracerOption) apitrace.Tracer {
c := trace.NewTracerConfig(opts...) c := trace.NewTracerConfig(opts...)
p.mu.Lock() p.mu.Lock()
@ -106,7 +106,7 @@ func (p *Provider) Tracer(name string, opts ...apitrace.TracerOption) apitrace.T
} }
// RegisterSpanProcessor adds the given SpanProcessor to the list of SpanProcessors // RegisterSpanProcessor adds the given SpanProcessor to the list of SpanProcessors
func (p *Provider) RegisterSpanProcessor(s SpanProcessor) { func (p *TracerProvider) RegisterSpanProcessor(s SpanProcessor) {
p.mu.Lock() p.mu.Lock()
defer p.mu.Unlock() defer p.mu.Unlock()
new := make(spanProcessorMap) new := make(spanProcessorMap)
@ -120,7 +120,7 @@ func (p *Provider) RegisterSpanProcessor(s SpanProcessor) {
} }
// UnregisterSpanProcessor removes the given SpanProcessor from the list of SpanProcessors // UnregisterSpanProcessor removes the given SpanProcessor from the list of SpanProcessors
func (p *Provider) UnregisterSpanProcessor(s SpanProcessor) { func (p *TracerProvider) UnregisterSpanProcessor(s SpanProcessor) {
p.mu.Lock() p.mu.Lock()
defer p.mu.Unlock() defer p.mu.Unlock()
new := make(spanProcessorMap) new := make(spanProcessorMap)
@ -140,7 +140,7 @@ func (p *Provider) UnregisterSpanProcessor(s SpanProcessor) {
// ApplyConfig changes the configuration of the provider. // ApplyConfig changes the configuration of the provider.
// If a field in the configuration is empty or nil then its original value is preserved. // If a field in the configuration is empty or nil then its original value is preserved.
func (p *Provider) ApplyConfig(cfg Config) { func (p *TracerProvider) ApplyConfig(cfg Config) {
p.mu.Lock() p.mu.Lock()
defer p.mu.Unlock() defer p.mu.Unlock()
c := *p.config.Load().(*Config) c := *p.config.Load().(*Config)
@ -165,36 +165,36 @@ func (p *Provider) ApplyConfig(cfg Config) {
p.config.Store(&c) p.config.Store(&c)
} }
// WithSyncer registers the exporter with the Provider using a // WithSyncer registers the exporter with the TracerProvider using a
// SimpleSpanProcessor. // SimpleSpanProcessor.
func WithSyncer(e export.SpanExporter) ProviderOption { func WithSyncer(e export.SpanExporter) TracerProviderOption {
return WithSpanProcessor(NewSimpleSpanProcessor(e)) return WithSpanProcessor(NewSimpleSpanProcessor(e))
} }
// WithBatcher registers the exporter with the Provider using a // WithBatcher registers the exporter with the TracerProvider using a
// BatchSpanProcessor configured with the passed opts. // BatchSpanProcessor configured with the passed opts.
func WithBatcher(e export.SpanExporter, opts ...BatchSpanProcessorOption) ProviderOption { func WithBatcher(e export.SpanExporter, opts ...BatchSpanProcessorOption) TracerProviderOption {
return WithSpanProcessor(NewBatchSpanProcessor(e, opts...)) return WithSpanProcessor(NewBatchSpanProcessor(e, opts...))
} }
// WithSpanProcessor registers the SpanProcessor with a Provider. // WithSpanProcessor registers the SpanProcessor with a TracerProvider.
func WithSpanProcessor(sp SpanProcessor) ProviderOption { func WithSpanProcessor(sp SpanProcessor) TracerProviderOption {
return func(opts *ProviderOptions) { return func(opts *TracerProviderConfig) {
opts.processors = append(opts.processors, sp) opts.processors = append(opts.processors, sp)
} }
} }
// WithConfig option sets the configuration to provider. // WithConfig option sets the configuration to provider.
func WithConfig(config Config) ProviderOption { func WithConfig(config Config) TracerProviderOption {
return func(opts *ProviderOptions) { return func(opts *TracerProviderConfig) {
opts.config = config opts.config = config
} }
} }
// WithResource option attaches a resource to the provider. // WithResource option attaches a resource to the provider.
// The resource is added to the span when it is started. // The resource is added to the span when it is started.
func WithResource(r *resource.Resource) ProviderOption { func WithResource(r *resource.Resource) TracerProviderOption {
return func(opts *ProviderOptions) { return func(opts *TracerProviderConfig) {
opts.config.Resource = r opts.config.Resource = r
} }
} }

View File

@ -51,7 +51,7 @@ func TestNewSimpleSpanProcessorWithNilExporter(t *testing.T) {
} }
func TestSimpleSpanProcessorOnEnd(t *testing.T) { func TestSimpleSpanProcessorOnEnd(t *testing.T) {
tp := basicProvider(t) tp := basicTracerProvider(t)
te := testExporter{} te := testExporter{}
ssp := sdktrace.NewSimpleSpanProcessor(&te) ssp := sdktrace.NewSimpleSpanProcessor(&te)
if ssp == nil { if ssp == nil {

View File

@ -44,7 +44,7 @@ func (t *testSpanProcesor) ForceFlush() {
func TestRegisterSpanProcessort(t *testing.T) { func TestRegisterSpanProcessort(t *testing.T) {
name := "Register span processor before span starts" name := "Register span processor before span starts"
tp := basicProvider(t) tp := basicTracerProvider(t)
sp := NewTestSpanProcessor() sp := NewTestSpanProcessor()
tp.RegisterSpanProcessor(sp) tp.RegisterSpanProcessor(sp)
@ -64,7 +64,7 @@ func TestRegisterSpanProcessort(t *testing.T) {
func TestUnregisterSpanProcessor(t *testing.T) { func TestUnregisterSpanProcessor(t *testing.T) {
name := "Start span after unregistering span processor" name := "Start span after unregistering span processor"
tp := basicProvider(t) tp := basicTracerProvider(t)
sp := NewTestSpanProcessor() sp := NewTestSpanProcessor()
tp.RegisterSpanProcessor(sp) tp.RegisterSpanProcessor(sp)
@ -91,7 +91,7 @@ func TestUnregisterSpanProcessor(t *testing.T) {
func TestUnregisterSpanProcessorWhileSpanIsActive(t *testing.T) { func TestUnregisterSpanProcessorWhileSpanIsActive(t *testing.T) {
name := "Unregister span processor while span is active" name := "Unregister span processor while span is active"
tp := basicProvider(t) tp := basicTracerProvider(t)
sp := NewTestSpanProcessor() sp := NewTestSpanProcessor()
tp.RegisterSpanProcessor(sp) tp.RegisterSpanProcessor(sp)
@ -116,7 +116,7 @@ func TestUnregisterSpanProcessorWhileSpanIsActive(t *testing.T) {
func TestSpanProcessorShutdown(t *testing.T) { func TestSpanProcessorShutdown(t *testing.T) {
name := "Increment shutdown counter of a span processor" name := "Increment shutdown counter of a span processor"
tp := basicProvider(t) tp := basicTracerProvider(t)
sp := NewTestSpanProcessor() sp := NewTestSpanProcessor()
if sp == nil { if sp == nil {
t.Fatalf("Error creating new instance of TestSpanProcessor\n") t.Fatalf("Error creating new instance of TestSpanProcessor\n")
@ -134,7 +134,7 @@ func TestSpanProcessorShutdown(t *testing.T) {
func TestMultipleUnregisterSpanProcessorCalls(t *testing.T) { func TestMultipleUnregisterSpanProcessorCalls(t *testing.T) {
name := "Increment shutdown counter after first UnregisterSpanProcessor call" name := "Increment shutdown counter after first UnregisterSpanProcessor call"
tp := basicProvider(t) tp := basicTracerProvider(t)
sp := NewTestSpanProcessor() sp := NewTestSpanProcessor()
if sp == nil { if sp == nil {
t.Fatalf("Error creating new instance of TestSpanProcessor\n") t.Fatalf("Error creating new instance of TestSpanProcessor\n")

View File

@ -60,7 +60,7 @@ func init() {
} }
func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) { func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) {
tp := NewProvider(WithConfig(Config{DefaultSampler: TraceIDRatioBased(0)})) tp := NewTracerProvider(WithConfig(Config{DefaultSampler: TraceIDRatioBased(0)}))
harness := apitest.NewHarness(t) harness := apitest.NewHarness(t)
subjectFactory := func() trace.Tracer { subjectFactory := func() trace.Tracer {
return tp.Tracer("") return tp.Tracer("")
@ -151,7 +151,7 @@ func (ts testSampler) Description() string {
func TestSetName(t *testing.T) { func TestSetName(t *testing.T) {
fooSampler := &testSampler{prefix: "foo", t: t} fooSampler := &testSampler{prefix: "foo", t: t}
tp := NewProvider(WithConfig(Config{DefaultSampler: fooSampler})) tp := NewTracerProvider(WithConfig(Config{DefaultSampler: fooSampler}))
type testCase struct { type testCase struct {
name string name string
@ -206,7 +206,7 @@ func TestSetName(t *testing.T) {
} }
func TestRecordingIsOn(t *testing.T) { func TestRecordingIsOn(t *testing.T) {
tp := NewProvider() tp := NewTracerProvider()
_, span := tp.Tracer("Recording on").Start(context.Background(), "StartSpan") _, span := tp.Tracer("Recording on").Start(context.Background(), "StartSpan")
defer span.End() defer span.End()
if span.IsRecording() == false { if span.IsRecording() == false {
@ -259,7 +259,7 @@ func TestSampling(t *testing.T) {
tc := tc tc := tc
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
t.Parallel() t.Parallel()
p := NewProvider(WithConfig(Config{DefaultSampler: tc.sampler})) p := NewTracerProvider(WithConfig(Config{DefaultSampler: tc.sampler}))
tr := p.Tracer("test") tr := p.Tracer("test")
var sampled int var sampled int
for i := 0; i < total; i++ { for i := 0; i < total; i++ {
@ -297,7 +297,7 @@ func TestSampling(t *testing.T) {
} }
func TestStartSpanWithParent(t *testing.T) { func TestStartSpanWithParent(t *testing.T) {
tp := NewProvider() tp := NewTracerProvider()
tr := tp.Tracer("SpanWithParent") tr := tp.Tracer("SpanWithParent")
ctx := context.Background() ctx := context.Background()
@ -341,7 +341,7 @@ func TestStartSpanWithParent(t *testing.T) {
func TestSetSpanAttributesOnStart(t *testing.T) { func TestSetSpanAttributesOnStart(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, span := startSpan(tp,
"StartSpanAttribute", "StartSpanAttribute",
apitrace.WithAttributes(label.String("key1", "value1")), apitrace.WithAttributes(label.String("key1", "value1")),
@ -374,7 +374,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) {
func TestSetSpanAttributes(t *testing.T) { func TestSetSpanAttributes(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "SpanAttribute") span := startSpan(tp, "SpanAttribute")
span.SetAttributes(label.String("key1", "value1")) span.SetAttributes(label.String("key1", "value1"))
got, err := endSpan(te, span) got, err := endSpan(te, span)
@ -404,7 +404,7 @@ func TestSetSpanAttributes(t *testing.T) {
func TestSetSpanAttributesOverLimit(t *testing.T) { func TestSetSpanAttributesOverLimit(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
cfg := Config{MaxAttributesPerSpan: 2} cfg := Config{MaxAttributesPerSpan: 2}
tp := NewProvider(WithConfig(cfg), WithSyncer(te)) tp := NewTracerProvider(WithConfig(cfg), WithSyncer(te))
span := startSpan(tp, "SpanAttributesOverLimit") span := startSpan(tp, "SpanAttributesOverLimit")
span.SetAttributes( span.SetAttributes(
@ -441,7 +441,7 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
func TestEvents(t *testing.T) { func TestEvents(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "Events") span := startSpan(tp, "Events")
k1v1 := label.String("key1", "value1") k1v1 := label.String("key1", "value1")
@ -487,7 +487,7 @@ func TestEvents(t *testing.T) {
func TestEventsOverLimit(t *testing.T) { func TestEventsOverLimit(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
cfg := Config{MaxEventsPerSpan: 2} cfg := Config{MaxEventsPerSpan: 2}
tp := NewProvider(WithConfig(cfg), WithSyncer(te)) tp := NewTracerProvider(WithConfig(cfg), WithSyncer(te))
span := startSpan(tp, "EventsOverLimit") span := startSpan(tp, "EventsOverLimit")
k1v1 := label.String("key1", "value1") k1v1 := label.String("key1", "value1")
@ -538,7 +538,7 @@ func TestEventsOverLimit(t *testing.T) {
func TestLinks(t *testing.T) { func TestLinks(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
k1v1 := label.String("key1", "value1") k1v1 := label.String("key1", "value1")
k2v2 := label.String("key2", "value2") k2v2 := label.String("key2", "value2")
@ -583,7 +583,7 @@ func TestLinksOverLimit(t *testing.T) {
sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}}
sc3 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} sc3 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}}
tp := NewProvider(WithConfig(cfg), WithSyncer(te)) tp := NewTracerProvider(WithConfig(cfg), WithSyncer(te))
span := startSpan(tp, "LinksOverLimit", span := startSpan(tp, "LinksOverLimit",
apitrace.WithLinks( apitrace.WithLinks(
@ -624,7 +624,7 @@ func TestLinksOverLimit(t *testing.T) {
func TestSetSpanName(t *testing.T) { func TestSetSpanName(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
ctx := context.Background() ctx := context.Background()
want := "SpanName-1" want := "SpanName-1"
@ -646,7 +646,7 @@ func TestSetSpanName(t *testing.T) {
func TestSetSpanStatus(t *testing.T) { func TestSetSpanStatus(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "SpanStatus") span := startSpan(tp, "SpanStatus")
span.SetStatus(otelcodes.Canceled, "canceled") span.SetStatus(otelcodes.Canceled, "canceled")
@ -712,7 +712,7 @@ func checkChild(p apitrace.SpanContext, apiSpan apitrace.Span) error {
// startSpan starts a span with a name "span0". See startNamedSpan for // startSpan starts a span with a name "span0". See startNamedSpan for
// details. // details.
func startSpan(tp *Provider, trName string, args ...apitrace.SpanOption) apitrace.Span { func startSpan(tp *TracerProvider, trName string, args ...apitrace.SpanOption) apitrace.Span {
return startNamedSpan(tp, trName, "span0", args...) return startNamedSpan(tp, trName, "span0", args...)
} }
@ -720,7 +720,7 @@ func startSpan(tp *Provider, trName string, args ...apitrace.SpanOption) apitrac
// passed name and with remote span context as parent. The remote span // passed name and with remote span context as parent. The remote span
// context contains TraceFlags with sampled bit set. This allows the // context contains TraceFlags with sampled bit set. This allows the
// span to be automatically sampled. // span to be automatically sampled.
func startNamedSpan(tp *Provider, trName, name string, args ...apitrace.SpanOption) apitrace.Span { func startNamedSpan(tp *TracerProvider, trName, name string, args ...apitrace.SpanOption) apitrace.Span {
ctx := context.Background() ctx := context.Background()
ctx = apitrace.ContextWithRemoteSpanContext(ctx, remoteSpanContext()) ctx = apitrace.ContextWithRemoteSpanContext(ctx, remoteSpanContext())
args = append(args, apitrace.WithRecord()) args = append(args, apitrace.WithRecord())
@ -777,7 +777,7 @@ func checkTime(x *time.Time) bool {
func TestEndSpanTwice(t *testing.T) { func TestEndSpanTwice(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "EndSpanTwice") span := startSpan(tp, "EndSpanTwice")
span.End() span.End()
@ -789,7 +789,7 @@ func TestEndSpanTwice(t *testing.T) {
func TestStartSpanAfterEnd(t *testing.T) { func TestStartSpanAfterEnd(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te)) tp := NewTracerProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te))
ctx := context.Background() ctx := context.Background()
tr := tp.Tracer("SpanAfterEnd") tr := tp.Tracer("SpanAfterEnd")
@ -834,7 +834,7 @@ func TestStartSpanAfterEnd(t *testing.T) {
func TestChildSpanCount(t *testing.T) { func TestChildSpanCount(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te)) tp := NewTracerProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te))
tr := tp.Tracer("ChidSpanCount") tr := tp.Tracer("ChidSpanCount")
ctx, span0 := tr.Start(context.Background(), "parent") ctx, span0 := tr.Start(context.Background(), "parent")
@ -888,7 +888,7 @@ func TestNilSpanEnd(t *testing.T) {
func TestExecutionTracerTaskEnd(t *testing.T) { func TestExecutionTracerTaskEnd(t *testing.T) {
var n uint64 var n uint64
tp := NewProvider(WithConfig(Config{DefaultSampler: NeverSample()})) tp := NewTracerProvider(WithConfig(Config{DefaultSampler: NeverSample()}))
tr := tp.Tracer("Execution Tracer Task End") tr := tp.Tracer("Execution Tracer Task End")
executionTracerTaskEnd := func() { executionTracerTaskEnd := func() {
@ -937,7 +937,7 @@ func TestExecutionTracerTaskEnd(t *testing.T) {
func TestCustomStartEndTime(t *testing.T) { func TestCustomStartEndTime(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te), WithConfig(Config{DefaultSampler: AlwaysSample()})) tp := NewTracerProvider(WithSyncer(te), WithConfig(Config{DefaultSampler: AlwaysSample()}))
startTime := time.Date(2019, time.August, 27, 14, 42, 0, 0, time.UTC) startTime := time.Date(2019, time.August, 27, 14, 42, 0, 0, time.UTC)
endTime := startTime.Add(time.Second * 20) endTime := startTime.Add(time.Second * 20)
@ -980,7 +980,7 @@ func TestRecordError(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "RecordError") span := startSpan(tp, "RecordError")
errTime := time.Now() errTime := time.Now()
@ -1022,7 +1022,7 @@ func TestRecordError(t *testing.T) {
func TestRecordErrorWithStatus(t *testing.T) { func TestRecordErrorWithStatus(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "RecordErrorWithStatus") span := startSpan(tp, "RecordErrorWithStatus")
testErr := ottest.NewTestError("test error") testErr := ottest.NewTestError("test error")
@ -1068,7 +1068,7 @@ func TestRecordErrorWithStatus(t *testing.T) {
func TestRecordErrorNil(t *testing.T) { func TestRecordErrorNil(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "RecordErrorNil") span := startSpan(tp, "RecordErrorNil")
span.RecordError(context.Background(), nil) span.RecordError(context.Background(), nil)
@ -1098,7 +1098,7 @@ func TestRecordErrorNil(t *testing.T) {
func TestWithSpanKind(t *testing.T) { func TestWithSpanKind(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te), WithConfig(Config{DefaultSampler: AlwaysSample()})) tp := NewTracerProvider(WithSyncer(te), WithConfig(Config{DefaultSampler: AlwaysSample()}))
tr := tp.Tracer("withSpanKind") tr := tp.Tracer("withSpanKind")
_, span := tr.Start(context.Background(), "WithoutSpanKind") _, span := tr.Start(context.Background(), "WithoutSpanKind")
@ -1136,7 +1136,7 @@ func TestWithSpanKind(t *testing.T) {
func TestWithResource(t *testing.T) { func TestWithResource(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te), tp := NewTracerProvider(WithSyncer(te),
WithConfig(Config{DefaultSampler: AlwaysSample()}), WithConfig(Config{DefaultSampler: AlwaysSample()}),
WithResource(resource.New(label.String("rk1", "rv1"), label.Int64("rk2", 5)))) WithResource(resource.New(label.String("rk1", "rv1"), label.Int64("rk2", 5))))
span := startSpan(tp, "WithResource") span := startSpan(tp, "WithResource")
@ -1168,7 +1168,7 @@ func TestWithResource(t *testing.T) {
func TestWithInstrumentationVersion(t *testing.T) { func TestWithInstrumentationVersion(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
ctx := context.Background() ctx := context.Background()
ctx = apitrace.ContextWithRemoteSpanContext(ctx, remoteSpanContext()) ctx = apitrace.ContextWithRemoteSpanContext(ctx, remoteSpanContext())
@ -1202,7 +1202,7 @@ func TestWithInstrumentationVersion(t *testing.T) {
func TestSpanCapturesPanic(t *testing.T) { func TestSpanCapturesPanic(t *testing.T) {
te := NewTestExporter() te := NewTestExporter()
tp := NewProvider(WithSyncer(te)) tp := NewTracerProvider(WithSyncer(te))
_, span := tp.Tracer("CatchPanic").Start( _, span := tp.Tracer("CatchPanic").Start(
context.Background(), context.Background(),
"span", "span",

View File

@ -23,7 +23,7 @@ import (
) )
type tracer struct { type tracer struct {
provider *Provider provider *TracerProvider
instrumentationLibrary instrumentation.Library instrumentationLibrary instrumentation.Library
} }

View File

@ -22,7 +22,7 @@ import (
var testConfig = sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()} var testConfig = sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}
func basicProvider(t *testing.T) *sdktrace.Provider { func basicTracerProvider(t *testing.T) *sdktrace.TracerProvider {
tp := sdktrace.NewProvider(sdktrace.WithConfig(testConfig)) tp := sdktrace.NewTracerProvider(sdktrace.WithConfig(testConfig))
return tp return tp
} }