You've already forked opentelemetry-go
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:
committed by
rghetia
parent
0db77910a7
commit
56e1a9d1f4
@@ -32,5 +32,5 @@ func CurrentSpan(ctx context.Context) Span {
|
|||||||
if span, has := ctx.Value(currentSpanKey).(Span); has {
|
if span, has := ctx.Value(currentSpanKey).(Span); has {
|
||||||
return span
|
return span
|
||||||
}
|
}
|
||||||
return noopSpan{}
|
return NoopSpan{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func GlobalTracer() Tracer {
|
|||||||
if t := global.Load(); t != nil {
|
if t := global.Load(); t != nil {
|
||||||
return t.(Tracer)
|
return t.(Tracer)
|
||||||
}
|
}
|
||||||
return noopTracer{}
|
return NoopTracer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetGlobalTracer sets provided tracer as a global tracer.
|
// SetGlobalTracer sets provided tracer as a global tracer.
|
||||||
|
|||||||
@@ -24,58 +24,58 @@ import (
|
|||||||
"go.opentelemetry.io/api/tag"
|
"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.
|
// SpancContext returns an invalid span context.
|
||||||
func (noopSpan) SpanContext() core.SpanContext {
|
func (NoopSpan) SpanContext() core.SpanContext {
|
||||||
return core.EmptySpanContext()
|
return core.EmptySpanContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRecordingEvents always returns false for noopSpan.
|
// IsRecordingEvents always returns false for NoopSpan.
|
||||||
func (noopSpan) IsRecordingEvents() bool {
|
func (NoopSpan) IsRecordingEvents() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStatus does nothing.
|
// SetStatus does nothing.
|
||||||
func (noopSpan) SetStatus(status codes.Code) {
|
func (NoopSpan) SetStatus(status codes.Code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetError does nothing.
|
// SetError does nothing.
|
||||||
func (noopSpan) SetError(v bool) {
|
func (NoopSpan) SetError(v bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAttribute does nothing.
|
// SetAttribute does nothing.
|
||||||
func (noopSpan) SetAttribute(attribute core.KeyValue) {
|
func (NoopSpan) SetAttribute(attribute core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAttributes does nothing.
|
// SetAttributes does nothing.
|
||||||
func (noopSpan) SetAttributes(attributes ...core.KeyValue) {
|
func (NoopSpan) SetAttributes(attributes ...core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyAttribute does nothing.
|
// ModifyAttribute does nothing.
|
||||||
func (noopSpan) ModifyAttribute(mutator tag.Mutator) {
|
func (NoopSpan) ModifyAttribute(mutator tag.Mutator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyAttributes does nothing.
|
// ModifyAttributes does nothing.
|
||||||
func (noopSpan) ModifyAttributes(mutators ...tag.Mutator) {
|
func (NoopSpan) ModifyAttributes(mutators ...tag.Mutator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish does nothing.
|
// Finish does nothing.
|
||||||
func (noopSpan) Finish() {
|
func (NoopSpan) Finish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tracer returns noop implementation of Tracer.
|
// Tracer returns noop implementation of Tracer.
|
||||||
func (noopSpan) Tracer() Tracer {
|
func (NoopSpan) Tracer() Tracer {
|
||||||
return noopTracer{}
|
return NoopTracer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEvent does nothing.
|
// AddEvent does nothing.
|
||||||
func (noopSpan) AddEvent(ctx context.Context, event event.Event) {
|
func (NoopSpan) AddEvent(ctx context.Context, event event.Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event does nothing.
|
// 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) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,36 +20,36 @@ import (
|
|||||||
"go.opentelemetry.io/api/core"
|
"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.
|
// 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
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithComponent does nothing and returns noop implementation of Tracer.
|
// 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
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithService does nothing and returns noop implementation of Tracer.
|
// 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
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts a noop span.
|
// Start starts a noop span.
|
||||||
func (noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
|
func (NoopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
|
||||||
span := noopSpan{}
|
span := NoopSpan{}
|
||||||
return SetCurrentSpan(ctx, span), span
|
return SetCurrentSpan(ctx, span), span
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject does nothing.
|
// Inject does nothing.
|
||||||
func (noopTracer) Inject(ctx context.Context, span Span, injector Injector) {
|
func (NoopTracer) Inject(ctx context.Context, span Span, injector Injector) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user