github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/tracer/tracer.go (about) 1 package tracer 2 3 import "context" 4 5 type Tracer interface { 6 Start(ctx context.Context, spanName string, opts ...interface{}) (context.Context, Span) 7 } 8 9 type Span interface { 10 RecordError(err error) 11 End() 12 } 13 14 var tracer Tracer = &NoOpTracer{} 15 16 // Can be used for your own tracing (for example, with Lightstep) 17 func SetTracer(t Tracer) { 18 tracer = t 19 } 20 21 func Start(ctx context.Context, spanName string, opts ...interface{}) (context.Context, Span) { 22 return tracer.Start(ctx, spanName, opts...) 23 } 24 25 type NoOpTracer struct{} 26 27 func (t *NoOpTracer) Start(ctx context.Context, _ string, _ ...interface{}) (context.Context, Span) { 28 return ctx, &NoOpSpan{} 29 } 30 31 type NoOpSpan struct{} 32 33 func (s *NoOpSpan) RecordError(_ error) {} 34 35 func (s *NoOpSpan) End() {}