Refactor debug/trace ready for Jaeger

This commit is contained in:
Micro
2020-01-29 15:45:11 +00:00
parent 1108cc5e91
commit 62c067adcd
10 changed files with 130 additions and 36 deletions

View File

@@ -6,8 +6,8 @@ import (
"time"
)
// Trace is an interface for distributed tracing
type Trace interface {
// Tracer is an interface for distributed tracing
type Tracer interface {
// Start a trace
Start(ctx context.Context, name string) (context.Context, *Span)
// Finish the trace
@@ -36,11 +36,6 @@ type Span struct {
type spanKey struct{}
var (
// Default tracer
DefaultTrace = NewTrace()
)
// FromContext returns a span from context
func FromContext(ctx context.Context) (*Span, bool) {
s, ok := ctx.Value(spanKey{}).(*Span)
@@ -51,3 +46,25 @@ func FromContext(ctx context.Context) (*Span, bool) {
func NewContext(ctx context.Context, s *Span) context.Context {
return context.WithValue(ctx, spanKey{}, s)
}
var (
DefaultTracer Tracer = new(noop)
)
type noop struct{}
func (n *noop) Init(...Option) error {
return nil
}
func (n *noop) Start(ctx context.Context, name string) (context.Context, *Span) {
return nil, nil
}
func (n *noop) Finish(*Span) error {
return nil
}
func (n *noop) Read(...ReadOption) ([]*Span, error) {
return nil, nil
}