trace

package
v0.0.0-...-493f229 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

Trace GoDoc

Provides a pluggable distributed tracing interface

type Trace interface {
	Close() error
	// New span with certain fields preset.
	// Provide parent span if you have it.
	NewSpan(*Span) *Span
	// Collect spans
	Collect(*Span) error
	// Name
	String() string
}

type Span struct {
	Name      string        // Topic / RPC Method
	Id        string        // id of this span
	TraceId   string        // The root trace id
	ParentId  string        // Parent span id
	Timestamp time.Time     // Microseconds from epoch. When span started.
	Duration  time.Duration // Microseconds. Duration of the span.
	Debug     bool          // Should persist no matter what.

	Source      *registry.Service // Originating service
	Destination *registry.Service // Destination service

	sync.Mutex
	Annotations []*Annotation
}

type Annotation struct {
	Timestamp time.Time // Microseconds from epoch
	Type      AnnotationType
	Key       string
	Value     []byte
	Debug     map[string]string
	Service   *registry.Service // Annotator
}

func NewTrace(opts ...Option) Trace {
	return newOS(opts...)
}

Supported

Usage

You can either manually use the Trace interface to create and collect spans - look at the wrappers for an example - or use the client and server wrappers which will be called on every request made or received.

Also check out go-os/examples/trace.

import (
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/registry"
	"github.com/pydio/go-os/trace"
)

func main() {
	t := trace.NewTrace()

	srv := &registry.Service{Name: "go.micro.srv.example"}

	service := micro.NewService(
		micro.Name("go.micro.srv.example"),
		micro.WrapClient(trace.ClientWrapper(t, srv)),
		micro.WrapHandler(trace.HandlerWrapper(t, srv)),
	)
}

Documentation

Overview

Package trace is an interface for tracing.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBatchSize     = 100
	DefaultBatchInterval = time.Second * 5

	TraceTopic   = "micro.trace.span"
	TraceHeader  = "X-Micro-Trace-Id"
	SpanHeader   = "X-Micro-Span-Id"
	ParentHeader = "X-Micro-Parent-Id"
	DebugHeader  = "X-Micro-Trace-Debug"
)

Functions

func ClientWrapper

func ClientWrapper(t Trace, s *registry.Service) client.Wrapper

func ContextWithSpan

func ContextWithSpan(ctx context.Context, s *Span) context.Context

func HandlerWrapper

func HandlerWrapper(t Trace, s *registry.Service) server.HandlerWrapper

func HeaderWithSpan

func HeaderWithSpan(md map[string]string, s *Span) map[string]string

func NewContext

func NewContext(ctx context.Context, c Trace) context.Context

Types

type Annotation

type Annotation struct {
	Timestamp time.Time // Microseconds from epoch
	Type      AnnotationType
	Key       string
	Value     []byte
	Debug     map[string]string
	Service   *registry.Service // Annotator
}

type AnnotationType

type AnnotationType int32
const (
	AnnUnknown            AnnotationType = 0
	AnnStart              AnnotationType = 1
	AnnEnd                AnnotationType = 2
	AnnTimeout            AnnotationType = 3
	AnnClientRequest      AnnotationType = 4
	AnnClientResponse     AnnotationType = 5
	AnnClientPublication  AnnotationType = 6
	AnnServerRequest      AnnotationType = 7
	AnnServerResponse     AnnotationType = 8
	AnnServerSubscription AnnotationType = 9
)

type Option

type Option func(o *Options)

func BatchInterval

func BatchInterval(b time.Duration) Option

func BatchSize

func BatchSize(b int) Option

func Client

func Client(c client.Client) Option

func CollectTimeout

func CollectTimeout(t time.Duration) Option

func Collectors

func Collectors(c ...string) Option

func Service

func Service(s *registry.Service) Option

func Topic

func Topic(t string) Option

type Options

type Options struct {
	BatchSize      int
	BatchInterval  time.Duration
	CollectTimeout time.Duration
	Collectors     []string
	Topic          string

	Client  client.Client
	Service *registry.Service
}

type Span

type Span struct {
	Name      string        // Topic / RPC Method
	Id        string        // id of this span
	TraceId   string        // The root trace id
	ParentId  string        // Parent span id
	Timestamp time.Time     // Microseconds from epoch. When span started.
	Duration  time.Duration // Microseconds. Duration of the span.
	Debug     bool          // Should persist no matter what.

	Source      *registry.Service // Originating service
	Destination *registry.Service // Destination service

	sync.Mutex
	Annotations []*Annotation
}

func SpanFromContext

func SpanFromContext(ctx context.Context) (*Span, bool)

func SpanFromHeader

func SpanFromHeader(md map[string]string) (*Span, bool)

type Trace

type Trace interface {
	Close() error
	// New span with certain fields preset.
	// Provide parent span if you have it.
	NewSpan(*Span) *Span
	// Collect spans
	Collect(*Span) error
	// Name
	String() string
}

func FromContext

func FromContext(ctx context.Context) (Trace, bool)

func NewTrace

func NewTrace(opts ...Option) Trace

Directories

Path Synopsis
Package go_micro_os_trace is a generated protocol buffer package.
Package go_micro_os_trace is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL