Skip to content

Commit

Permalink
Clear NoopTracer implementation and improve Tracer argument names (#314)
Browse files Browse the repository at this point in the history
* clean dead code from noop tracer

* rename arguments from the Tracer interface's methods

* remove service, resources and component options from sdk/tracer and mock tracer

* remove unused fields from sdk/tracer
  • Loading branch information
paivagustavo authored and rghetia committed Nov 14, 2019
1 parent 1fd93b2 commit 9d19d82
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 59 deletions.
12 changes: 6 additions & 6 deletions api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ type Provider interface {

type Tracer interface {
// Start a span.
Start(context.Context, string, ...SpanOption) (context.Context, Span)
Start(ctx context.Context, spanName string, startOpts ...SpanOption) (context.Context, Span)

// WithSpan wraps the execution of the function body with a span.
// It starts a new span and sets it as an active span in the context.
// It then executes the body. It closes the span before returning the execution result.
// WithSpan wraps the execution of the fn function with a span.
// It starts a new span, sets it as an active span in the context,
// executes the fn function and closes the span before returning the result of fn.
WithSpan(
ctx context.Context,
operation string,
body func(ctx context.Context) error,
spanName string,
fn func(ctx context.Context) error,
) error
}

Expand Down
17 changes: 0 additions & 17 deletions api/trace/noop_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,12 @@ package trace

import (
"context"

"go.opentelemetry.io/otel/api/core"
)

type NoopTracer struct{}

var _ Tracer = NoopTracer{}

// WithResources does nothing and returns noop implementation of Tracer.
func (t NoopTracer) WithResources(attributes ...core.KeyValue) Tracer {
return t
}

// WithComponent does nothing and returns noop implementation of Tracer.
func (t NoopTracer) WithComponent(name string) Tracer {
return t
}

// WithService does nothing and returns noop implementation of Tracer.
func (t NoopTracer) WithService(name string) Tracer {
return t
}

// WithSpan wraps around execution of func with noop span.
func (t NoopTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error {
return body(ctx)
Expand Down
15 changes: 0 additions & 15 deletions internal/trace/mock_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ type MockTracer struct {

var _ apitrace.Tracer = (*MockTracer)(nil)

// WithResources does nothing and returns MockTracer implementation of Tracer.
func (mt *MockTracer) WithResources(attributes ...core.KeyValue) apitrace.Tracer {
return mt
}

// WithComponent does nothing and returns MockTracer implementation of Tracer.
func (mt *MockTracer) WithComponent(name string) apitrace.Tracer {
return mt
}

// WithService does nothing and returns MockTracer implementation of Tracer.
func (mt *MockTracer) WithService(name string) apitrace.Tracer {
return mt
}

// WithSpan does nothing except executing the body.
func (mt *MockTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error {
return body(ctx)
Expand Down
23 changes: 2 additions & 21 deletions sdk/trace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (
)

type tracer struct {
provider *Provider
name string
component string
resources []core.KeyValue
provider *Provider
name string
}

var _ apitrace.Tracer = &tracer{}
Expand Down Expand Up @@ -90,23 +88,6 @@ func (tr *tracer) WithSpan(ctx context.Context, name string, body func(ctx conte
return nil
}

func (tr *tracer) WithService(name string) apitrace.Tracer {
tr.name = name
return tr
}

// WithResources does nothing and returns noop implementation of apitrace.Tracer.
func (tr *tracer) WithResources(res ...core.KeyValue) apitrace.Tracer {
tr.resources = res
return tr
}

// WithComponent does nothing and returns noop implementation of apitrace.Tracer.
func (tr *tracer) WithComponent(component string) apitrace.Tracer {
tr.component = component
return tr
}

func (tr *tracer) spanNameWithPrefix(name string) string {
if tr.name != "" {
return tr.name + "/" + name
Expand Down

0 comments on commit 9d19d82

Please sign in to comment.