github.com/thanos-io/thanos@v0.32.5/internal/cortex/util/spanlogger/noop.go (about) 1 // Copyright (c) The Cortex Authors. 2 // Licensed under the Apache License 2.0. 3 4 package spanlogger 5 6 import ( 7 opentracing "github.com/opentracing/opentracing-go" 8 "github.com/opentracing/opentracing-go/log" 9 ) 10 11 type noopTracer struct{} 12 13 type noopSpan struct{} 14 type noopSpanContext struct{} 15 16 var ( 17 defaultNoopSpanContext = noopSpanContext{} 18 defaultNoopSpan = noopSpan{} 19 defaultNoopTracer = noopTracer{} 20 ) 21 22 const ( 23 emptyString = "" 24 ) 25 26 func (n noopSpanContext) ForeachBaggageItem(handler func(k, v string) bool) {} 27 28 func (n noopSpan) Context() opentracing.SpanContext { return defaultNoopSpanContext } 29 func (n noopSpan) SetBaggageItem(key, val string) opentracing.Span { return defaultNoopSpan } 30 func (n noopSpan) BaggageItem(key string) string { return emptyString } 31 func (n noopSpan) SetTag(key string, value interface{}) opentracing.Span { return n } 32 func (n noopSpan) LogFields(fields ...log.Field) {} 33 func (n noopSpan) LogKV(keyVals ...interface{}) {} 34 func (n noopSpan) Finish() {} 35 func (n noopSpan) FinishWithOptions(opts opentracing.FinishOptions) {} 36 func (n noopSpan) SetOperationName(operationName string) opentracing.Span { return n } 37 func (n noopSpan) Tracer() opentracing.Tracer { return defaultNoopTracer } 38 func (n noopSpan) LogEvent(event string) {} 39 func (n noopSpan) LogEventWithPayload(event string, payload interface{}) {} 40 func (n noopSpan) Log(data opentracing.LogData) {} 41 42 // StartSpan belongs to the Tracer interface. 43 func (n noopTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { 44 return defaultNoopSpan 45 } 46 47 // Inject belongs to the Tracer interface. 48 func (n noopTracer) Inject(sp opentracing.SpanContext, format interface{}, carrier interface{}) error { 49 return nil 50 } 51 52 // Extract belongs to the Tracer interface. 53 func (n noopTracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error) { 54 return nil, opentracing.ErrSpanContextNotFound 55 }