2021-03-04 01:12:16 +03:00
|
|
|
package tracer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-07-29 00:40:58 +03:00
|
|
|
|
|
|
|
"go.unistack.org/micro/v4/options"
|
2021-03-04 01:12:16 +03:00
|
|
|
)
|
|
|
|
|
2023-07-04 00:23:50 +03:00
|
|
|
var _ Tracer = (*noopTracer)(nil)
|
|
|
|
|
2021-03-04 01:12:16 +03:00
|
|
|
type noopTracer struct {
|
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (t *noopTracer) Start(ctx context.Context, name string, opts ...options.Option) (context.Context, Span) {
|
2021-03-04 01:12:16 +03:00
|
|
|
span := &noopSpan{
|
|
|
|
name: name,
|
|
|
|
ctx: ctx,
|
|
|
|
tracer: t,
|
2023-01-18 00:21:18 +03:00
|
|
|
opts: NewSpanOptions(opts...),
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
if span.ctx == nil {
|
|
|
|
span.ctx = context.Background()
|
|
|
|
}
|
|
|
|
return NewSpanContext(ctx, span), span
|
|
|
|
}
|
|
|
|
|
2023-07-04 00:23:50 +03:00
|
|
|
func (t *noopTracer) Flush(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (t *noopTracer) Init(opts ...options.Option) error {
|
2021-03-04 01:12:16 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&t.opts)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *noopTracer) Name() string {
|
|
|
|
return t.opts.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopSpan struct {
|
2023-01-18 09:48:58 +03:00
|
|
|
ctx context.Context
|
|
|
|
tracer Tracer
|
|
|
|
name string
|
|
|
|
opts SpanOptions
|
|
|
|
status SpanStatus
|
|
|
|
statusMsg string
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (s *noopSpan) Finish(opts ...options.Option) {
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) Context() context.Context {
|
|
|
|
return s.ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *noopSpan) Tracer() Tracer {
|
|
|
|
return s.tracer
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (s *noopSpan) AddEvent(name string, opts ...options.Option) {
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
|
|
|
}
|
|
|
|
|
2023-01-18 00:21:18 +03:00
|
|
|
func (s *noopSpan) Kind() SpanKind {
|
|
|
|
return s.opts.Kind
|
|
|
|
}
|
|
|
|
|
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
|
2023-07-29 00:40:58 +03:00
|
|
|
func NewTracer(opts ...options.Option) Tracer {
|
2021-03-04 01:12:16 +03:00
|
|
|
return &noopTracer{
|
|
|
|
opts: NewOptions(opts...),
|
|
|
|
}
|
|
|
|
}
|