1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-28 03:57:09 +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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
`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

View File

@ -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
@ -51,7 +51,7 @@ type meterKey struct {
}
type meterProvider struct {
delegate metric.Provider
delegate metric.MeterProvider
// lock protects `delegate` and `meters`.
lock sync.Mutex
@ -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{}
@ -123,7 +123,7 @@ func (inst *instrument) Descriptor() metric.Descriptor {
return inst.descriptor
}
// Provider interface and delegation
// MeterProvider interface and delegation
func newMeterProvider() *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()
defer p.lock.Unlock()
@ -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()

View File

@ -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...)
@ -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)
@ -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")
@ -213,7 +213,7 @@ func TestUnbindThenRecordOne(t *testing.T) {
}
type meterProviderWithConstructorError struct {
metric.Provider
metric.MeterProvider
}
type meterWithConstructorError struct {
@ -221,7 +221,7 @@ type meterWithConstructorError struct {
}
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) {
@ -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() {
@ -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
@ -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))

View File

@ -27,11 +27,11 @@ import (
type (
tracerProviderHolder struct {
tp trace.Provider
tp trace.TracerProvider
}
meterProviderHolder struct {
mp metric.Provider
mp metric.MeterProvider
}
propagatorsHolder struct {
@ -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)
}
@ -71,12 +71,12 @@ 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()
@ -84,7 +84,7 @@ func SetMeterProvider(mp metric.Provider) {
// 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)
}

View File

@ -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
@ -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
}
@ -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()
@ -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...) })
}

View File

@ -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.
@ -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()

View File

@ -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
@ -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)
}

View File

@ -23,7 +23,7 @@ import (
type testMeterProvider struct{}
var _ metric.Provider = &testMeterProvider{}
var _ metric.MeterProvider = &testMeterProvider{}
func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter {
return metric.Meter{}
@ -31,13 +31,13 @@ func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) 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)
}
}

View File

@ -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)
}

View File

@ -24,7 +24,7 @@ import (
type testTracerProvider struct{}
var _ trace.Provider = &testTracerProvider{}
var _ trace.TracerProvider = &testTracerProvider{}
func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
return noop.Tracer
@ -32,13 +32,13 @@ func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Trace
func TestMultipleGlobalTracerProvider(t *testing.T) {
p1 := testTracerProvider{}
p2 := trace.NoopProvider()
p2 := trace.NoopTracerProvider()
global.SetTracerProvider(&p1)
global.SetTracerProvider(p2)
got := global.TracerProvider()
want := p2
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
// 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.
// To obtain a Provider implementation, initialize and configure any
// The MeterProvider interface supports obtaining a named Meter interface. To
// obtain a MeterProvider implementation, initialize and configure any
// compatible SDK.
package metric // import "go.opentelemetry.io/otel/api/metric"

View File

@ -22,7 +22,7 @@ import (
// The file is organized as follows:
//
// - Provider interface
// - MeterProvider interface
// - Meter struct
// - RecordBatch
// - BatchObserver
@ -31,8 +31,8 @@ import (
// - Batch asynchronous constructors (1 x int64,float64)
// - Internals
// Provider supports named Meter instances.
type Provider interface {
// MeterProvider supports named Meter instances.
type MeterProvider interface {
// Meter creates an implementation of the Meter interface.
// The instrumentationName must be the name of the library providing
// 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{
asyncInstruments: NewAsyncInstrumentState(),
}
return impl, registry.NewProvider(impl)
return impl, registry.NewMeterProvider(impl)
}
func NewMeter() (*MeterImpl, apimetric.Meter) {
impl, p := NewProvider()
impl, p := NewMeterProvider()
return impl, p.Meter("mock")
}

View File

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

View File

@ -23,12 +23,12 @@ import (
"go.opentelemetry.io/otel/label"
)
// Provider is a standard metric.Provider for wrapping `MeterImpl`
type Provider struct {
// MeterProvider is a standard MeterProvider for wrapping `MeterImpl`
type MeterProvider struct {
impl metric.MeterImpl
}
var _ metric.Provider = (*Provider)(nil)
var _ metric.MeterProvider = (*MeterProvider)(nil)
// uniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding
// uniqueness checking for instrument descriptors. Use NewUniqueInstrumentMeter
@ -47,16 +47,16 @@ type key struct {
InstrumentationVersion string
}
// NewProvider returns a new provider that implements instrument
// NewMeterProvider returns a new provider that implements instrument
// name-uniqueness checking.
func NewProvider(impl metric.MeterImpl) *Provider {
return &Provider{
func NewMeterProvider(impl metric.MeterImpl) *MeterProvider {
return &MeterProvider{
impl: NewUniqueInstrumentMeterImpl(impl),
}
}
// Meter implements metric.Provider.
func (p *Provider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
// Meter implements MeterProvider.
func (p *MeterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
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) {
for _, nf := range allNew {
_, provider := mockTest.NewProvider()
_, provider := mockTest.NewMeterProvider()
meter := provider.Meter("meter")
inst1, err1 := nf(meter, "this")
@ -86,7 +86,7 @@ func TestRegistrySameInstruments(t *testing.T) {
func TestRegistryDifferentNamespace(t *testing.T) {
for _, nf := range allNew {
_, provider := mockTest.NewProvider()
_, provider := mockTest.NewMeterProvider()
meter1 := provider.Meter("meter1")
meter2 := provider.Meter("meter2")
@ -101,7 +101,7 @@ func TestRegistryDifferentNamespace(t *testing.T) {
func TestRegistryDiffInstruments(t *testing.T) {
for origName, origf := range allNew {
_, provider := mockTest.NewProvider()
_, provider := mockTest.NewMeterProvider()
meter := provider.Meter("meter")
_, 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()
p := registry.NewProvider(impl)
p := registry.NewMeterProvider(impl)
m1 := p.Meter("m1")
m1p := p.Meter("m1")
m2 := p.Meter("m2")

View File

@ -22,7 +22,8 @@ import (
"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.
// The instrumentationName must be the name of the library providing
// instrumentation. This name may be the same as the instrumented code

View File

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

View File

@ -20,17 +20,17 @@ import (
"go.opentelemetry.io/otel/api/trace"
)
type Provider struct {
type TracerProvider struct {
config config
tracersMu sync.Mutex
tracers map[instrumentation]*Tracer
}
var _ trace.Provider = (*Provider)(nil)
var _ trace.TracerProvider = (*TracerProvider)(nil)
func NewProvider(opts ...Option) *Provider {
return &Provider{
func NewTracerProvider(opts ...Option) *TracerProvider {
return &TracerProvider{
config: newConfig(opts...),
tracers: make(map[instrumentation]*Tracer),
}
@ -40,7 +40,7 @@ type instrumentation struct {
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...)
inst := instrumentation{

View File

@ -32,7 +32,7 @@ import (
func TestSpan(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.Parallel()
@ -46,7 +46,7 @@ func TestSpan(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.Parallel()
@ -125,7 +125,7 @@ func TestSpan(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.Parallel()
@ -236,7 +236,7 @@ func TestSpan(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.Parallel()
@ -250,7 +250,7 @@ func TestSpan(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.Parallel()
@ -275,7 +275,7 @@ func TestSpan(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.Parallel()
@ -319,7 +319,7 @@ func TestSpan(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.Parallel()
@ -415,7 +415,7 @@ func TestSpan(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.Parallel()
@ -432,7 +432,7 @@ func TestSpan(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.Parallel()
@ -526,7 +526,7 @@ func TestSpan(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.Parallel()
@ -608,7 +608,7 @@ func TestSpan(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.Parallel()

View File

@ -30,10 +30,10 @@ import (
)
func TestTracer(t *testing.T) {
tp := tracetest.NewProvider()
tp := tracetest.NewTracerProvider()
apitest.NewHarness(t).TestTracer(func() func() trace.Tracer {
tp := tracetest.NewProvider()
tp := tracetest.NewTracerProvider()
var i uint64
return func() trace.Tracer {
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)) {
tp := tracetest.NewProvider()
tp := tracetest.NewTracerProvider()
t.Run("starts a span with the expected name", func(t *testing.T) {
t.Parallel()
@ -304,7 +304,7 @@ func testTracedSpan(t *testing.T, fn func(tracer trace.Tracer, name string) (tra
e := matchers.NewExpecter(t)
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")
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)
sr := new(tracetest.StandardSpanRecorder)
subject := tracetest.NewProvider(tracetest.WithSpanRecorder(sr)).Tracer(t.Name())
subject := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(sr)).Tracer(t.Name())
numSpans := 2

View File

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

View File

@ -22,21 +22,21 @@ import (
"go.opentelemetry.io/otel/bridge/opentracing/migration"
)
type WrapperProvider struct {
type WrapperTracerProvider struct {
wTracer *WrapperTracer
}
var _ oteltrace.Provider = (*WrapperProvider)(nil)
var _ oteltrace.TracerProvider = (*WrapperTracerProvider)(nil)
// Tracer returns the WrapperTracer associated with the WrapperProvider.
func (p *WrapperProvider) Tracer(_ string, _ ...oteltrace.TracerOption) oteltrace.Tracer {
// Tracer returns the WrapperTracer associated with the WrapperTracerProvider.
func (p *WrapperTracerProvider) Tracer(_ string, _ ...oteltrace.TracerOption) oteltrace.Tracer {
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.
func NewWrappedProvider(bridge *BridgeTracer, tracer oteltrace.Tracer) *WrapperProvider {
return &WrapperProvider{
func NewWrappedTracerProvider(bridge *BridgeTracer, tracer oteltrace.Tracer) *WrapperTracerProvider {
return &WrapperTracerProvider{
wTracer: NewWrapperTracer(bridge, tracer),
}
}

View File

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

View File

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

View File

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

View File

@ -134,7 +134,7 @@ func InstallNewPipeline(config Config, options ...pull.Option) (*Exporter, error
if err != nil {
return nil, err
}
global.SetMeterProvider(exp.Provider())
global.SetMeterProvider(exp.MeterProvider())
return exp, nil
}
@ -154,9 +154,9 @@ func (e *Exporter) SetController(config Config, options ...pull.Option) {
)
}
// Provider returns the metric.Provider of this exporter.
func (e *Exporter) Provider() metric.Provider {
return e.controller.Provider()
// MeterProvider returns the MeterProvider of this exporter.
func (e *Exporter) MeterProvider() metric.MeterProvider {
return e.controller.MeterProvider()
}
// 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)
meter := exporter.Provider().Meter("test")
meter := exporter.MeterProvider().Meter("test")
counter := metric.Must(meter).NewFloat64Counter("counter")
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")
@ -105,7 +105,7 @@ func TestPrometheusStatefulness(t *testing.T) {
)
require.NoError(t, err)
meter := exporter.Provider().Meter("test")
meter := exporter.MeterProvider().Meter("test")
// GET the HTTP endpoint
scrape := func() string {

View File

@ -41,16 +41,16 @@ func main() {
}()
// Note: The exporter can also be used as a Batcher. E.g.
// tracerProvider := sdktrace.NewProvider(
// tracerProvider := sdktrace.NewTracerProvider(
// sdktrace.WithBatcher(exporter,
// sdktrace.WithBatchTimeout(time.Second*15),
// sdktrace.WithMaxExportBatchSize(100),
// ),
// )
tracerProvider := sdktrace.NewProvider(sdktrace.WithBatcher(exporter))
tracerProvider := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
pusher := push.New(simple.NewWithExactDistribution(), exporter)
pusher.Start()
metricProvider := pusher.Provider()
metricProvider := pusher.MeterProvider()
// 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.WithBatcher(
exp,
@ -84,7 +84,7 @@ func Example_withTLS() {
}
}()
tp := sdktrace.NewProvider(
tp := sdktrace.NewTracerProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher(
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.WithBatcher(
exp,
@ -95,13 +95,13 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
sdktrace.WithMaxExportBatchSize(10),
),
}
tp1 := sdktrace.NewProvider(append(pOpts,
tp1 := sdktrace.NewTracerProvider(append(pOpts,
sdktrace.WithResource(resource.New(
label.String("rk1", "rv11)"),
label.Int64("rk2", 5),
)))...)
tp2 := sdktrace.NewProvider(append(pOpts,
tp2 := sdktrace.NewTracerProvider(append(pOpts,
sdktrace.WithResource(resource.New(
label.String("rk1", "rv12)"),
label.Float32("rk3", 6.5),
@ -127,7 +127,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
pusher.Start()
ctx := context.Background()
meter := pusher.Provider().Meter("test-meter")
meter := pusher.MeterProvider().Meter("test-meter")
labels := []label.KeyValue{label.Bool("test", true)}
type data struct {
@ -462,7 +462,7 @@ func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
_ = exp.Shutdown(context.Background())
}()
tp := sdktrace.NewProvider(
tp := sdktrace.NewTracerProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher(
exp,

View File

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

View File

@ -151,14 +151,14 @@ func NewRawExporter(endpointOption EndpointOption, opts ...Option) (*Exporter, e
// NewExportPipeline sets up a complete export pipeline
// 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{}
opts = append(opts, WithDisabledFromEnv())
for _, opt := range opts {
opt(&o)
}
if o.Disabled {
return apitrace.NoopProvider(), func() {}, nil
return apitrace.NoopTracerProvider(), func() {}, nil
}
exporter, err := NewRawExporter(endpointOption, opts...)
@ -166,11 +166,11 @@ func NewExportPipeline(endpointOption EndpointOption, opts ...Option) (apitrace.
return nil, nil, err
}
pOpts := []sdktrace.ProviderOption{sdktrace.WithSyncer(exporter)}
pOpts := []sdktrace.TracerProviderOption{sdktrace.WithSyncer(exporter)}
if exporter.o.Config != nil {
pOpts = append(pOpts, sdktrace.WithConfig(*exporter.o.Config))
}
tp := sdktrace.NewProvider(pOpts...)
tp := sdktrace.NewTracerProvider(pOpts...)
return tp, exporter.Flush, nil
}

View File

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

View File

@ -111,13 +111,13 @@ func NewRawExporter(collectorURL, serviceName string, opts ...Option) (*Exporter
// NewExportPipeline sets up a complete export pipeline
// 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...)
if err != nil {
return nil, err
}
tp := sdktrace.NewProvider(sdktrace.WithBatcher(exp))
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exp))
if exp.o.config != nil {
tp.ApplyConfig(*exp.o.config)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -153,7 +153,7 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
for _, option := range options {
t.Run(option.name, func(t *testing.T) {
te := testBatchExporter{}
tp := basicProvider(t)
tp := basicTracerProvider(t)
ssp := createAndRegisterBatchSP(option, &te)
if ssp == nil {
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 {
tp := sdktrace.NewProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sampler}))
tp := sdktrace.NewTracerProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sampler}))
return tp.Tracer(name)
}

View File

@ -33,34 +33,34 @@ const (
// TODO (MrAlias): unify this API option design:
// https://github.com/open-telemetry/opentelemetry-go/issues/536
// ProviderOptions
type ProviderOptions struct {
// TracerProviderConfig
type TracerProviderConfig struct {
processors []SpanProcessor
config Config
}
type ProviderOption func(*ProviderOptions)
type TracerProviderOption func(*TracerProviderConfig)
type Provider struct {
type TracerProvider struct {
mu sync.Mutex
namedTracer map[instrumentation.Library]*tracer
spanProcessors atomic.Value
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
// to all tracer instances that will be created by this provider.
func NewProvider(opts ...ProviderOption) *Provider {
o := &ProviderOptions{}
func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider {
o := &TracerProviderConfig{}
for _, opt := range opts {
opt(o)
}
tp := &Provider{
tp := &TracerProvider{
namedTracer: make(map[instrumentation.Library]*tracer),
}
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,
// 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...)
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
func (p *Provider) RegisterSpanProcessor(s SpanProcessor) {
func (p *TracerProvider) RegisterSpanProcessor(s SpanProcessor) {
p.mu.Lock()
defer p.mu.Unlock()
new := make(spanProcessorMap)
@ -120,7 +120,7 @@ func (p *Provider) RegisterSpanProcessor(s SpanProcessor) {
}
// 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()
defer p.mu.Unlock()
new := make(spanProcessorMap)
@ -140,7 +140,7 @@ func (p *Provider) UnregisterSpanProcessor(s SpanProcessor) {
// ApplyConfig changes the configuration of the provider.
// 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()
defer p.mu.Unlock()
c := *p.config.Load().(*Config)
@ -165,36 +165,36 @@ func (p *Provider) ApplyConfig(cfg Config) {
p.config.Store(&c)
}
// WithSyncer registers the exporter with the Provider using a
// WithSyncer registers the exporter with the TracerProvider using a
// SimpleSpanProcessor.
func WithSyncer(e export.SpanExporter) ProviderOption {
func WithSyncer(e export.SpanExporter) TracerProviderOption {
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.
func WithBatcher(e export.SpanExporter, opts ...BatchSpanProcessorOption) ProviderOption {
func WithBatcher(e export.SpanExporter, opts ...BatchSpanProcessorOption) TracerProviderOption {
return WithSpanProcessor(NewBatchSpanProcessor(e, opts...))
}
// WithSpanProcessor registers the SpanProcessor with a Provider.
func WithSpanProcessor(sp SpanProcessor) ProviderOption {
return func(opts *ProviderOptions) {
// WithSpanProcessor registers the SpanProcessor with a TracerProvider.
func WithSpanProcessor(sp SpanProcessor) TracerProviderOption {
return func(opts *TracerProviderConfig) {
opts.processors = append(opts.processors, sp)
}
}
// WithConfig option sets the configuration to provider.
func WithConfig(config Config) ProviderOption {
return func(opts *ProviderOptions) {
func WithConfig(config Config) TracerProviderOption {
return func(opts *TracerProviderConfig) {
opts.config = config
}
}
// WithResource option attaches a resource to the provider.
// The resource is added to the span when it is started.
func WithResource(r *resource.Resource) ProviderOption {
return func(opts *ProviderOptions) {
func WithResource(r *resource.Resource) TracerProviderOption {
return func(opts *TracerProviderConfig) {
opts.config.Resource = r
}
}

View File

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

View File

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

View File

@ -60,7 +60,7 @@ func init() {
}
func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) {
tp := NewProvider(WithConfig(Config{DefaultSampler: TraceIDRatioBased(0)}))
tp := NewTracerProvider(WithConfig(Config{DefaultSampler: TraceIDRatioBased(0)}))
harness := apitest.NewHarness(t)
subjectFactory := func() trace.Tracer {
return tp.Tracer("")
@ -151,7 +151,7 @@ func (ts testSampler) Description() string {
func TestSetName(t *testing.T) {
fooSampler := &testSampler{prefix: "foo", t: t}
tp := NewProvider(WithConfig(Config{DefaultSampler: fooSampler}))
tp := NewTracerProvider(WithConfig(Config{DefaultSampler: fooSampler}))
type testCase struct {
name string
@ -206,7 +206,7 @@ func TestSetName(t *testing.T) {
}
func TestRecordingIsOn(t *testing.T) {
tp := NewProvider()
tp := NewTracerProvider()
_, span := tp.Tracer("Recording on").Start(context.Background(), "StartSpan")
defer span.End()
if span.IsRecording() == false {
@ -259,7 +259,7 @@ func TestSampling(t *testing.T) {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
p := NewProvider(WithConfig(Config{DefaultSampler: tc.sampler}))
p := NewTracerProvider(WithConfig(Config{DefaultSampler: tc.sampler}))
tr := p.Tracer("test")
var sampled int
for i := 0; i < total; i++ {
@ -297,7 +297,7 @@ func TestSampling(t *testing.T) {
}
func TestStartSpanWithParent(t *testing.T) {
tp := NewProvider()
tp := NewTracerProvider()
tr := tp.Tracer("SpanWithParent")
ctx := context.Background()
@ -341,7 +341,7 @@ func TestStartSpanWithParent(t *testing.T) {
func TestSetSpanAttributesOnStart(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp,
"StartSpanAttribute",
apitrace.WithAttributes(label.String("key1", "value1")),
@ -374,7 +374,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) {
func TestSetSpanAttributes(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "SpanAttribute")
span.SetAttributes(label.String("key1", "value1"))
got, err := endSpan(te, span)
@ -404,7 +404,7 @@ func TestSetSpanAttributes(t *testing.T) {
func TestSetSpanAttributesOverLimit(t *testing.T) {
te := NewTestExporter()
cfg := Config{MaxAttributesPerSpan: 2}
tp := NewProvider(WithConfig(cfg), WithSyncer(te))
tp := NewTracerProvider(WithConfig(cfg), WithSyncer(te))
span := startSpan(tp, "SpanAttributesOverLimit")
span.SetAttributes(
@ -441,7 +441,7 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
func TestEvents(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "Events")
k1v1 := label.String("key1", "value1")
@ -487,7 +487,7 @@ func TestEvents(t *testing.T) {
func TestEventsOverLimit(t *testing.T) {
te := NewTestExporter()
cfg := Config{MaxEventsPerSpan: 2}
tp := NewProvider(WithConfig(cfg), WithSyncer(te))
tp := NewTracerProvider(WithConfig(cfg), WithSyncer(te))
span := startSpan(tp, "EventsOverLimit")
k1v1 := label.String("key1", "value1")
@ -538,7 +538,7 @@ func TestEventsOverLimit(t *testing.T) {
func TestLinks(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
k1v1 := label.String("key1", "value1")
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}}
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",
apitrace.WithLinks(
@ -624,7 +624,7 @@ func TestLinksOverLimit(t *testing.T) {
func TestSetSpanName(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
ctx := context.Background()
want := "SpanName-1"
@ -646,7 +646,7 @@ func TestSetSpanName(t *testing.T) {
func TestSetSpanStatus(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "SpanStatus")
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
// 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...)
}
@ -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
// context contains TraceFlags with sampled bit set. This allows the
// 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 = apitrace.ContextWithRemoteSpanContext(ctx, remoteSpanContext())
args = append(args, apitrace.WithRecord())
@ -777,7 +777,7 @@ func checkTime(x *time.Time) bool {
func TestEndSpanTwice(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "EndSpanTwice")
span.End()
@ -789,7 +789,7 @@ func TestEndSpanTwice(t *testing.T) {
func TestStartSpanAfterEnd(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te))
tp := NewTracerProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te))
ctx := context.Background()
tr := tp.Tracer("SpanAfterEnd")
@ -834,7 +834,7 @@ func TestStartSpanAfterEnd(t *testing.T) {
func TestChildSpanCount(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te))
tp := NewTracerProvider(WithConfig(Config{DefaultSampler: AlwaysSample()}), WithSyncer(te))
tr := tp.Tracer("ChidSpanCount")
ctx, span0 := tr.Start(context.Background(), "parent")
@ -888,7 +888,7 @@ func TestNilSpanEnd(t *testing.T) {
func TestExecutionTracerTaskEnd(t *testing.T) {
var n uint64
tp := NewProvider(WithConfig(Config{DefaultSampler: NeverSample()}))
tp := NewTracerProvider(WithConfig(Config{DefaultSampler: NeverSample()}))
tr := tp.Tracer("Execution Tracer Task End")
executionTracerTaskEnd := func() {
@ -937,7 +937,7 @@ func TestExecutionTracerTaskEnd(t *testing.T) {
func TestCustomStartEndTime(t *testing.T) {
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)
endTime := startTime.Add(time.Second * 20)
@ -980,7 +980,7 @@ func TestRecordError(t *testing.T) {
for _, s := range scenarios {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "RecordError")
errTime := time.Now()
@ -1022,7 +1022,7 @@ func TestRecordError(t *testing.T) {
func TestRecordErrorWithStatus(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "RecordErrorWithStatus")
testErr := ottest.NewTestError("test error")
@ -1068,7 +1068,7 @@ func TestRecordErrorWithStatus(t *testing.T) {
func TestRecordErrorNil(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
span := startSpan(tp, "RecordErrorNil")
span.RecordError(context.Background(), nil)
@ -1098,7 +1098,7 @@ func TestRecordErrorNil(t *testing.T) {
func TestWithSpanKind(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te), WithConfig(Config{DefaultSampler: AlwaysSample()}))
tp := NewTracerProvider(WithSyncer(te), WithConfig(Config{DefaultSampler: AlwaysSample()}))
tr := tp.Tracer("withSpanKind")
_, span := tr.Start(context.Background(), "WithoutSpanKind")
@ -1136,7 +1136,7 @@ func TestWithSpanKind(t *testing.T) {
func TestWithResource(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te),
tp := NewTracerProvider(WithSyncer(te),
WithConfig(Config{DefaultSampler: AlwaysSample()}),
WithResource(resource.New(label.String("rk1", "rv1"), label.Int64("rk2", 5))))
span := startSpan(tp, "WithResource")
@ -1168,7 +1168,7 @@ func TestWithResource(t *testing.T) {
func TestWithInstrumentationVersion(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
ctx := context.Background()
ctx = apitrace.ContextWithRemoteSpanContext(ctx, remoteSpanContext())
@ -1202,7 +1202,7 @@ func TestWithInstrumentationVersion(t *testing.T) {
func TestSpanCapturesPanic(t *testing.T) {
te := NewTestExporter()
tp := NewProvider(WithSyncer(te))
tp := NewTracerProvider(WithSyncer(te))
_, span := tp.Tracer("CatchPanic").Start(
context.Background(),
"span",

View File

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

View File

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