From 1ab708e4b844ceb6b5db5ebd4973e3d5f81ab634 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 31 Aug 2020 10:02:04 -0700 Subject: [PATCH] Rename global SetTraceProvider and TraceProvider (#1102) * Rename global {Set,}TraceProvider Resolves #1101 * Rename unexported and testing vars --- api/global/internal/state.go | 20 ++++++++++---------- api/global/internal/trace.go | 12 ++++++------ api/global/internal/trace_test.go | 4 ++-- api/global/trace.go | 18 +++++++++--------- api/global/trace_test.go | 14 +++++++------- bridge/opentracing/mix_test.go | 2 +- example/namedtracer/main.go | 2 +- example/otel-collector/main.go | 4 ++-- example/zipkin/main.go | 4 ++-- exporters/otlp/README.md | 4 ++-- exporters/otlp/example_test.go | 4 ++-- exporters/stdout/example_test.go | 2 +- exporters/stdout/exporter.go | 4 ++-- exporters/trace/jaeger/jaeger.go | 2 +- exporters/trace/jaeger/jaeger_test.go | 8 ++++---- exporters/trace/zipkin/zipkin.go | 2 +- exporters/trace/zipkin/zipkin_test.go | 4 ++-- 17 files changed, 55 insertions(+), 55 deletions(-) diff --git a/api/global/internal/state.go b/api/global/internal/state.go index f965aa9ccec..64ff66467f2 100644 --- a/api/global/internal/state.go +++ b/api/global/internal/state.go @@ -25,7 +25,7 @@ import ( ) type ( - traceProviderHolder struct { + tracerProviderHolder struct { tp trace.Provider } @@ -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. @@ -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 } diff --git a/api/global/internal/trace.go b/api/global/internal/trace.go index 69024b66769..d9371fd2ea2 100644 --- a/api/global/internal/trace.go +++ b/api/global/internal/trace.go @@ -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. // @@ -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 } @@ -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() diff --git a/api/global/internal/trace_test.go b/api/global/internal/trace_test.go index 53781843151..bf8cc573f64 100644 --- a/api/global/internal/trace_test.go +++ b/api/global/internal/trace_test.go @@ -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() diff --git a/api/global/trace.go b/api/global/trace.go index 5c23325b751..6fcd928af90 100644 --- a/api/global/trace.go +++ b/api/global/trace.go @@ -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) } diff --git a/api/global/trace_test.go b/api/global/trace_test.go index c92a0e7db19..679bc9b9fb5 100644 --- a/api/global/trace_test.go +++ b/api/global/trace_test.go @@ -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) diff --git a/bridge/opentracing/mix_test.go b/bridge/opentracing/mix_test.go index 70d805375a6..315d83216c2 100644 --- a/bridge/opentracing/mix_test.go +++ b/bridge/opentracing/mix_test.go @@ -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) diff --git a/example/namedtracer/main.go b/example/namedtracer/main.go index 942961dd7be..373514f3708 100644 --- a/example/namedtracer/main.go +++ b/example/namedtracer/main.go @@ -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() { diff --git a/example/otel-collector/main.go b/example/otel-collector/main.go index 0512984c435..719c8d46a9a 100644 --- a/example/otel-collector/main.go +++ b/example/otel-collector/main.go @@ -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 @@ -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() diff --git a/example/zipkin/main.go b/example/zipkin/main.go index ed85056d39f..c853be6ae9d 100644 --- a/example/zipkin/main.go +++ b/example/zipkin/main.go @@ -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) @@ -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() diff --git a/exporters/otlp/README.md b/exporters/otlp/README.md index dfb9697ea5c..e968ff3699b 100644 --- a/exporters/otlp/README.md +++ b/exporters/otlp/README.md @@ -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) } diff --git a/exporters/otlp/example_test.go b/exporters/otlp/example_test.go index 5cf14f92b6f..fdaf346ccfe 100644 --- a/exporters/otlp/example_test.go +++ b/exporters/otlp/example_test.go @@ -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") @@ -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") diff --git a/exporters/stdout/example_test.go b/exporters/stdout/example_test.go index ff7c0144b60..082dfb130f7 100644 --- a/exporters/stdout/example_test.go +++ b/exporters/stdout/example_test.go @@ -31,7 +31,7 @@ const ( ) var ( - tracer = global.TraceProvider().Tracer( + tracer = global.TracerProvider().Tracer( instrumentationName, trace.WithInstrumentationVersion(instrumentationVersion), ) diff --git a/exporters/stdout/exporter.go b/exporters/stdout/exporter.go index 49d25468d29..fa5f3418a61 100644 --- a/exporters/stdout/exporter.go +++ b/exporters/stdout/exporter.go @@ -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 } diff --git a/exporters/trace/jaeger/jaeger.go b/exporters/trace/jaeger/jaeger.go index 77fac532f9c..29ba1db91ad 100644 --- a/exporters/trace/jaeger/jaeger.go +++ b/exporters/trace/jaeger/jaeger.go @@ -178,7 +178,7 @@ func InstallNewPipeline(endpointOption EndpointOption, opts ...Option) (func(), return nil, err } - global.SetTraceProvider(tp) + global.SetTracerProvider(tp) return flushFn, nil } diff --git a/exporters/trace/jaeger/jaeger_test.go b/exporters/trace/jaeger/jaeger_test.go index a0fcb6e8350..f4dfcb592fd 100644 --- a/exporters/trace/jaeger/jaeger_test.go +++ b/exporters/trace/jaeger/jaeger_test.go @@ -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) }) } } @@ -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 { @@ -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() diff --git a/exporters/trace/zipkin/zipkin.go b/exporters/trace/zipkin/zipkin.go index 7c16d61b5bc..3c0577c6db4 100644 --- a/exporters/trace/zipkin/zipkin.go +++ b/exporters/trace/zipkin/zipkin.go @@ -133,7 +133,7 @@ func InstallNewPipeline(collectorURL, serviceName string, opts ...Option) error return err } - global.SetTraceProvider(tp) + global.SetTracerProvider(tp) return nil } diff --git a/exporters/trace/zipkin/zipkin_test.go b/exporters/trace/zipkin/zipkin_test.go index c77f633b89d..9dc17761e42 100644 --- a/exporters/trace/zipkin/zipkin_test.go +++ b/exporters/trace/zipkin/zipkin_test.go @@ -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) { @@ -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)