2021-03-04 01:12:16 +03:00
|
|
|
package tracer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2023-07-04 00:23:50 +03:00
|
|
|
var _ Tracer = (*noopTracer)(nil)
|
|
|
|
|
2021-03-04 01:12:16 +03:00
|
|
|
type noopTracer struct {
|
2023-09-08 13:40:01 +03:00
|
|
|
opts Options
|
|
|
|
spans []Span
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *noopTracer) Spans() []Span {
|
|
|
|
return t.spans
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
|
2023-09-08 13:40:01 +03:00
|
|
|
options := NewSpanOptions(opts...)
|
2021-03-04 01:12:16 +03:00
|
|
|
span := &noopSpan{
|
|
|
|
name: name,
|
|
|
|
ctx: ctx,
|
|
|
|
tracer: t,
|
2023-09-08 13:40:01 +03:00
|
|
|
labels: options.Labels,
|
|
|
|
kind: options.Kind,
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
if span.ctx == nil {
|
|
|
|
span.ctx = context.Background()
|
|
|
|
}
|
2023-09-08 13:40:01 +03:00
|
|
|
t.spans = append(t.spans, span)
|
2021-03-04 01:12:16 +03:00
|
|
|
return NewSpanContext(ctx, span), span
|
|
|
|
}
|
|
|
|
|
2023-07-04 00:23:50 +03:00
|
|
|
func (t *noopTracer) Flush(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-04 01:12:16 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-09-08 13:40:01 +03:00
|
|
|
type noopEvent struct {
|
|
|
|
name string
|
|
|
|
labels []interface{}
|
|
|
|
}
|
|
|
|
|
2021-03-04 01:12:16 +03:00
|
|
|
type noopSpan struct {
|
2023-01-18 09:48:58 +03:00
|
|
|
ctx context.Context
|
|
|
|
tracer Tracer
|
|
|
|
name string
|
|
|
|
statusMsg string
|
2023-09-08 13:40:01 +03:00
|
|
|
events []*noopEvent
|
|
|
|
labels []interface{}
|
|
|
|
logs []interface{}
|
|
|
|
kind SpanKind
|
|
|
|
status SpanStatus
|
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) {
|
2023-09-08 13:40:01 +03:00
|
|
|
options := NewEventOptions(opts...)
|
|
|
|
s.events = append(s.events, &noopEvent{name: name, labels: options.Labels})
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) SetName(name string) {
|
|
|
|
s.name = name
|
|
|
|
}
|
|
|
|
|
2023-09-08 13:40:01 +03:00
|
|
|
func (s *noopSpan) AddLogs(kv ...interface{}) {
|
|
|
|
s.logs = append(s.logs, kv...)
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2023-09-08 13:40:01 +03:00
|
|
|
func (s *noopSpan) AddLabels(kv ...interface{}) {
|
|
|
|
s.labels = append(s.labels, kv...)
|
2022-12-24 19:20:22 +03:00
|
|
|
}
|
|
|
|
|
2023-01-18 00:21:18 +03:00
|
|
|
func (s *noopSpan) Kind() SpanKind {
|
2023-09-08 13:40:01 +03:00
|
|
|
return s.kind
|
2023-01-18 00:21:18 +03:00
|
|
|
}
|
|
|
|
|
2023-01-18 09:48:58 +03:00
|
|
|
func (s *noopSpan) Status() (SpanStatus, string) {
|
|
|
|
return s.status, s.statusMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) SetStatus(st SpanStatus, msg string) {
|
|
|
|
s.status = st
|
|
|
|
s.statusMsg = msg
|
|
|
|
}
|
|
|
|
|
2021-03-04 01:12:16 +03:00
|
|
|
// NewTracer returns new memory tracer
|
|
|
|
func NewTracer(opts ...Option) Tracer {
|
|
|
|
return &noopTracer{
|
|
|
|
opts: NewOptions(opts...),
|
|
|
|
}
|
|
|
|
}
|