1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-12-01 23:12:29 +02:00

sdk/trace: Test the Sampling Probability (#247)

* sdk/trace: Test the Sampling Probability

Closes #163

* Add tests for when the parent is sampled.
This commit is contained in:
Edward Muller (SFDC)
2019-10-29 16:53:50 -07:00
committed by rghetia
parent 937f4ff8b0
commit f420f7409d
4 changed files with 77 additions and 7 deletions

View File

@@ -39,16 +39,18 @@ type SamplingDecision struct {
Sample bool
}
// ProbabilitySampler returns a Sampler that samples a given fraction of traces.
//
// It also samples spans whose parents are sampled.
// ProbabilitySampler samples a given fraction of traces. Fractions >= 1 will
// always sample. If the parent span is sampled, then it's child spans will
// automatically be sampled. Fractions <0 are treated as zero, but spans may
// still be sampled if their parent is.
func ProbabilitySampler(fraction float64) Sampler {
if !(fraction >= 0) {
fraction = 0
} else if fraction >= 1 {
if fraction >= 1 {
return AlwaysSample()
}
if fraction <= 0 {
fraction = 0
}
traceIDUpperBound := uint64(fraction * (1 << 63))
return Sampler(func(p SamplingParameters) SamplingDecision {
if p.ParentContext.IsSampled() {