Skip to content

Commit

Permalink
Rename GetTracer to Tracer (#347)
Browse files Browse the repository at this point in the history
* Rename GetTracer to NewTracer

* Drop New prefix
  • Loading branch information
ferhatelmas authored and rghetia committed Nov 25, 2019
1 parent 059ca3e commit 0f052af
Show file tree
Hide file tree
Showing 26 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
)

type Provider interface {
// GetTracer creates a named tracer that implements Tracer interface.
// Tracer creates a named tracer that implements Tracer interface.
// If the name is an empty string then provider uses default name.
GetTracer(name string) Tracer
Tracer(name string) Tracer
}

type Tracer interface {
Expand Down
4 changes: 2 additions & 2 deletions api/trace/noop_trace_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type NoopProvider struct{}

var _ Provider = NoopProvider{}

// GetTracer returns noop implementation of Tracer.
func (p NoopProvider) GetTracer(name string) Tracer {
// Tracer returns noop implementation of Tracer.
func (p NoopProvider) Tracer(name string) Tracer {
return NoopTracer{}
}
6 changes: 3 additions & 3 deletions bridge/opentracing/mix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (tm *tracerMessTest) setup(t *testing.T, tracer *internal.MockTracer) {

func (tm *tracerMessTest) check(t *testing.T, tracer *internal.MockTracer) {
globalOtTracer := ot.GlobalTracer()
globalOtelTracer := global.TraceProvider().GetTracer("")
globalOtelTracer := global.TraceProvider().Tracer("")
if len(tm.recordedOTSpanTracers) != 3 {
t.Errorf("Expected 3 recorded OpenTracing tracers from spans, got %d", len(tm.recordedOTSpanTracers))
}
Expand Down Expand Up @@ -535,7 +535,7 @@ func min(a, b int) int {
}

func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func(*testing.T, context.Context)) {
tr := global.TraceProvider().GetTracer("")
tr := global.TraceProvider().Tracer("")
ctx, span := tr.Start(ctx, fmt.Sprintf("%s_Otel_OTOtel", name), oteltrace.WithSpanKind(oteltrace.SpanKindClient))
defer span.End()
callback(t, ctx)
Expand All @@ -552,7 +552,7 @@ func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func
}

func runOTOtelOT(t *testing.T, ctx context.Context, name string, callback func(*testing.T, context.Context)) {
tr := global.TraceProvider().GetTracer("")
tr := global.TraceProvider().Tracer("")
span, ctx := ot.StartSpanFromContext(ctx, fmt.Sprintf("%s_OT_OtelOT", name), ot.Tag{Key: "span.kind", Value: "client"})
defer span.Finish()
callback(t, ctx)
Expand Down
2 changes: 1 addition & 1 deletion bridge/opentracing/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import (
func NewTracerPair(tracer oteltrace.Tracer) (*BridgeTracer, *WrapperProvider) {
bridgeTracer := NewBridgeTracer()
wrapperProvider := NewWrappedProvider(bridgeTracer, tracer)
bridgeTracer.SetOpenTelemetryTracer(wrapperProvider.GetTracer(""))
bridgeTracer.SetOpenTelemetryTracer(wrapperProvider.Tracer(""))
return bridgeTracer, wrapperProvider
}
6 changes: 3 additions & 3 deletions bridge/opentracing/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ type WrapperProvider struct {

var _ oteltrace.Provider = (*WrapperProvider)(nil)

// GetTracer returns the WrapperTracer associated with the WrapperProvider.
func (p *WrapperProvider) GetTracer(name string) oteltrace.Tracer {
// Tracer returns the WrapperTracer associated with the WrapperProvider.
func (p *WrapperProvider) Tracer(name string) oteltrace.Tracer {
return p.wTracer
}

// WrapperProvider creates a new trace provider that creates a single
// NewWrappedProvider 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{
Expand Down
2 changes: 1 addition & 1 deletion example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func main() {
// Note: Have to get the meter and tracer after the global is
// initialized. See OTEP 0005.

tracer := global.TraceProvider().GetTracer("ex.com/basic")
tracer := global.TraceProvider().Tracer("ex.com/basic")
meter := global.MeterProvider().GetMeter("ex.com/basic")

oneMetric := meter.NewFloat64Gauge("ex.com.one",
Expand Down
2 changes: 1 addition & 1 deletion example/http-stackdriver/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func initTracer() {

func main() {
initTracer()
tr := global.TraceProvider().GetTracer("stackdriver/example/client")
tr := global.TraceProvider().Tracer("stackdriver/example/client")

client := http.DefaultClient
ctx := distributedcontext.NewContext(context.Background(),
Expand Down
2 changes: 1 addition & 1 deletion example/http-stackdriver/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func initTracer() {
func main() {
initTracer()

tr := global.TraceProvider().GetTracer("stackdriver/example/server")
tr := global.TraceProvider().Tracer("stackdriver/example/server")

helloHandler := func(w http.ResponseWriter, req *http.Request) {
attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
Expand Down
2 changes: 1 addition & 1 deletion example/http/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func main() {

var body []byte

tr := global.TraceProvider().GetTracer("example/client")
tr := global.TraceProvider().Tracer("example/client")
err := tr.WithSpan(ctx, "say hello",
func(ctx context.Context) error {
req, _ := http.NewRequest("GET", "http://localhost:7777/hello", nil)
Expand Down
2 changes: 1 addition & 1 deletion example/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func initTracer() {

func main() {
initTracer()
tr := global.TraceProvider().GetTracer("example/server")
tr := global.TraceProvider().Tracer("example/server")

helloHandler := func(w http.ResponseWriter, req *http.Request) {
attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
Expand Down
4 changes: 2 additions & 2 deletions example/jaeger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func main() {

ctx := context.Background()

tr := global.TraceProvider().GetTracer("component-main")
tr := global.TraceProvider().Tracer("component-main")
ctx, span := tr.Start(ctx, "foo")
bar(ctx)
span.End()
}

func bar(ctx context.Context) {
tr := global.TraceProvider().GetTracer("component-bar")
tr := global.TraceProvider().Tracer("component-bar")
_, span := tr.Start(ctx, "bar")
defer span.End()

Expand Down
2 changes: 1 addition & 1 deletion example/namedtracer/foo/foo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func SubOperation(ctx context.Context) error {

// Using global provider. Alternative is to have application provide a getter
// for its component to get the instance of the provider.
tr := global.TraceProvider().GetTracer("example/namedtracer/foo")
tr := global.TraceProvider().Tracer("example/namedtracer/foo")
return tr.WithSpan(
ctx,
"Sub operation...",
Expand Down
2 changes: 1 addition & 1 deletion example/namedtracer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
initTracer()

// Create a named tracer with package path as its name.
tracer := tp.GetTracer("example/namedtracer/main")
tracer := tp.Tracer("example/namedtracer/main")
ctx := context.Background()

ctx = distributedcontext.NewContext(ctx,
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestExporter_ExportSpan(t *testing.T) {
assert.NoError(t, err)

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

assert.True(t, span.SpanContext().IsValid())
Expand Down
4 changes: 2 additions & 2 deletions exporter/trace/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestExporter_ExportSpans(t *testing.T) {
assert.NoError(t, err)

global.SetTraceProvider(tp)
_, span := global.TraceProvider().GetTracer("test-tracer").Start(context.Background(), "test-span")
_, span := global.TraceProvider().Tracer("test-tracer").Start(context.Background(), "test-span")
span.End()
assert.True(t, span.SpanContext().IsValid())

Expand Down Expand Up @@ -145,7 +145,7 @@ func TestExporter_Timeout(t *testing.T) {
assert.NoError(t, err)

global.SetTraceProvider(tp)
_, span := global.TraceProvider().GetTracer("test-tracer").Start(context.Background(), "test-span")
_, span := global.TraceProvider().Tracer("test-tracer").Start(context.Background(), "test-span")
span.End()
assert.True(t, span.SpanContext().IsValid())

Expand Down
2 changes: 1 addition & 1 deletion global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
// TraceProvider 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().GetTracer("example.com/foo")
// tracer := global.TraceProvider().Tracer("example.com/foo")
func TraceProvider() trace.Provider {
if gp := globalTracer.Load(); gp != nil {
return gp.(traceProvider).tp
Expand Down
4 changes: 2 additions & 2 deletions global/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ var (
_ metric.Provider = &testMeterProvider{}
)

func (*testTraceProvider) GetTracer(name string) trace.Tracer {
func (*testTraceProvider) Tracer(_ string) trace.Tracer {
return &trace.NoopTracer{}
}

func (*testMeterProvider) GetMeter(name string) metric.Meter {
func (*testMeterProvider) GetMeter(_ string) metric.Meter {
return &metric.NoopMeter{}
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/httptrace/clienttrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewClientTrace(ctx context.Context) *httptrace.ClientTrace {
activeHooks: make(map[string]trace.Span),
}

ct.tr = global.TraceProvider().GetTracer("go.opentelemetry.io/otel/plugin/httptrace")
ct.tr = global.TraceProvider().Tracer("go.opentelemetry.io/otel/plugin/httptrace")
ct.start("http.request", "http.request")

return &httptrace.ClientTrace{
Expand Down
2 changes: 1 addition & 1 deletion plugin/httptrace/clienttrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestHTTPRequestWithClientTrace(t *testing.T) {
tp, _ := sdktrace.NewProvider(sdktrace.WithSyncer(exp), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}))
global.SetTraceProvider(tp)

tr := tp.GetTracer("httptrace/client")
tr := tp.Tracer("httptrace/client")

// Mock http server
ts := httptest.NewServer(
Expand Down
2 changes: 1 addition & 1 deletion plugin/othttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func WithMessageEvents(events ...event) Option {
func NewHandler(handler http.Handler, operation string, opts ...Option) http.Handler {
h := Handler{handler: handler, operation: operation}
defaultOpts := []Option{
WithTracer(global.TraceProvider().GetTracer("go.opentelemetry.io/plugin/othttp")),
WithTracer(global.TraceProvider().Tracer("go.opentelemetry.io/plugin/othttp")),
WithPropagator(prop.HTTPTraceContextPropagator{}),
WithSpanOptions(trace.WithSpanKind(trace.SpanKindServer)),
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/batch_span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
t.Errorf("%s: Error creating new instance of BatchSpanProcessor\n", option.name)
}
tp.RegisterSpanProcessor(ssp)
tr := tp.GetTracer("BatchSpanProcessorWithOptions")
tr := tp.Tracer("BatchSpanProcessorWithOptions")

generateSpan(t, tr, option)

Expand Down
8 changes: 4 additions & 4 deletions sdk/trace/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ func BenchmarkSpanID_DotString(b *testing.B) {
func traceBenchmark(b *testing.B, name string, fn func(*testing.B, apitrace.Tracer)) {
b.Run("AlwaysSample", func(b *testing.B) {
b.ReportAllocs()
fn(b, getTracer(b, name, sdktrace.AlwaysSample()))
fn(b, tracer(b, name, sdktrace.AlwaysSample()))
})
b.Run("NeverSample", func(b *testing.B) {
b.ReportAllocs()
fn(b, getTracer(b, name, sdktrace.NeverSample()))
fn(b, tracer(b, name, sdktrace.NeverSample()))
})
}

func getTracer(b *testing.B, name string, sampler sdktrace.Sampler) apitrace.Tracer {
func tracer(b *testing.B, name string, sampler sdktrace.Sampler) apitrace.Tracer {
tp, err := sdktrace.NewProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sampler}))
if err != nil {
b.Fatalf("Failed to create trace provider for test %s\n", name)
}
return tp.GetTracer(name)
return tp.Tracer(name)
}
4 changes: 2 additions & 2 deletions sdk/trace/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func NewProvider(opts ...ProviderOption) (*Provider, error) {
return tp, nil
}

// GetTracer with the given name. If a tracer for the given name does not exist,
// Tracer with the given name. If a tracer for the given name does not exist,
// it is created first. If the name is empty, DefaultTracerName is used.
func (p *Provider) GetTracer(name string) apitrace.Tracer {
func (p *Provider) Tracer(name string) apitrace.Tracer {
p.mu.Lock()
defer p.mu.Unlock()
if name == "" {
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/simple_span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestSimpleSpanProcessorOnEnd(t *testing.T) {
}

tp.RegisterSpanProcessor(ssp)
tr := tp.GetTracer("SimpleSpanProcessor")
tr := tp.Tracer("SimpleSpanProcessor")
tid, _ := core.TraceIDFromHex("01020304050607080102040810203040")
sid, _ := core.SpanIDFromHex("0102040810203040")
sc := core.SpanContext{
Expand Down
6 changes: 3 additions & 3 deletions sdk/trace/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestRegisterSpanProcessort(t *testing.T) {
sp := NewTestSpanProcessor()
tp.RegisterSpanProcessor(sp)

tr := tp.GetTracer("SpanProcessor")
tr := tp.Tracer("SpanProcessor")
_, span := tr.Start(context.Background(), "OnStart")
span.End()
wantCount := 1
Expand All @@ -65,7 +65,7 @@ func TestUnregisterSpanProcessor(t *testing.T) {
sp := NewTestSpanProcessor()
tp.RegisterSpanProcessor(sp)

tr := tp.GetTracer("SpanProcessor")
tr := tp.Tracer("SpanProcessor")
_, span := tr.Start(context.Background(), "OnStart")
span.End()
tp.UnregisterSpanProcessor(sp)
Expand All @@ -92,7 +92,7 @@ func TestUnregisterSpanProcessorWhileSpanIsActive(t *testing.T) {
sp := NewTestSpanProcessor()
tp.RegisterSpanProcessor(sp)

tr := tp.GetTracer("SpanProcessor")
tr := tp.Tracer("SpanProcessor")
_, span := tr.Start(context.Background(), "OnStart")
tp.UnregisterSpanProcessor(sp)

Expand Down
Loading

0 comments on commit 0f052af

Please sign in to comment.