github.com/blend/go-sdk@v1.20220411.3/datadog/rate_sampler.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package datadog 9 10 import ( 11 "math/rand" 12 13 "gopkg.in/DataDog/dd-trace-go.v1/ddtrace" 14 ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" 15 ) 16 17 var ( 18 _ ddtracer.RateSampler = (*RateSampler)(nil) 19 ) 20 21 // RateSampler samples from a sample rate. 22 type RateSampler float64 23 24 // SetRate is a no-op 25 func (r RateSampler) SetRate(newRate float64) {} 26 27 // Rate returns the rate. 28 func (r RateSampler) Rate() float64 { 29 return float64(r) 30 } 31 32 // Sample returns true if the given span should be sampled. 33 func (r RateSampler) Sample(spn ddtrace.Span) bool { 34 if r < 1 { 35 return rand.Float64() < float64(r) 36 } 37 38 return true 39 }