github.com/mailgun/holster/v4@v4.20.0/tracing/dummy_span.go (about) 1 package tracing 2 3 import ( 4 "context" 5 6 "go.opentelemetry.io/otel/attribute" 7 "go.opentelemetry.io/otel/codes" 8 "go.opentelemetry.io/otel/trace" 9 "go.opentelemetry.io/otel/trace/embedded" 10 ) 11 12 // DummySpan is used to create a stub span as a placeholder for spans not 13 // intended for export. 14 // This is used to selectively disable tracing individual spans based on 15 // criteria, such as log level. 16 // Any child spans created from a DummySpan will be linked to the dummy's 17 // next non-dummy ancestor. 18 type DummySpan struct { 19 embedded.Span 20 21 // Next non-dummy parent span. 22 parentSpan trace.Span 23 } 24 25 // newDummySpan creates a dummy span as a child of provided parent span. 26 func newDummySpan(ctx context.Context) (context.Context, trace.Span) { 27 span := &DummySpan{ 28 parentSpan: trace.SpanFromContext(ctx), 29 } 30 ctx = trace.ContextWithSpan(ctx, span) 31 32 return ctx, span 33 } 34 35 func (s *DummySpan) End(options ...trace.SpanEndOption) { 36 // no-op 37 } 38 39 func (s *DummySpan) AddEvent(name string, options ...trace.EventOption) { 40 // no-op 41 } 42 43 func (s *DummySpan) IsRecording() bool { 44 return s.parentSpan.IsRecording() 45 } 46 47 func (s *DummySpan) RecordError(err error, options ...trace.EventOption) { 48 // no-op 49 } 50 51 func (s *DummySpan) SpanContext() trace.SpanContext { 52 return s.parentSpan.SpanContext() 53 } 54 55 func (s *DummySpan) SetStatus(code codes.Code, description string) { 56 // no-op 57 } 58 59 func (s *DummySpan) SetName(name string) { 60 // no-op 61 } 62 63 func (s *DummySpan) SetAttributes(kv ...attribute.KeyValue) { 64 // no-op 65 } 66 67 func (s *DummySpan) TracerProvider() trace.TracerProvider { 68 return s.parentSpan.TracerProvider() 69 } 70 71 func (s *DummySpan) AddLink(trace.Link) { 72 // no-op 73 }