// WithSampler allows one to set a Sampler function
177738
func WithSampler(sampler Sampler) TracerOption {
	return func(o *Tracer) error {
		o.sampler = sampler
		return nil
	}
}
1252575
func (c *StatsdClient) TimingWithSampling(stat string, delta int64, sampleRate float32) error {
	if err := checkSampleRate(sampleRate); err != nil {
		return err
	}

	if !shouldFire(sampleRate) {
		return nil // ignore this call
	}

	return c.send(stat, "%d|ms", delta, sampleRate)
}
1325483
func (t *TotalThroughput) GetSampleRate(key string) int {
	t.lock.Lock()
	defer t.lock.Unlock()
	t.currentCounts[key]++
	if rate, found := t.savedSampleRates[key]; found {
		return rate
	}
	return 1
}
1285430
func (s *RemotelyControlledSampler) updateRateLimitingOrProbabilisticSampler(res *sampling.SamplingStrategyResponse) error {
	var newSampler Sampler
	if probabilistic := res.GetProbabilisticSampling(); probabilistic != nil {
		newSampler = newProbabilisticSampler(probabilistic.SamplingRate)
	} else if rateLimiting := res.GetRateLimitingSampling(); rateLimiting != nil {
		newSampler = NewRateLimitingSampler(float64(rateLimiting.MaxTracesPerSecond))
	} else {
		return fmt.Errorf("Unsupported sampling strategy type %v", res.GetStrategyType())
	}
	if !s.sampler.Equal(newSampler) {
		s.sampler = newSampler
	}
	return nil
}
854475
func (samplerOptions) SamplingServerURL(samplingServerURL string) SamplerOption {
	return func(o *samplerOptions) {
		o.samplingServerURL = samplingServerURL
	}
}
1202891
func MaxSamplingRate(r int) TracerOption {
	if r <= 0 {
		panic("max sampling rate must be greater than 0")
	}
	return func(o *tracerOptions) *tracerOptions {
		o.maxSamplingRate = r
		return o
	}
}
716194
func (m *Matrix) WithEpsilon(epsilon float64) *Matrix {
	m.epsilon = epsilon
	return m
}
105112
func NewSamplingEventLogger(l EventLogger) *SamplingEventLogger {
	return &SamplingEventLogger{
		l:         l,
		r:         rand.New(rand.NewSource(time.Now().UnixNano())),
		rates:     make(map[string]float64),
		rootRates: make(map[ID]float64),
		m:         new(sync.Mutex),
	}
}
388746
func (e *RecordEncoder) Samples(samples []RefSample, b []byte) []byte {
	buf := encoding.Encbuf{B: b}
	buf.PutByte(byte(RecordSamples))

	if len(samples) == 0 {
		return buf.Get()
	}

	// Store base timestamp and base reference number of first sample.
	// All samples encode their timestamp and ref as delta to those.
	first := samples[0]

	buf.PutBE64(first.Ref)
	buf.PutBE64int64(first.T)

	for _, s := range samples {
		buf.PutVarint64(int64(s.Ref) - int64(first.Ref))
		buf.PutVarint64(s.T - first.T)
		buf.PutBE64(math.Float64bits(s.V))
	}
	return buf.Get()
}
288616
func (s *Server) WithDecisionLoggerWithErr(logger func(context.Context, *Info) error) *Server {
	s.logger = logger
	return s
}
993258
func (s *Eac3Settings) SetSampleRate(v int64) *Eac3Settings {
	s.SampleRate = &v
	return s
}
1227078
func (c *StatsdClient) GaugeWithSampling(stat string, value int64, sampleRate float32) error {
	if err := checkSampleRate(sampleRate); err != nil {
		return err
	}

	if !shouldFire(sampleRate) {
		return nil // ignore this call
	}

	if value < 0 {
		err := c.send(stat, "%d|g", 0, 1)
		if nil != err {
			return err
		}
	}

	return c.send(stat, "%d|g", value, sampleRate)
}
1070971
func NewGuaranteedThroughputProbabilisticSampler(
	lowerBound, samplingRate float64,
) (*GuaranteedThroughputProbabilisticSampler, error) {
	return newGuaranteedThroughputProbabilisticSampler(lowerBound, samplingRate), nil
}
1064366
func GetSampledEntries(ctx context.Context, conf Config, sampleRate uint) ([]chan string, error) {
	unsampledLinesChans, err := GetEntries(ctx, conf)
	if err != nil {
		return nil, err
	}
	if sampleRate == 1 {
		return unsampledLinesChans, nil
	}

	sampledLinesChans := make([]chan string, 0, len(unsampledLinesChans))

	for _, lines := range unsampledLinesChans {
		sampledLines := make(chan string)
		go func(pLines chan string) {
			defer close(sampledLines)
			for line := range pLines {
				if shouldDrop(sampleRate) {
					logrus.WithFields(logrus.Fields{
						"line":       line,
						"samplerate": sampleRate,
					}).Debug("Sampler says skip this line")
				} else {
					sampledLines <- line
				}
			}
		}(lines)
		sampledLinesChans = append(sampledLinesChans, sampledLines)
	}
	return sampledLinesChans, nil
}
621025
func (s *SkillsStoreSkill) SetSampleUtterances(v []*string) *SkillsStoreSkill {
	s.SampleUtterances = v
	return s
}
1037780
func NewCountingSampler(rate float64) Sampler {
	if rate <= 0 {
		return neverSample
	}
	if rate >= 1.0 {
		return alwaysSample
	}
	var (
		i         = 0
		outOf100  = int(rate*100 + math.Copysign(0.5, rate*100)) // for rounding float to int conversion instead of truncation
		decisions = randomBitSet(100, outOf100, rand.New(rand.NewSource(time.Now().UnixNano())))
		mtx       = &sync.Mutex{}
	)

	return func(_ uint64) bool {
		mtx.Lock()
		defer mtx.Unlock()
		result := decisions[i]
		i++
		if i == 100 {
			i = 0
		}
		return result
	}
}
569981
func WithNoPager(ctx context.Context, bv bool) context.Context {
	return context.WithValue(ctx, ctxKeyNoPager, bv)
}