Back to godoc.org

Package sampling

v0.4.0
Latest Go to latest
Published: Jun 16, 2020 | License: Apache-2.0 | Module: go.opentelemetry.io/collector

Overview

Package sampling contains the interfaces and data types used to implement the various sampling policies.

Index

Package Files

type Decision

type Decision int32

Decision gives the status of sampling decision.

const (
	// Unspecified indicates that the status of the decision was not set yet.
	Unspecified Decision = iota
	// Pending indicates that the policy was not evaluated yet.
	Pending
	// Sampled is used to indicate that the decision was already taken
	// to sample the data.
	Sampled
	// NotSampled is used to indicate that the decision was already taken
	// to not sample the data.
	NotSampled
	// Dropped is used when data needs to be purged before the sampling policy
	// had a chance to evaluate it.
	Dropped
)

type PolicyEvaluator

type PolicyEvaluator interface {
	// OnLateArrivingSpans notifies the evaluator that the given list of spans arrived
	// after the sampling decision was already taken for the trace.
	// This gives the evaluator a chance to log any message/metrics and/or update any
	// related internal state.
	OnLateArrivingSpans(earlyDecision Decision, spans []*tracepb.Span) error

	// Evaluate looks at the trace data and returns a corresponding SamplingDecision.
	Evaluate(traceID []byte, trace *TraceData) (Decision, error)

	// OnDroppedSpans is called when the trace needs to be dropped, due to memory
	// pressure, before the decision_wait time has been reached.
	OnDroppedSpans(traceID []byte, trace *TraceData) (Decision, error)
}

PolicyEvaluator implements a tail-based sampling policy evaluator, which makes a sampling decision for a given trace when requested.

func NewAlwaysSample

func NewAlwaysSample(logger *zap.Logger) PolicyEvaluator

NewAlwaysSample creates a policy evaluator the samples all traces.

func NewNumericAttributeFilter

func NewNumericAttributeFilter(logger *zap.Logger, key string, minValue, maxValue int64) PolicyEvaluator

NewNumericAttributeFilter creates a policy evaluator that samples all traces with the given attribute in the given numeric range.

func NewRateLimiting

func NewRateLimiting(logger *zap.Logger, spansPerSecond int64) PolicyEvaluator

NewRateLimiting creates a policy evaluator the samples all traces.

func NewStringAttributeFilter

func NewStringAttributeFilter(logger *zap.Logger, key string, values []string) PolicyEvaluator

NewStringAttributeFilter creates a policy evaluator that samples all traces with the given attribute in the given numeric range.

type TraceData

type TraceData struct {
	sync.Mutex
	// Decisions gives the current status of the sampling decision for each policy.
	Decisions []Decision
	// Arrival time the first span for the trace was received.
	ArrivalTime time.Time
	// Decisiontime time when sampling decision was taken.
	DecisionTime time.Time
	// SpanCount track the number of spans on the trace.
	SpanCount int64
	// ReceivedBatches stores all the batches received for the trace.
	ReceivedBatches []consumerdata.TraceData
}

TraceData stores the sampling related trace data.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier