github.com/livekit/protocol@v1.16.1-0.20240517185851-47e4c6bba773/tracer/tracer.go (about) 1 // Copyright 2023 LiveKit, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tracer 16 17 import "context" 18 19 type Tracer interface { 20 Start(ctx context.Context, spanName string, opts ...interface{}) (context.Context, Span) 21 } 22 23 type Span interface { 24 RecordError(err error) 25 End() 26 } 27 28 var tracer Tracer = &NoOpTracer{} 29 30 // Can be used for your own tracing (for example, with Lightstep) 31 func SetTracer(t Tracer) { 32 tracer = t 33 } 34 35 func Start(ctx context.Context, spanName string, opts ...interface{}) (context.Context, Span) { 36 return tracer.Start(ctx, spanName, opts...) 37 } 38 39 type NoOpTracer struct{} 40 41 func (t *NoOpTracer) Start(ctx context.Context, _ string, _ ...interface{}) (context.Context, Span) { 42 return ctx, &NoOpSpan{} 43 } 44 45 type NoOpSpan struct{} 46 47 func (s *NoOpSpan) RecordError(_ error) {} 48 49 func (s *NoOpSpan) End() {}