sampling

package
v0.142.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 22 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

func IsInvertDecisionsDisabled added in v0.126.0

func IsInvertDecisionsDisabled() bool

func NewAlwaysSample

func NewAlwaysSample(settings component.TelemetrySettings) samplingpolicy.Evaluator

NewAlwaysSample creates a policy evaluator the samples all traces.

func NewAnd added in v0.44.0

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

func NewBooleanAttributeFilter added in v0.73.0

func NewBooleanAttributeFilter(settings component.TelemetrySettings, key string, value, invertMatch bool) samplingpolicy.Evaluator

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

func NewBytesLimiting added in v0.141.0

func NewBytesLimiting(settings component.TelemetrySettings, bytesPerSecond int64) samplingpolicy.Evaluator

NewBytesLimiting creates a policy evaluator that samples traces based on byte limit per second using a token bucket algorithm. The bucket capacity defaults to 2x the bytes per second to allow for reasonable burst traffic.

func NewBytesLimitingWithBurstCapacity added in v0.141.0

func NewBytesLimitingWithBurstCapacity(_ component.TelemetrySettings, bytesPerSecond, burstCapacity int64) samplingpolicy.Evaluator

NewBytesLimitingWithBurstCapacity creates a policy evaluator with custom burst capacity. Uses golang.org/x/time/rate.Limiter for efficient, thread-safe token bucket implementation.

func NewComposite added in v0.38.0

func NewComposite(
	logger *zap.Logger,
	maxTotalSpansPerSecond int64,
	subPolicyParams []SubPolicyEvalParams,
	timeProvider TimeProvider,
	recordSubPolicy bool,
) samplingpolicy.Evaluator

NewComposite creates a policy evaluator that samples all subpolicies.

func NewDrop added in v0.126.0

func NewDrop(
	logger *zap.Logger,
	subpolicies []samplingpolicy.Evaluator,
) samplingpolicy.Evaluator

func NewLatency

func NewLatency(settings component.TelemetrySettings, thresholdMs, upperThresholdMs int64) samplingpolicy.Evaluator

NewLatency creates a policy evaluator sampling traces with a duration greater than a configured threshold

func NewNumericAttributeFilter

func NewNumericAttributeFilter(settings component.TelemetrySettings, key string, minValue, maxValue *int64, invertMatch bool) samplingpolicy.Evaluator

NewNumericAttributeFilter creates a policy evaluator that samples all traces with the given attribute in the given numeric range. If minValue is nil, it will use math.MinInt64. If maxValue is nil, it will use math.MaxInt64. At least one of minValue or maxValue must be set.

func NewOTTLConditionFilter added in v0.78.0

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

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

func NewProbabilisticSampler added in v0.34.0

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

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

func NewRateLimiting

func NewRateLimiting(settings component.TelemetrySettings, spansPerSecond int64) samplingpolicy.Evaluator

NewRateLimiting creates a policy evaluator the samples all traces.

func NewSpanCount added in v0.54.0

func NewSpanCount(settings component.TelemetrySettings, minSpans, maxSpans int32) samplingpolicy.Evaluator

NewSpanCount creates a policy evaluator sampling traces with more than one span per trace

func NewStatusCodeFilter

func NewStatusCodeFilter(settings component.TelemetrySettings, statusCodeString []string) (samplingpolicy.Evaluator, 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) (samplingpolicy.Evaluator, error)

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

func NewTraceStateFilter added in v0.54.0

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

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

func SetAttrOnScopeSpans added in v0.120.0

func SetAttrOnScopeSpans(data *samplingpolicy.TraceData, attrName, attrKey string)

func SetBoolAttrOnScopeSpans added in v0.136.0

func SetBoolAttrOnScopeSpans(data ptrace.Traces, attrName string, attrValue bool)

Types

type And added in v0.44.0

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

func (*And) Evaluate added in v0.44.0

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

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

type Composite added in v0.38.0

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

Composite evaluator and its internal data

func (*Composite) Evaluate added in v0.38.0

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

type Drop added in v0.126.0

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

func (*Drop) Evaluate added in v0.126.0

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

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

type MonotonicClock added in v0.38.0

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 SubPolicyEvalParams added in v0.38.0

type SubPolicyEvalParams struct {
	Evaluator         samplingpolicy.Evaluator
	MaxSpansPerSecond int64
	Name              string
}

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

type TimeProvider added in v0.38.0

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

TimeProvider allows to get current Unix second

Jump to

Keyboard shortcuts

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