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"
|
|
|
|
"time"
|
2020-11-18 16:50:41 +03:00
|
|
|
|
|
|
|
"github.com/unistack-org/micro/v3/metadata"
|
2020-01-18 13:20:46 +03:00
|
|
|
)
|
|
|
|
|
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-01-29 13:17:32 +03:00
|
|
|
Name() string
|
|
|
|
Init(...Option) error
|
2020-01-18 13:20:46 +03:00
|
|
|
// Start a trace
|
2020-01-25 00:44:48 +03:00
|
|
|
Start(ctx context.Context, name string) (context.Context, *Span)
|
2020-01-18 13:20:46 +03:00
|
|
|
// Finish the trace
|
|
|
|
Finish(*Span) error
|
2021-01-29 13:17:32 +03:00
|
|
|
// Lookup get span from context
|
|
|
|
Lookup(ctx context.Context) (*Span, error)
|
2020-01-18 13:20:46 +03:00
|
|
|
// Read the traces
|
|
|
|
Read(...ReadOption) ([]*Span, error)
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:57:17 +03:00
|
|
|
// SpanType describe the nature of the trace span
|
|
|
|
type SpanType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// SpanTypeRequestInbound is a span created when serving a request
|
|
|
|
SpanTypeRequestInbound SpanType = iota
|
|
|
|
// SpanTypeRequestOutbound is a span created when making a service call
|
|
|
|
SpanTypeRequestOutbound
|
|
|
|
)
|
|
|
|
|
2020-01-18 13:20:46 +03:00
|
|
|
// Span is used to record an entry
|
|
|
|
type Span struct {
|
|
|
|
// Id of the trace
|
|
|
|
Trace string
|
|
|
|
// name of the span
|
|
|
|
Name string
|
|
|
|
// id of the span
|
|
|
|
Id string
|
|
|
|
// parent span id
|
|
|
|
Parent string
|
|
|
|
// Start time
|
|
|
|
Started time.Time
|
2020-01-25 00:24:51 +03:00
|
|
|
// Duration in nano seconds
|
|
|
|
Duration time.Duration
|
2020-01-18 13:20:46 +03:00
|
|
|
// associated data
|
2020-11-18 16:50:41 +03:00
|
|
|
Metadata metadata.Metadata
|
2020-02-12 13:57:17 +03:00
|
|
|
// Type
|
|
|
|
Type SpanType
|
2020-01-18 13:20:46 +03:00
|
|
|
}
|