Documentation ¶
Overview ¶
Package sampling contains the interfaces and data types used to implement the various sampling policies.
Copyright The OpenTelemetry Authors ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- type Composite
- type Decision
- type MonotonicClock
- type PolicyEvaluator
- func NewAlwaysSample(logger *zap.Logger) PolicyEvaluator
- func NewComposite(logger *zap.Logger, maxTotalSpansPerSecond int64, ...) PolicyEvaluator
- func NewLatency(logger *zap.Logger, thresholdMs int64) PolicyEvaluator
- func NewNumericAttributeFilter(logger *zap.Logger, key string, minValue, maxValue int64) PolicyEvaluator
- func NewProbabilisticSampler(logger *zap.Logger, hashSalt string, samplingPercentage float64) PolicyEvaluator
- func NewRateLimiting(logger *zap.Logger, spansPerSecond int64) PolicyEvaluator
- func NewStatusCodeFilter(logger *zap.Logger, statusCodeString []string) (PolicyEvaluator, error)
- func NewStringAttributeFilter(logger *zap.Logger, key string, values []string, regexMatchEnabled bool, ...) PolicyEvaluator
- type SubPolicyEvalParams
- type TimeProvider
- type TraceData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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.
func (*Composite) OnDroppedSpans ¶ added in v0.38.0
OnDroppedSpans is called when the trace needs to be dropped, due to memory pressure, before the decision_wait time has been reached.
func (*Composite) OnLateArrivingSpans ¶ added in v0.38.0
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.
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 ¶ 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 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 []*pdata.Span) error // Evaluate looks at the trace data and returns a corresponding SamplingDecision. Evaluate(traceID pdata.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(logger *zap.Logger) PolicyEvaluator
NewAlwaysSample creates a policy evaluator the samples all traces.
func NewComposite ¶ added in v0.38.0
func NewComposite( logger *zap.Logger, maxTotalSpansPerSecond int64, subPolicyParams []SubPolicyEvalParams, timeProvider TimeProvider, ) PolicyEvaluator
NewComposite creates a policy evaluator that samples all subpolicies.
func NewLatency ¶
func NewLatency(logger *zap.Logger, thresholdMs int64) PolicyEvaluator
NewLatency creates a policy evaluator sampling traces with a duration higher than a configured threshold
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 NewProbabilisticSampler ¶ added in v0.34.0
func NewProbabilisticSampler(logger *zap.Logger, hashSalt string, samplingPercentage float64) PolicyEvaluator
NewProbabilisticSampler creates a policy evaluator that samples a percentage of traces.
func NewRateLimiting ¶
func NewRateLimiting(logger *zap.Logger, spansPerSecond int64) PolicyEvaluator
NewRateLimiting creates a policy evaluator the samples all traces.
func NewStatusCodeFilter ¶
func NewStatusCodeFilter(logger *zap.Logger, statusCodeString []string) (PolicyEvaluator, error)
NewStatusCodeFilter creates a policy evaluator that samples all traces with a given status code.
func NewStringAttributeFilter ¶
func NewStringAttributeFilter(logger *zap.Logger, 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.
type SubPolicyEvalParams ¶ added in v0.38.0
type SubPolicyEvalParams struct { Evaluator PolicyEvaluator MaxSpansPerSecond int64 }
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
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 []pdata.Traces }
TraceData stores the sampling related trace data.