Skip to content

Commit

Permalink
Rename *Provider names (#1190)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MrAlias authored Sep 23, 2020
1 parent 5dd2962 commit 7d71867
Show file tree
Hide file tree
Showing 49 changed files with 276 additions and 256 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
`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)
- 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)

### Removed
Expand Down
32 changes: 16 additions & 16 deletions api/global/internal/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import (
"go.opentelemetry.io/otel/label"
)

// This file contains the forwarding implementation of metric.Provider
// used as the default global instance. Metric events using instruments
// provided by this implementation are no-ops until the first Meter
// implementation is set as the global provider.
// This file contains the forwarding implementation of MeterProvider used as
// the default global instance. Metric events using instruments provided by
// this implementation are no-ops until the first Meter implementation is set
// as the global provider.
//
// The implementation here uses Mutexes to maintain a list of active
// Meters in the Provider and Instruments in each Meter, under the
// assumption that these interfaces are not performance-critical.
// The implementation here uses Mutexes to maintain a list of active Meters in
// the MeterProvider and Instruments in each Meter, under the assumption that
// these interfaces are not performance-critical.
//
// We have the invariant that setDelegate() will be called before a
// new metric.Provider implementation is registered as the global
// provider. Mutexes in the Provider and Meters ensure that each
// instrument has a delegate before the global provider is set.
// We have the invariant that setDelegate() will be called before a new
// MeterProvider implementation is registered as the global provider. Mutexes
// in the MeterProvider and Meters ensure that each instrument has a delegate
// before the global provider is set.
//
// Bound instrument operations are implemented by delegating to the
// instrument after it is registered, with a sync.Once initializer to
Expand All @@ -51,7 +51,7 @@ type meterKey struct {
}

type meterProvider struct {
delegate metric.Provider
delegate metric.MeterProvider

// lock protects `delegate` and `meters`.
lock sync.Mutex
Expand Down Expand Up @@ -113,7 +113,7 @@ type syncHandle struct {
initialize sync.Once
}

var _ metric.Provider = &meterProvider{}
var _ metric.MeterProvider = &meterProvider{}
var _ metric.MeterImpl = &meterImpl{}
var _ metric.InstrumentImpl = &syncImpl{}
var _ metric.BoundSyncImpl = &syncHandle{}
Expand All @@ -123,15 +123,15 @@ func (inst *instrument) Descriptor() metric.Descriptor {
return inst.descriptor
}

// Provider interface and delegation
// MeterProvider interface and delegation

func newMeterProvider() *meterProvider {
return &meterProvider{
meters: map[meterKey]*meterEntry{},
}
}

func (p *meterProvider) setDelegate(provider metric.Provider) {
func (p *meterProvider) setDelegate(provider metric.MeterProvider) {
p.lock.Lock()
defer p.lock.Unlock()

Expand Down Expand Up @@ -166,7 +166,7 @@ func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOp

// 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()
defer m.lock.Unlock()

Expand Down
16 changes: 8 additions & 8 deletions api/global/internal/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestDirect(t *testing.T) {
second.Record(ctx, 1, labels3...)
second.Record(ctx, 2, labels3...)

mock, provider := metrictest.NewProvider()
mock, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider)

counter.Add(ctx, 1, labels1...)
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestBound(t *testing.T) {
boundM.Record(ctx, 1)
boundM.Record(ctx, 2)

mock, provider := metrictest.NewProvider()
mock, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider)

boundC.Add(ctx, 1)
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestUnbindThenRecordOne(t *testing.T) {
internal.ResetForTest()

ctx := context.Background()
mock, provider := metrictest.NewProvider()
mock, provider := metrictest.NewMeterProvider()

meter := global.Meter("test")
counter := Must(meter).NewInt64Counter("test.counter")
Expand All @@ -213,15 +213,15 @@ func TestUnbindThenRecordOne(t *testing.T) {
}

type meterProviderWithConstructorError struct {
metric.Provider
metric.MeterProvider
}

type meterWithConstructorError struct {
metric.MeterImpl
}

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) {
Expand All @@ -237,7 +237,7 @@ func TestErrorInDeferredConstructor(t *testing.T) {
c1 := Must(meter).NewInt64Counter("test")
c2 := Must(meter).NewInt64Counter("test")

_, provider := metrictest.NewProvider()
_, provider := metrictest.NewMeterProvider()
sdk := &meterProviderWithConstructorError{provider}

require.Panics(t, func() {
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestImplementationIndirection(t *testing.T) {
require.False(t, ok)

// Register the SDK
_, provider := metrictest.NewProvider()
_, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider)

// Repeat the above tests
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestRecordBatchMock(t *testing.T) {

meter.RecordBatch(context.Background(), nil, counter.Measurement(1))

mock, provider := metrictest.NewProvider()
mock, provider := metrictest.NewMeterProvider()
global.SetMeterProvider(provider)

meter.RecordBatch(context.Background(), nil, counter.Measurement(1))
Expand Down
16 changes: 8 additions & 8 deletions api/global/internal/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (

type (
tracerProviderHolder struct {
tp trace.Provider
tp trace.TracerProvider
}

meterProviderHolder struct {
mp metric.Provider
mp metric.MeterProvider
}

propagatorsHolder struct {
Expand All @@ -49,19 +49,19 @@ var (
)

// TracerProvider is the internal implementation for global.TracerProvider.
func TracerProvider() trace.Provider {
func TracerProvider() trace.TracerProvider {
return globalTracer.Load().(tracerProviderHolder).tp
}

// SetTracerProvider is the internal implementation for global.SetTracerProvider.
func SetTracerProvider(tp trace.Provider) {
func SetTracerProvider(tp trace.TracerProvider) {
delegateTraceOnce.Do(func() {
current := TracerProvider()
if current == tp {
// Setting the provider to the prior default is nonsense, panic.
// Panic is acceptable because we are likely still early in the
// 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 {
def.setDelegate(tp)
}
Expand All @@ -71,20 +71,20 @@ func SetTracerProvider(tp trace.Provider) {
}

// MeterProvider is the internal implementation for global.MeterProvider.
func MeterProvider() metric.Provider {
func MeterProvider() metric.MeterProvider {
return globalMeter.Load().(meterProviderHolder).mp
}

// SetMeterProvider is the internal implementation for global.SetMeterProvider.
func SetMeterProvider(mp metric.Provider) {
func SetMeterProvider(mp metric.MeterProvider) {
delegateMeterOnce.Do(func() {
current := MeterProvider()

if current == mp {
// Setting the provider to the prior default is nonsense, panic.
// Panic is acceptable because we are likely still early in the
// 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 {
def.setDelegate(mp)
}
Expand Down
33 changes: 18 additions & 15 deletions api/global/internal/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
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
returned by the global Provider will provide no-op functionality. This means
that all Span created prior to initialization are no-op Spans.
returned by the global TracerProvider will provide no-op functionality. This
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
Tracers provided by the SDK defined Provider. However, any Span started prior
to this initialization does not change its behavior. Meaning, the Span remains
a no-op Span.
Tracers provided by the SDK defined TracerProvider. However, any Span started
prior to this initialization does not change its behavior. Meaning, the Span
remains a no-op Span.
The implementation to track and swap Tracers locks all new Tracer creation
until the swap is complete. This assumes that this operation is not
Expand All @@ -39,27 +39,30 @@ import (
"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 {
mtx sync.Mutex
tracers []*tracer

delegate trace.Provider
delegate trace.TracerProvider
}

// Compile-time guarantee that tracerProvider implements the trace.Provider interface.
var _ trace.Provider = &tracerProvider{}
// Compile-time guarantee that tracerProvider implements the 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
// Tracers provided by provider.
//
// Delegation only happens on the first call to this method. All subsequent
// calls result in no delegation changes.
func (p *tracerProvider) setDelegate(provider trace.Provider) {
func (p *tracerProvider) setDelegate(provider trace.TracerProvider) {
if p.delegate != nil {
return
}
Expand All @@ -75,7 +78,7 @@ func (p *tracerProvider) setDelegate(provider trace.Provider) {
p.tracers = nil
}

// Tracer implements trace.Provider.
// Tracer implements TracerProvider.
func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
p.mtx.Lock()
defer p.mtx.Unlock()
Expand Down Expand Up @@ -111,7 +114,7 @@ var _ trace.Tracer = &tracer{}
//
// Delegation only happens on the first call to this method. All subsequent
// 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...) })
}

Expand Down
4 changes: 2 additions & 2 deletions api/global/internal/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestTraceWithSDK(t *testing.T) {
_, span1 := tracer1.Start(ctx, "span1")

sr := new(tracetest.StandardSpanRecorder)
tp := tracetest.NewProvider(tracetest.WithSpanRecorder(sr))
tp := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(sr))
global.SetTracerProvider(tp)

// This span was started before initialization, it is expected to be dropped.
Expand All @@ -45,7 +45,7 @@ func TestTraceWithSDK(t *testing.T) {
_, span2 := tracer1.Start(ctx, "span2")
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")
_, span3 := tracer2.Start(ctx, "span3")
span3.End()
Expand Down
6 changes: 3 additions & 3 deletions api/global/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

// 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
// code only if that code provides built-in instrumentation. If the
// instrumentationName is empty, then a implementation defined default name
Expand All @@ -39,11 +39,11 @@ func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter
// meter := global.MeterProvider().Meter("example.com/foo")
// or
// meter := global.Meter("example.com/foo")
func MeterProvider() metric.Provider {
func MeterProvider() metric.MeterProvider {
return internal.MeterProvider()
}

// SetMeterProvider registers `mp` as the global meter provider.
func SetMeterProvider(mp metric.Provider) {
func SetMeterProvider(mp metric.MeterProvider) {
internal.SetMeterProvider(mp)
}
6 changes: 3 additions & 3 deletions api/global/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ import (

type testMeterProvider struct{}

var _ metric.Provider = &testMeterProvider{}
var _ metric.MeterProvider = &testMeterProvider{}

func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter {
return metric.Meter{}
}

func TestMultipleGlobalMeterProvider(t *testing.T) {
p1 := testMeterProvider{}
p2 := metric.NoopProvider{}
p2 := metric.NoopMeterProvider{}
global.SetMeterProvider(&p1)
global.SetMeterProvider(&p2)

got := global.MeterProvider()
want := &p2
if got != want {
t.Fatalf("Provider: got %p, want %p\n", got, want)
t.Fatalf("MeterProvider: got %p, want %p\n", got, want)
}
}
6 changes: 3 additions & 3 deletions api/global/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ func Tracer(name string) trace.Tracer {
}

// 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.
// tracer := global.TracerProvider().Tracer("example.com/foo")
// or
// tracer := global.Tracer("example.com/foo")
func TracerProvider() trace.Provider {
func TracerProvider() trace.TracerProvider {
return internal.TracerProvider()
}

// SetTracerProvider registers `tp` as the global trace provider.
func SetTracerProvider(tp trace.Provider) {
func SetTracerProvider(tp trace.TracerProvider) {
internal.SetTracerProvider(tp)
}
Loading

0 comments on commit 7d71867

Please sign in to comment.