2021-03-04 01:12:16 +03:00
|
|
|
package tracer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type noopTracer struct {
|
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
|
|
|
|
span := &noopSpan{
|
|
|
|
name: name,
|
|
|
|
ctx: ctx,
|
|
|
|
tracer: t,
|
|
|
|
}
|
|
|
|
if span.ctx == nil {
|
|
|
|
span.ctx = context.Background()
|
|
|
|
}
|
|
|
|
return NewSpanContext(ctx, span), span
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *noopTracer) Init(opts ...Option) error {
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&t.opts)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *noopTracer) Name() string {
|
|
|
|
return t.opts.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopSpan struct {
|
|
|
|
ctx context.Context
|
|
|
|
tracer Tracer
|
2021-03-06 19:45:13 +03:00
|
|
|
name string
|
2022-12-24 18:09:48 +03:00
|
|
|
opts SpanOptions
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) Finish(opts ...SpanOption) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) Context() context.Context {
|
|
|
|
return s.ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) Tracer() Tracer {
|
|
|
|
return s.tracer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) AddEvent(name string, opts ...EventOption) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) SetName(name string) {
|
|
|
|
s.name = name
|
|
|
|
}
|
|
|
|
|
2022-12-24 18:09:48 +03:00
|
|
|
func (s *noopSpan) SetLabels(labels ...interface{}) {
|
|
|
|
s.opts.Labels = labels
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2022-12-24 19:20:22 +03:00
|
|
|
func (s *noopSpan) AddLabels(labels ...interface{}) {
|
|
|
|
s.opts.Labels = append(s.opts.Labels, labels...)
|
|
|
|
}
|
|
|
|
|
2021-03-04 01:12:16 +03:00
|
|
|
// NewTracer returns new memory tracer
|
|
|
|
func NewTracer(opts ...Option) Tracer {
|
|
|
|
return &noopTracer{
|
|
|
|
opts: NewOptions(opts...),
|
|
|
|
}
|
|
|
|
}
|