trace

package
v2.9.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package trace provides an interface for distributed tracing

Index

Constants

View Source
const (
	// DefaultSize of the buffer
	DefaultSize = 64
)

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) (traceID string, parentSpanID string, isFound bool)

FromContext returns a span from context

func ToContext

func ToContext(ctx context.Context, traceID, parentSpanID string) context.Context

ToContext saves the trace and span ids in the context

Types

type Option

type Option func(o *Options)

type Options

type Options struct {
	// Size is the size of ring buffer
	Size int
}

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default options

type ReadOption

type ReadOption func(o *ReadOptions)

func ReadTrace

func ReadTrace(t string) ReadOption

Read the given trace

type ReadOptions

type ReadOptions struct {
	// Trace id
	Trace string
}

type Span

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
	// Duration in nano seconds
	Duration time.Duration
	// associated data
	Metadata map[string]string
	// Type
	Type SpanType
}

Span is used to record an entry

type SpanType

type SpanType int

SpanType describe the nature of the trace span

const (
	// SpanTypeRequestInbound is a span created when serving a request
	SpanTypeRequestInbound SpanType = iota
	// SpanTypeRequestOutbound is a span created when making a service call
	SpanTypeRequestOutbound
)

type Tracer

type Tracer interface {
	// Start a trace
	Start(ctx context.Context, name string) (context.Context, *Span)
	// Finish the trace
	Finish(*Span) error
	// Read the traces
	Read(...ReadOption) ([]*Span, error)
}

Tracer is an interface for distributed tracing

var (
	DefaultTracer Tracer = new(noop)
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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