2020-11-03 02:02:32 +03:00
|
|
|
// Package tracer provides an interface for distributed tracing
|
2021-10-02 19:55:07 +03:00
|
|
|
package tracer // import "go.unistack.org/micro/v3/tracer"
|
2020-01-18 10:20:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2021-04-27 08:32:47 +03:00
|
|
|
// DefaultTracer is the global default tracer
|
2022-05-03 14:38:44 +03:00
|
|
|
var DefaultTracer = NewTracer()
|
2020-09-10 00:06:29 +03:00
|
|
|
|
2020-01-29 15:45:11 +00: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 10:20:46 +00: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 {
|
|
|
|
val interface{}
|
2021-03-06 19:45:13 +03:00
|
|
|
key string
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2021-10-07 22:46:47 +03:00
|
|
|
func LabelAny(k string, v interface{}) Label {
|
2021-03-06 19:45:13 +03:00
|
|
|
return Label{key: k, val: v}
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2021-10-07 22:46:47 +03:00
|
|
|
func LabelString(k string, v string) Label {
|
2021-03-06 19:45:13 +03:00
|
|
|
return Label{key: k, val: v}
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2021-10-07 22:46:47 +03:00
|
|
|
func LabelInt(k string, v int) Label {
|
2021-03-06 19:45:13 +03:00
|
|
|
return Label{key: k, val: v}
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2021-10-07 22:46:47 +03:00
|
|
|
func LabelInt64(k string, v int64) Label {
|
2021-03-06 19:45:13 +03:00
|
|
|
return Label{key: k, val: v}
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
|
|
|
|
2021-10-07 22:46:47 +03:00
|
|
|
func LabelFloat64(k string, v float64) Label {
|
2021-03-06 19:45:13 +03:00
|
|
|
return Label{key: k, val: v}
|
2021-03-04 01:12:16 +03:00
|
|
|
}
|
2020-02-12 11:57:17 +01:00
|
|
|
|
2021-10-07 22:46:47 +03:00
|
|
|
func LabelBool(k string, v bool) Label {
|
2021-03-06 19:45:13 +03:00
|
|
|
return Label{key: k, val: v}
|
2020-01-18 10:20:46 +00:00
|
|
|
}
|