trace

package
v1.1.0-1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package trace provides functions and constants for tracing.

Index

Constants

View Source
const (
	Sampling        = "Sampling"
	Debug           = "Debug"
	DebugWithFilter = "DebugWithFilter"
)

Variables

View Source
var DefaultSchedulerTracerImplParams = &SchedulerTracerImplParams{
	Mode:       Sampling,
	FilterTags: nil,
}

Functions

func NewConstTracer

func NewConstTracer(serviceName string, collect bool) (opentracing.Tracer, io.Closer, error)

NewConstTracer returns an instance of Jaeger Tracer that samples 100% or 0% of traces for test.

func NewTracerFromEnv

func NewTracerFromEnv(serviceName string) (opentracing.Tracer, io.Closer, error)

NewTracerFromEnv returns an instance of Jaeger Tracer that get sampling strategy from env settings.

Types

type DelaySchedulerTraceContextImpl

type DelaySchedulerTraceContextImpl struct {
	Tracer     opentracing.Tracer
	Spans      []*DelaySpan
	StackLen   int
	FilterTags map[string]interface{}
}

DelaySchedulerTraceContextImpl delays reporting spans and chooses whether to report based on FilterTags when the entire trace is collected.

func (*DelaySchedulerTraceContextImpl) ActiveSpan

func (d *DelaySchedulerTraceContextImpl) ActiveSpan() (opentracing.Span, error)

func (*DelaySchedulerTraceContextImpl) FinishActiveSpan

func (d *DelaySchedulerTraceContextImpl) FinishActiveSpan() error

FinishActiveSpan finishes current active span by setting its FinishTime and pop it from the unfinished span stack.

func (*DelaySchedulerTraceContextImpl) StartSpan

func (d *DelaySchedulerTraceContextImpl) StartSpan(operationName string) (opentracing.Span, error)

type DelaySpan

type DelaySpan struct {
	opentracing.Span
	FinishTime time.Time
}

DelaySpan implements the opentracing.Span interface. It will set the FinishTime field and delay reporting when finished.

func (*DelaySpan) Finish

func (d *DelaySpan) Finish()

Finish implements the opentracing.Span interface and panics when calling.

func (*DelaySpan) FinishWithOptions

func (d *DelaySpan) FinishWithOptions(opentracing.FinishOptions)

FinishWithOptions implements the opentracing.Span interface and panics when calling.

type SchedulerTraceContext

type SchedulerTraceContext interface {
	// ActiveSpan returns current active (latest unfinished) span in this context object.
	// Error returns if there doesn't exist an unfinished span.
	ActiveSpan() (opentracing.Span, error)

	// StartSpan creates and starts a new span based on the context state with the operationName parameter.
	// The new span is the child of current active span if it exists.
	// Or the new span will become the root span of this trace.
	StartSpan(operationName string) (opentracing.Span, error)

	// FinishActiveSpan finishes current active span and set its parent as active if exists.
	// Error returns if there doesn't exist an unfinished span.
	FinishActiveSpan() error
}

SchedulerTraceContext manages spans for one trace. It only designs for the scheduling process so we keeps the interface simple. We have to call StartSpan and FinishActiveSpan in pairs, like this:

span, _ := ctx.StartSpan("op")
defer ctx.FinishActiveSpan()
...
span.SetTag("foo", "bar")
...

We should not call span.Finish or span.FinishWithOptions because they won't change the structure in the trace context. We should be careful if functions that might cause panic are involved in the procedure when tracing, which is similar to resource opening and closing.

type SchedulerTraceContextImpl

type SchedulerTraceContextImpl struct {
	Tracer       opentracing.Tracer
	SpanStack    []opentracing.Span
	OnDemandFlag bool
}

SchedulerTraceContextImpl reports the spans to tracer once they are finished. Root span's "sampling.priority" tag will be set to 1 to force reporting all spans if OnDemandFlag is true.

func (*SchedulerTraceContextImpl) ActiveSpan

func (s *SchedulerTraceContextImpl) ActiveSpan() (opentracing.Span, error)

func (*SchedulerTraceContextImpl) FinishActiveSpan

func (s *SchedulerTraceContextImpl) FinishActiveSpan() error

func (*SchedulerTraceContextImpl) StartSpan

func (s *SchedulerTraceContextImpl) StartSpan(operationName string) (opentracing.Span, error)

type SchedulerTracer

type SchedulerTracer interface {
	NewTraceContext() SchedulerTraceContext
	Close()
}

SchedulerTracer defines minimum interface for tracing

func NewSchedulerTracer

func NewSchedulerTracer(params *SchedulerTracerImplParams) (SchedulerTracer, error)

NewSchedulerTracer creates new tracer instance with params params is set to default sampling mode if it is nil

type SchedulerTracerImpl

type SchedulerTracerImpl struct {
	Tracer opentracing.Tracer
	Closer io.Closer
	sync.RWMutex
	*SchedulerTracerImplParams
}

func (*SchedulerTracerImpl) Close

func (s *SchedulerTracerImpl) Close()

Close calls tracer's closer if exists

func (*SchedulerTracerImpl) NewTraceContext

func (s *SchedulerTracerImpl) NewTraceContext() SchedulerTraceContext

NewTraceContext create SchedulerTraceContext based on parameter settings

func (*SchedulerTracerImpl) SetParams

func (s *SchedulerTracerImpl) SetParams(params *SchedulerTracerImplParams)

SetParams set runtime parameter for tracer

type SchedulerTracerImplParams

type SchedulerTracerImplParams struct {
	Mode       string
	FilterTags map[string]interface{}
}

Jump to

Keyboard shortcuts

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