1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-23 22:34:47 +02:00

Export NoopSpan and NoopTracer (#92)

This commit is contained in:
Isobel Redelmeier
2019-08-13 16:03:41 -07:00
committed by rghetia
parent 0db77910a7
commit 56e1a9d1f4
4 changed files with 27 additions and 27 deletions

View File

@@ -32,5 +32,5 @@ func CurrentSpan(ctx context.Context) Span {
if span, has := ctx.Value(currentSpanKey).(Span); has {
return span
}
return noopSpan{}
return NoopSpan{}
}

View File

@@ -27,7 +27,7 @@ func GlobalTracer() Tracer {
if t := global.Load(); t != nil {
return t.(Tracer)
}
return noopTracer{}
return NoopTracer{}
}
// SetGlobalTracer sets provided tracer as a global tracer.

View File

@@ -24,58 +24,58 @@ import (
"go.opentelemetry.io/api/tag"
)
type noopSpan struct {
type NoopSpan struct {
}
var _ Span = (*noopSpan)(nil)
var _ Span = (*NoopSpan)(nil)
// SpancContext returns an invalid span context.
func (noopSpan) SpanContext() core.SpanContext {
func (NoopSpan) SpanContext() core.SpanContext {
return core.EmptySpanContext()
}
// IsRecordingEvents always returns false for noopSpan.
func (noopSpan) IsRecordingEvents() bool {
// IsRecordingEvents always returns false for NoopSpan.
func (NoopSpan) IsRecordingEvents() bool {
return false
}
// SetStatus does nothing.
func (noopSpan) SetStatus(status codes.Code) {
func (NoopSpan) SetStatus(status codes.Code) {
}
// SetError does nothing.
func (noopSpan) SetError(v bool) {
func (NoopSpan) SetError(v bool) {
}
// SetAttribute does nothing.
func (noopSpan) SetAttribute(attribute core.KeyValue) {
func (NoopSpan) SetAttribute(attribute core.KeyValue) {
}
// SetAttributes does nothing.
func (noopSpan) SetAttributes(attributes ...core.KeyValue) {
func (NoopSpan) SetAttributes(attributes ...core.KeyValue) {
}
// ModifyAttribute does nothing.
func (noopSpan) ModifyAttribute(mutator tag.Mutator) {
func (NoopSpan) ModifyAttribute(mutator tag.Mutator) {
}
// ModifyAttributes does nothing.
func (noopSpan) ModifyAttributes(mutators ...tag.Mutator) {
func (NoopSpan) ModifyAttributes(mutators ...tag.Mutator) {
}
// Finish does nothing.
func (noopSpan) Finish() {
func (NoopSpan) Finish() {
}
// Tracer returns noop implementation of Tracer.
func (noopSpan) Tracer() Tracer {
return noopTracer{}
func (NoopSpan) Tracer() Tracer {
return NoopTracer{}
}
// AddEvent does nothing.
func (noopSpan) AddEvent(ctx context.Context, event event.Event) {
func (NoopSpan) AddEvent(ctx context.Context, event event.Event) {
}
// Event does nothing.
func (noopSpan) Event(ctx context.Context, msg string, attrs ...core.KeyValue) {
func (NoopSpan) Event(ctx context.Context, msg string, attrs ...core.KeyValue) {
}

View File

@@ -20,36 +20,36 @@ import (
"go.opentelemetry.io/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 {
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 {
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 {
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 {
func (t NoopTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error {
return body(ctx)
}
// Start starts a noop span.
func (noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
span := noopSpan{}
func (NoopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
span := NoopSpan{}
return SetCurrentSpan(ctx, span), span
}
// Inject does nothing.
func (noopTracer) Inject(ctx context.Context, span Span, injector Injector) {
func (NoopTracer) Inject(ctx context.Context, span Span, injector Injector) {
}