sampling

package
v0.0.0-...-8ff3c68 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

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

Copyright The OpenTelemetry Authors SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type And

type And struct {
	// contains filtered or unexported fields
}

func (*And) Evaluate

func (c *And) Evaluate(ctx context.Context, traceID pcommon.TraceID, trace *TraceData) (Decision, error)

Evaluate looks at the trace data and returns a corresponding SamplingDecision.

func (*And) OnDroppedSpans

func (c *And) OnDroppedSpans(pcommon.TraceID, *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.

type Composite

type Composite struct {
	// contains filtered or unexported fields
}

Composite evaluator and its internal data

func (*Composite) Evaluate

func (c *Composite) Evaluate(ctx context.Context, traceID pcommon.TraceID, trace *TraceData) (Decision, error)

Evaluate looks at the trace data and returns a corresponding SamplingDecision.

func (*Composite) OnDroppedSpans

func (c *Composite) OnDroppedSpans(pcommon.TraceID, *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.

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
	// Error is used to indicate that policy evaluation was not succeeded.
	Error
	// InvertSampled is used on the invert match flow and indicates to sample
	// the data.
	InvertSampled
	// InvertNotSampled is used on the invert match flow and indicates to not
	// sample the data.
	InvertNotSampled
)

type MonotonicClock

type MonotonicClock struct{}

MonotonicClock provides monotonic real clock-based current Unix second. Use it when creating a NewComposite which should measure sample rates against a realtime clock (this is almost always what you want to do, the exception is usually only automated testing where you may want to have fake clocks).

type PolicyEvaluator

type PolicyEvaluator interface {
	// Evaluate looks at the trace data and returns a corresponding SamplingDecision.
	Evaluate(ctx context.Context, traceID pcommon.TraceID, 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(settings component.TelemetrySettings) PolicyEvaluator

NewAlwaysSample creates a policy evaluator the samples all traces.

func NewAnd

func NewAnd(
	logger *zap.Logger,
	subpolicies []PolicyEvaluator,
) PolicyEvaluator

func NewBooleanAttributeFilter

func NewBooleanAttributeFilter(settings component.TelemetrySettings, key string, value bool) PolicyEvaluator

NewBooleanAttributeFilter creates a policy evaluator that samples all traces with the given attribute that match the supplied boolean value.

func NewComposite

func NewComposite(
	logger *zap.Logger,
	maxTotalSpansPerSecond int64,
	subPolicyParams []SubPolicyEvalParams,
	timeProvider TimeProvider,
) PolicyEvaluator

NewComposite creates a policy evaluator that samples all subpolicies.

func NewNumericAttributeFilter

func NewNumericAttributeFilter(settings component.TelemetrySettings, 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 NewOTTLConditionFilter

func NewOTTLConditionFilter(settings component.TelemetrySettings, spanConditions, spanEventConditions []string, errMode ottl.ErrorMode) (PolicyEvaluator, error)

NewOTTLConditionFilter looks at the trace data and returns a corresponding SamplingDecision.

func NewProbabilisticSampler

func NewProbabilisticSampler(settings component.TelemetrySettings, hashSalt string, samplingPercentage float64) PolicyEvaluator

NewProbabilisticSampler creates a policy evaluator that samples a percentage of traces.

func NewRateLimiting

func NewRateLimiting(settings component.TelemetrySettings, spansPerSecond int64) PolicyEvaluator

NewRateLimiting creates a policy evaluator the samples all traces.

func NewStatusCodeFilter

func NewStatusCodeFilter(settings component.TelemetrySettings, statusCodeString []string) (PolicyEvaluator, error)

NewStatusCodeFilter creates a policy evaluator that samples all traces with a given status code.

func NewStringAttributeFilter

func NewStringAttributeFilter(settings component.TelemetrySettings, key string, values []string, regexMatchEnabled bool, evictSize int, invertMatch bool) PolicyEvaluator

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

func NewTraceStateFilter

func NewTraceStateFilter(settings component.TelemetrySettings, key string, values []string) PolicyEvaluator

NewTraceStateFilter creates a policy evaluator that samples all traces with the given value by the specific key in the trace_state.

func NewTransparencyAttributeFilter

func NewTransparencyAttributeFilter(settings component.TelemetrySettings) PolicyEvaluator

type SubPolicyEvalParams

type SubPolicyEvalParams struct {
	Evaluator         PolicyEvaluator
	MaxSpansPerSecond int64
}

SubPolicyEvalParams defines the evaluator and max rate for a sub-policy

type TimeProvider

type TimeProvider interface {
	// contains filtered or unexported methods
}

TimeProvider allows to get current Unix second

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 *atomic.Int64
	// ReceivedBatches stores all the batches received for the trace.
	ReceivedBatches ptrace.Traces
	// FinalDecision.
	FinalDecision Decision
}

TraceData stores the sampling related trace data.

Jump to

Keyboard shortcuts

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