github.com/facebookincubator/go-belt@v0.0.0-20230703220935-39cd348f1a38/tool/experimental/tracer/noop_tracer.go (about) 1 // Copyright 2022 Meta Platforms, Inc. and affiliates. 2 // 3 // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 // 5 // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 // 7 // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 // 9 // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 // 11 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 13 package tracer 14 15 import ( 16 "context" 17 "time" 18 19 "github.com/facebookincubator/go-belt" 20 "github.com/facebookincubator/go-belt/pkg/field" 21 ) 22 23 // NoopSpan is a no-op implementation of a Tracer. Supposed 24 // to be used as a dummy placeholder if no Tracer is set. 25 type noopTracer struct{} 26 27 // WithContextFields implements Tracer. 28 func (t noopTracer) WithContextFields(allFields *field.FieldsChain, newFieldsCount int) belt.Tool { 29 return t 30 } 31 32 // WithTraceIDs implements Tracer. 33 func (t noopTracer) WithTraceIDs(traceIDs belt.TraceIDs, newTraceIDsCount int) belt.Tool { 34 return t 35 } 36 37 // Start implements Tracer. 38 func (noopTracer) Start(name string, parent Span, options ...SpanOption) Span { 39 return NewNoopSpan(name, parent, time.Time{}) 40 } 41 42 // StartWithBelt implements Tracer. 43 func (noopTracer) StartWithBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt) { 44 span := NewNoopSpan(name, nil, time.Time{}) 45 return span, BeltWithSpan(belt, span) 46 } 47 48 // StartChildWithBelt implements Tracer. 49 func (noopTracer) StartChildWithBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt) { 50 span := NewNoopSpan(name, SpanFromBelt(belt), time.Time{}) 51 return span, BeltWithSpan(belt, span) 52 } 53 54 // StartWithCtx implements Tracer. 55 func (noopTracer) StartWithCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context) { 56 span := NewNoopSpan(name, nil, time.Time{}) 57 return span, CtxWithSpan(ctx, span) 58 } 59 60 // StartChildWithCtx implements Tracer. 61 func (noopTracer) StartChildWithCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context) { 62 span := NewNoopSpan(name, SpanFromCtx(ctx), time.Time{}) 63 return span, CtxWithSpan(ctx, span) 64 } 65 66 // WithPreHooks implements Tracer. 67 func (t noopTracer) WithPreHooks(...Hook) Tracer { 68 return t 69 } 70 71 // WithHooks implements Tracer. 72 func (t noopTracer) WithHooks(...Hook) Tracer { 73 return t 74 } 75 76 // Flush implements Tracer. 77 func (noopTracer) Flush() {}