mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-11-30 08:46:54 +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:
parent
1fd93b293c
commit
9d19d8296c
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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{}
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user