trace

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 4 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Finish added in v1.1.0

func Finish(span *Span) error

func FromContext

func FromContext(ctx context.Context) (string, string, 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

ReadTrace Reads 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

func Read added in v1.1.0

func Read(opts ...ReadOption) ([]*Span, error)

func Start added in v1.1.0

func Start(ctx context.Context, name string) (context.Context, *Span)

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)

	Flag = pflag.NewFlagSet("trace", pflag.ExitOnError)
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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