sampler

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAlwaysSampleSampler

func NewAlwaysSampleSampler() trace.SpanSampler

NewAlwaysSampleSampler 主要用于创建一个总是采样器(无锁实现) @return Sampler 采样器

func NewDistributedSampler

func NewDistributedSampler(sampleRate float64, opts ...DistributedSamplerOption) trace.SpanSampler

NewDistributedSampler 创建分布式采样器

func NewNeverSampleSampler

func NewNeverSampleSampler() trace.SpanSampler

NewNeverSampleSampler 主要用于创建一个从不采样器(无锁实现) @return Sampler 采样器

func NewProbabilitySampler

func NewProbabilitySampler(probability float64) trace.SpanSampler

NewProbabilitySampler 创建一个概率采样器

func NewRateLimitingSampler

func NewRateLimitingSampler(maxTracesPerSecond float64) trace.SpanSampler

NewRateLimitingSampler 主要用于创建一个速率限制采样器 @param maxTracesPerSecond 每秒最大追踪数 @return Sampler 采样器

Types

type AlwaysSampler

type AlwaysSampler struct{}

AlwaysSampler 是一个总是采样的Span采样器实现(无锁,高并发优化)

func (*AlwaysSampler) ShouldSample

func (s *AlwaysSampler) ShouldSample(params types.SamplingParameters) types.SamplingResult

ShouldSample 实现sampler.Sampler接口,总是返回采样

type DistributedSampler

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

DistributedSampler 分布式采样器 基于TraceID的一致性哈希进行采样,确保同一Trace的所有Spans采样决策一致 采样决策直接由 TraceID 计算,不保存无界缓存,避免长期运行后内存持续增长。

func (*DistributedSampler) ClearCache

func (s *DistributedSampler) ClearCache()

ClearCache 保留兼容入口;当前实现不再维护采样缓存。

func (*DistributedSampler) Description

func (s *DistributedSampler) Description() string

Description 返回采样器描述

func (*DistributedSampler) GetStats

func (s *DistributedSampler) GetStats() map[string]int64

GetStats 获取统计信息

func (*DistributedSampler) ShouldSample

ShouldSample 判断是否应该采样 基于TraceID的一致性哈希,确保同一Trace的所有Spans采样决策一致

type DistributedSamplerOption

type DistributedSamplerOption func(*DistributedSampler)

DistributedSamplerOption 分布式采样器选项

func WithDistributedSampleRate

func WithDistributedSampleRate(rate float64) DistributedSamplerOption

WithDistributedSampleRate 设置采样率

type NeverSampler

type NeverSampler struct {
}

NeverSampler 是一个从不采样的Span采样器实现

func NewNeverSampler

func NewNeverSampler() *NeverSampler

NewNeverSampler 创建一个新的NeverSampler

func (*NeverSampler) ShouldSample

func (s *NeverSampler) ShouldSample(params types.SamplingParameters) types.SamplingResult

ShouldSample 实现trace.SpanSampler接口 主要用于从不采样 @param params types.SamplingParameters 采样参数 @return types.SamplingResult 采样结果

type ProbabilitySampler

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

ProbabilitySampler 是一个概率采样的Span采样器实现 使用 math/rand/v2 的全局函数(线程安全),无需 Mutex

func (*ProbabilitySampler) ShouldSample

ShouldSample 实现sampler.Sampler接口 主要用于根据采样参数返回采样结果 使用 math/rand/v2 的全局函数 rand.Float64()(线程安全),无需 Mutex @param params 采样参数 @return SamplingResult 采样结果

type RateLimitingSampler

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

RateLimitingSampler 是一个限制采样的Span采样器实现

func (*RateLimitingSampler) ShouldSample

ShouldSample 实现trace.SpanSampler接口 主要用于根据速率限制采样器返回采样结果 @param params 采样参数 @return types.SamplingResult 采样结果

Jump to

Keyboard shortcuts

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