From 56e1a9d1f4ee0f840e45584ded55f8dee5cfbc2c Mon Sep 17 00:00:00 2001 From: Isobel Redelmeier Date: Tue, 13 Aug 2019 16:03:41 -0700 Subject: [PATCH] Export NoopSpan and NoopTracer (#92) --- api/trace/current.go | 2 +- api/trace/global.go | 2 +- api/trace/noop_span.go | 32 ++++++++++++++++---------------- api/trace/noop_trace.go | 18 +++++++++--------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/api/trace/current.go b/api/trace/current.go index 5eca012c7..abadaa4fe 100644 --- a/api/trace/current.go +++ b/api/trace/current.go @@ -32,5 +32,5 @@ func CurrentSpan(ctx context.Context) Span { if span, has := ctx.Value(currentSpanKey).(Span); has { return span } - return noopSpan{} + return NoopSpan{} } diff --git a/api/trace/global.go b/api/trace/global.go index d51436676..c85d775d5 100644 --- a/api/trace/global.go +++ b/api/trace/global.go @@ -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. diff --git a/api/trace/noop_span.go b/api/trace/noop_span.go index 337edcd31..f15fe2726 100644 --- a/api/trace/noop_span.go +++ b/api/trace/noop_span.go @@ -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) { } diff --git a/api/trace/noop_trace.go b/api/trace/noop_trace.go index ab44fa483..8a5902323 100644 --- a/api/trace/noop_trace.go +++ b/api/trace/noop_trace.go @@ -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) { }