micro/tracer/trace.go

52 lines
1.0 KiB
Go
Raw Normal View History

2020-01-18 10:20:46 +00:00
// Package trace provides an interface for distributed tracing
package tracer
2020-01-18 10:20:46 +00:00
import (
"context"
"time"
)
var (
DefaultTracer Tracer = NewTracer()
)
2020-01-29 15:45:11 +00:00
// Tracer is an interface for distributed tracing
type Tracer interface {
2020-01-18 10:20:46 +00:00
// Start a trace
2020-01-24 21:44:48 +00:00
Start(ctx context.Context, name string) (context.Context, *Span)
2020-01-18 10:20:46 +00:00
// Finish the trace
Finish(*Span) error
// Read the traces
Read(...ReadOption) ([]*Span, error)
}
// 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 10:20:46 +00: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-24 21:24:51 +00:00
// Duration in nano seconds
Duration time.Duration
2020-01-18 10:20:46 +00:00
// associated data
Metadata map[string]string
// Type
Type SpanType
2020-01-18 10:20:46 +00:00
}