1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-02 08:52:21 +02:00

Clear NoopTracer implementation and improve Tracer argument names (#314)

* 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
This commit is contained in:
Gustavo Silva Paiva 2019-11-14 14:50:20 -04:00 committed by rghetia
parent 1fd93b293c
commit 9d19d8296c
4 changed files with 8 additions and 59 deletions

View File

@ -31,15 +31,15 @@ type Provider interface {
type Tracer interface { type Tracer interface {
// Start a span. // 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. // WithSpan wraps the execution of the fn function with a span.
// It starts a new span and sets it as an active span in the context. // It starts a new span, sets it as an active span in the context,
// It then executes the body. It closes the span before returning the execution result. // executes the fn function and closes the span before returning the result of fn.
WithSpan( WithSpan(
ctx context.Context, ctx context.Context,
operation string, spanName string,
body func(ctx context.Context) error, fn func(ctx context.Context) error,
) error ) error
} }

View File

@ -16,29 +16,12 @@ package trace
import ( import (
"context" "context"
"go.opentelemetry.io/otel/api/core"
) )
type NoopTracer struct{} type NoopTracer struct{}
var _ Tracer = NoopTracer{} 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. // WithSpan wraps around execution of func with noop span.
func (t NoopTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error { func (t NoopTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error {
return body(ctx) return body(ctx)

View File

@ -38,21 +38,6 @@ type MockTracer struct {
var _ apitrace.Tracer = (*MockTracer)(nil) 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. // WithSpan does nothing except executing the body.
func (mt *MockTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error { func (mt *MockTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error {
return body(ctx) return body(ctx)

View File

@ -24,8 +24,6 @@ import (
type tracer struct { type tracer struct {
provider *Provider provider *Provider
name string name string
component string
resources []core.KeyValue
} }
var _ apitrace.Tracer = &tracer{} var _ apitrace.Tracer = &tracer{}
@ -90,23 +88,6 @@ func (tr *tracer) WithSpan(ctx context.Context, name string, body func(ctx conte
return nil 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 { func (tr *tracer) spanNameWithPrefix(name string) string {
if tr.name != "" { if tr.name != "" {
return tr.name + "/" + name return tr.name + "/" + name