Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename global SetTraceProvider and TraceProvider #1102

Merged
merged 4 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions api/global/internal/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

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

Expand All @@ -47,26 +47,26 @@ var (
delegateTraceOnce sync.Once
)

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

// SetTraceProvider is the internal implementation for global.SetTraceProvider.
func SetTraceProvider(tp trace.Provider) {
// SetTracerProvider is the internal implementation for global.SetTracerProvider.
func SetTracerProvider(tp trace.Provider) {
delegateTraceOnce.Do(func() {
current := TraceProvider()
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")
} else if def, ok := current.(*traceProvider); ok {
} else if def, ok := current.(*tracerProvider); ok {
def.setDelegate(tp)
}

})
globalTracer.Store(traceProviderHolder{tp: tp})
globalTracer.Store(tracerProviderHolder{tp: tp})
}

// MeterProvider is the internal implementation for global.MeterProvider.
Expand Down Expand Up @@ -103,7 +103,7 @@ func SetPropagators(pr propagation.Propagators) {

func defaultTracerValue() *atomic.Value {
v := &atomic.Value{}
v.Store(traceProviderHolder{tp: &traceProvider{}})
v.Store(tracerProviderHolder{tp: &tracerProvider{}})
return v
}

Expand Down
12 changes: 6 additions & 6 deletions api/global/internal/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ import (
"go.opentelemetry.io/otel/api/trace"
)

// traceProvider is a placeholder for a configured SDK Provider.
// tracerProvider is a placeholder for a configured SDK Provider.
//
// All Provider functionality is forwarded to a delegate once configured.
type traceProvider struct {
type tracerProvider struct {
mtx sync.Mutex
tracers []*tracer

delegate trace.Provider
}

// Compile-time guarantee that traceProvider implements the trace.Provider interface.
var _ trace.Provider = &traceProvider{}
// Compile-time guarantee that tracerProvider implements the trace.Provider interface.
var _ trace.Provider = &tracerProvider{}

// setDelegate configures p to delegate all Provider functionality to provider.
//
Expand All @@ -58,7 +58,7 @@ var _ trace.Provider = &traceProvider{}
//
// Delegation only happens on the first call to this method. All subsequent
// calls result in no delegation changes.
func (p *traceProvider) setDelegate(provider trace.Provider) {
func (p *tracerProvider) setDelegate(provider trace.Provider) {
if p.delegate != nil {
return
}
Expand All @@ -75,7 +75,7 @@ func (p *traceProvider) setDelegate(provider trace.Provider) {
}

// Tracer implements trace.Provider.
func (p *traceProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
p.mtx.Lock()
defer p.mtx.Unlock()

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 @@ -29,14 +29,14 @@ func TestTraceWithSDK(t *testing.T) {
internal.ResetForTest()

ctx := context.Background()
gtp := global.TraceProvider()
gtp := global.TracerProvider()
tracer1 := gtp.Tracer("pre")
// This is started before an SDK was registered and should be dropped.
_, span1 := tracer1.Start(ctx, "span1")

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

// This span was started before initialization, it is expected to be dropped.
span1.End()
Expand Down
18 changes: 9 additions & 9 deletions api/global/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ import (
// Tracer creates a named tracer that implements Tracer interface.
// If the name is an empty string then provider uses default name.
//
// This is short for TraceProvider().Tracer(name)
// This is short for TracerProvider().Tracer(name)
func Tracer(name string) trace.Tracer {
return TraceProvider().Tracer(name)
return TracerProvider().Tracer(name)
}

// TraceProvider 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.
//
// Use the trace provider to create a named tracer. E.g.
// tracer := global.TraceProvider().Tracer("example.com/foo")
// tracer := global.TracerProvider().Tracer("example.com/foo")
// or
// tracer := global.Tracer("example.com/foo")
func TraceProvider() trace.Provider {
return internal.TraceProvider()
func TracerProvider() trace.Provider {
return internal.TracerProvider()
}

// SetTraceProvider registers `tp` as the global trace provider.
func SetTraceProvider(tp trace.Provider) {
internal.SetTraceProvider(tp)
// SetTracerProvider registers `tp` as the global trace provider.
func SetTracerProvider(tp trace.Provider) {
internal.SetTracerProvider(tp)
}
14 changes: 7 additions & 7 deletions api/global/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import (
"go.opentelemetry.io/otel/api/trace"
)

type testTraceProvider struct{}
type testTracerProvider struct{}

var _ trace.Provider = &testTraceProvider{}
var _ trace.Provider = &testTracerProvider{}

func (*testTraceProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
return &trace.NoopTracer{}
}

func TestMultipleGlobalTracerProvider(t *testing.T) {
p1 := testTraceProvider{}
p1 := testTracerProvider{}
p2 := trace.NoopProvider{}
global.SetTraceProvider(&p1)
global.SetTraceProvider(&p2)
global.SetTracerProvider(&p1)
global.SetTracerProvider(&p2)

got := global.TraceProvider()
got := global.TracerProvider()
want := &p2
if got != want {
t.Fatalf("Provider: got %p, want %p\n", got, want)
Expand Down
2 changes: 1 addition & 1 deletion bridge/opentracing/mix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestMixedAPIs(t *testing.T) {
t.Log(msg)
})

otelglobal.SetTraceProvider(otelProvider)
otelglobal.SetTracerProvider(otelProvider)
ot.SetGlobalTracer(otTracer)

tc.setup(t, mockOtelTracer)
Expand Down
2 changes: 1 addition & 1 deletion example/namedtracer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func initTracer() {
if err != nil {
log.Panicf("failed to initialize trace provider %v\n", err)
}
global.SetTraceProvider(tp)
global.SetTracerProvider(tp)
}

func main() {
Expand Down
4 changes: 2 additions & 2 deletions example/otel-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func initProvider() (*otlp.Exporter, *push.Controller) {
)
handleErr(err, "failed to create exporter")

traceProvider, err := sdktrace.NewProvider(
tracerProvider, err := sdktrace.NewProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithResource(resource.New(
// the service name used to display traces in backends
Expand All @@ -73,7 +73,7 @@ func initProvider() (*otlp.Exporter, *push.Controller) {
push.WithPeriod(2*time.Second),
)

global.SetTraceProvider(traceProvider)
global.SetTracerProvider(tracerProvider)
global.SetMeterProvider(pusher.Provider())
pusher.Start()

Expand Down
4 changes: 2 additions & 2 deletions example/zipkin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {

ctx := context.Background()

tr := global.TraceProvider().Tracer("component-main")
tr := global.TracerProvider().Tracer("component-main")
ctx, span := tr.Start(ctx, "foo")
<-time.After(6 * time.Millisecond)
bar(ctx)
Expand All @@ -69,7 +69,7 @@ func main() {
}

func bar(ctx context.Context) {
tr := global.TraceProvider().Tracer("component-bar")
tr := global.TracerProvider().Tracer("component-bar")
_, span := tr.Start(ctx, "bar")
<-time.After(6 * time.Millisecond)
span.End()
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func main() {
}()

// Note: The exporter can also be used as a Batcher. E.g.
// traceProvider, err := sdktrace.NewProvider(
// tracerProvider, err := sdktrace.NewProvider(
// sdktrace.WithBatcher(exporter,
// sdktrace.WithBatchTimeout(time.Second*15),
// sdktrace.WithMaxExportBatchSize(100),
// ),
// )
traceProvider, err := sdktrace.NewProvider(sdktrace.WithBatcher(exporter))
tracerProvider, err := sdktrace.NewProvider(sdktrace.WithBatcher(exporter))
if err != nil {
log.Fatal("failed to create trace provider: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Example_insecure() {
log.Fatalf("error creating trace provider: %v\n", err)
}

global.SetTraceProvider(tp)
global.SetTracerProvider(tp)

tracer := global.Tracer("test-tracer")

Expand Down Expand Up @@ -87,7 +87,7 @@ func Example_withTLS() {
log.Fatalf("error creating trace provider: %v\n", err)
}

global.SetTraceProvider(tp)
global.SetTracerProvider(tp)

tracer := global.Tracer("test-tracer")

Expand Down
2 changes: 1 addition & 1 deletion exporters/stdout/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
)

var (
tracer = global.TraceProvider().Tracer(
tracer = global.TracerProvider().Tracer(
instrumentationName,
trace.WithInstrumentationVersion(instrumentationVersion),
)
Expand Down
4 changes: 2 additions & 2 deletions exporters/stdout/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func NewExportPipeline(exportOpts []Option, pushOpts []push.Option) (apitrace.Pr
// defer pipeline.Stop()
// ... Done
func InstallNewPipeline(exportOpts []Option, pushOpts []push.Option) (*push.Controller, error) {
traceProvider, controller, err := NewExportPipeline(exportOpts, pushOpts)
tracerProvider, controller, err := NewExportPipeline(exportOpts, pushOpts)
if err != nil {
return controller, err
}
global.SetTraceProvider(traceProvider)
global.SetTracerProvider(tracerProvider)
global.SetMeterProvider(controller.Provider())
return controller, err
}
2 changes: 1 addition & 1 deletion exporters/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func InstallNewPipeline(endpointOption EndpointOption, opts ...Option) (func(),
return nil, err
}

global.SetTraceProvider(tp)
global.SetTracerProvider(tp)
return flushFn, nil
}

Expand Down
8 changes: 4 additions & 4 deletions exporters/trace/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func TestInstallNewPipeline(t *testing.T) {
defer fn()

assert.NoError(t, err)
assert.IsType(t, tc.expectedProvider, global.TraceProvider())
assert.IsType(t, tc.expectedProvider, global.TracerProvider())

global.SetTraceProvider(nil)
global.SetTracerProvider(nil)
})
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestNewExportPipeline(t *testing.T) {
defer fn()

assert.NoError(t, err)
assert.NotEqual(t, tp, global.TraceProvider())
assert.NotEqual(t, tp, global.TracerProvider())
assert.IsType(t, tc.expectedProviderType, tp)

if tc.testSpanSampling {
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestExporter_ExportSpan(t *testing.T) {

assert.NoError(t, err)

global.SetTraceProvider(tp)
global.SetTracerProvider(tp)
_, span := global.Tracer("test-tracer").Start(context.Background(), "test-span")
span.End()

Expand Down
2 changes: 1 addition & 1 deletion exporters/trace/zipkin/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func InstallNewPipeline(collectorURL, serviceName string, opts ...Option) error
return err
}

global.SetTraceProvider(tp)
global.SetTracerProvider(tp)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions exporters/trace/zipkin/zipkin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestInstallNewPipeline(t *testing.T) {
serviceName,
)
assert.NoError(t, err)
assert.IsType(t, &sdktrace.Provider{}, global.TraceProvider())
assert.IsType(t, &sdktrace.Provider{}, global.TracerProvider())
}

func TestNewExportPipeline(t *testing.T) {
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestNewExportPipeline(t *testing.T) {
tc.options...,
)
assert.NoError(t, err)
assert.NotEqual(t, tp, global.TraceProvider())
assert.NotEqual(t, tp, global.TracerProvider())

if tc.testSpanSampling {
_, span := tp.Tracer("zipkin test").Start(context.Background(), tc.name)
Expand Down