2020-11-03 02:02:32 +03:00
|
|
|
// Package tracer provides an interface for distributed tracing
|
2020-09-10 00:06:29 +03:00
|
|
|
package tracer
|
2020-01-18 13:20:46 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2020-09-10 00:06:29 +03:00
|
|
|
var (
|
2020-11-03 02:02:32 +03:00
|
|
|
// DefaultTracer is the global default tracer
|
2020-10-16 09:38:57 +03:00
|
|
|
DefaultTracer Tracer = NewTracer()
|
2020-09-10 00:06:29 +03:00
|
|
|
)
|
|
|
|
|
2020-01-29 18:45:11 +03:00
|
|
|
// Tracer is an interface for distributed tracing
|
|
|
|
type Tracer interface {
|
2021-03-04 01:12:16 +03:00
|
|
|
// Name return tracer name
|
2021-01-29 13:17:32 +03:00
|
|
|
Name() string
|
2021-03-04 01:12:16 +03:00
|
|
|
// Init tracer with options
|
2021-01-29 13:17:32 +03:00
|
|
|
Init(...Option) error
|
2020-01-18 13:20:46 +03:00
|
|
|
// Start a trace
|
2021-03-04 01:12:16 +03:00
|
|
|
Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Span interface {
|
|
|
|
// Tracer return underlining tracer
|
|
|
|
Tracer() Tracer
|
|
|
|
// Finish complete and send span
|
|
|
|
Finish(opts ...SpanOption)
|
|
|
|
// AddEvent add event to span
|
|
|
|
AddEvent(name string, opts ...EventOption)
|
|
|
|
// Context return context with span
|
|
|
|
Context() context.Context
|
|
|
|
// SetName set the span name
|
|
|
|
SetName(name string)
|
|
|
|
// SetLabels set the span labels
|
|
|
|
SetLabels(labels ...Label)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Label struct {
|
|
|
|
key string
|
|
|
|
val interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Any(k string, v interface{}) Label {
|
|
|
|
return Label{k, v}
|
|
|
|
}
|
|
|
|
|
|
|
|
func String(k string, v string) Label {
|
|
|
|
return Label{k, v}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Int(k string, v int) Label {
|
|
|
|
return Label{k, v}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Int64(k string, v int64) Label {
|
|
|
|
return Label{k, v}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Float64(k string, v float64) Label {
|
|
|
|
return Label{k, v}
|
|
|
|
}
|
2020-02-12 13:57:17 +03:00
|
|
|
|
2021-03-04 01:12:16 +03:00
|
|
|
func Bool(k string, v bool) Label {
|
|
|
|
return Label{k, v}
|
2020-01-18 13:20:46 +03:00
|
|
|
}
|