github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/collector_noop.go (about) 1 // (c) Copyright IBM Corp. 2023 2 3 package instana 4 5 import ( 6 "context" 7 "errors" 8 9 ot "github.com/opentracing/opentracing-go" 10 ) 11 12 var ( 13 _ TracerLogger = (*noopCollector)(nil) 14 noopCollectorErrMsg string = "collector not initialized. make sure to initialize the Collector. eg: instana.InitCollector" 15 noopCollectorErr error = errors.New(noopCollectorErrMsg) 16 ) 17 18 type noopCollector struct { 19 l LeveledLogger 20 } 21 22 func newNoopCollector() TracerLogger { 23 c := &noopCollector{ 24 l: defaultLogger, 25 } 26 return c 27 } 28 29 func (c *noopCollector) Extract(format interface{}, carrier interface{}) (ot.SpanContext, error) { 30 c.l.Error(noopCollectorErrMsg) 31 return nil, noopCollectorErr 32 } 33 34 func (c *noopCollector) Inject(sm ot.SpanContext, format interface{}, carrier interface{}) error { 35 c.l.Error(noopCollectorErrMsg) 36 return noopCollectorErr 37 } 38 39 func (c *noopCollector) StartSpan(operationName string, opts ...ot.StartSpanOption) ot.Span { 40 c.l.Error(noopCollectorErrMsg) 41 return nil 42 } 43 44 func (c *noopCollector) StartSpanWithOptions(operationName string, opts ot.StartSpanOptions) ot.Span { 45 c.l.Error(noopCollectorErrMsg) 46 return nil 47 } 48 49 func (c *noopCollector) Options() TracerOptions { 50 return TracerOptions{} 51 } 52 53 func (c *noopCollector) Flush(ctx context.Context) error { 54 return noopCollectorErr 55 } 56 57 func (c *noopCollector) Debug(v ...interface{}) { 58 c.l.Error(noopCollectorErrMsg) 59 } 60 61 func (c *noopCollector) Info(v ...interface{}) { 62 c.l.Error(noopCollectorErrMsg) 63 } 64 65 func (c *noopCollector) Warn(v ...interface{}) { 66 c.l.Error(noopCollectorErrMsg) 67 } 68 69 func (c *noopCollector) Error(v ...interface{}) { 70 c.l.Error(noopCollectorErrMsg) 71 } 72 73 func (c *noopCollector) LegacySensor() *Sensor { 74 c.l.Error(noopCollectorErrMsg) 75 return nil 76 } 77 78 func (c *noopCollector) Tracer() ot.Tracer { 79 c.l.Error(noopCollectorErrMsg) 80 return nil 81 } 82 83 func (c *noopCollector) Logger() LeveledLogger { 84 c.l.Error(noopCollectorErrMsg) 85 return nil 86 } 87 88 // SetLogger sets the logger 89 func (c *noopCollector) SetLogger(l LeveledLogger) {}