You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Change name of ProbabilitySampler to TraceIdRatioBased (#1115)
* Change name of ProbabilitySampler to TraceIdRatioBased * Modify behavior to ignore parent span * Add test for inclusivity property on TraceIdRatioBased sampler * Modify tests in `trace_test.go` to reflect change in parent span behavior * Add to CHANGELOG * Satisfy golint * Update CHANGELOG.md Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@@ -55,32 +55,29 @@ type SamplingResult struct {
|
||||
Attributes []label.KeyValue
|
||||
}
|
||||
|
||||
type probabilitySampler struct {
|
||||
type traceIDRatioSampler struct {
|
||||
traceIDUpperBound uint64
|
||||
description string
|
||||
}
|
||||
|
||||
func (ps probabilitySampler) ShouldSample(p SamplingParameters) SamplingResult {
|
||||
if p.ParentContext.IsSampled() {
|
||||
return SamplingResult{Decision: RecordAndSampled}
|
||||
}
|
||||
|
||||
func (ts traceIDRatioSampler) ShouldSample(p SamplingParameters) SamplingResult {
|
||||
x := binary.BigEndian.Uint64(p.TraceID[0:8]) >> 1
|
||||
if x < ps.traceIDUpperBound {
|
||||
if x < ts.traceIDUpperBound {
|
||||
return SamplingResult{Decision: RecordAndSampled}
|
||||
}
|
||||
return SamplingResult{Decision: NotRecord}
|
||||
}
|
||||
|
||||
func (ps probabilitySampler) Description() string {
|
||||
return ps.description
|
||||
func (ts traceIDRatioSampler) Description() string {
|
||||
return ts.description
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// TraceIDRatioBased samples a given fraction of traces. Fractions >= 1 will
|
||||
// always sample. Fractions < 0 are treated as zero. To respect the
|
||||
// parent trace's `SampledFlag`, the `TraceIDRatioBased` sampler should be used
|
||||
// as a delegate of a `Parent` sampler.
|
||||
//nolint:golint // golint complains about stutter of `trace.TraceIDRatioBased`
|
||||
func TraceIDRatioBased(fraction float64) Sampler {
|
||||
if fraction >= 1 {
|
||||
return AlwaysSample()
|
||||
}
|
||||
@@ -89,9 +86,9 @@ func ProbabilitySampler(fraction float64) Sampler {
|
||||
fraction = 0
|
||||
}
|
||||
|
||||
return &probabilitySampler{
|
||||
return &traceIDRatioSampler{
|
||||
traceIDUpperBound: uint64(fraction * (1 << 63)),
|
||||
description: fmt.Sprintf("ProbabilitySampler{%g}", fraction),
|
||||
description: fmt.Sprintf("TraceIDRatioBased{%g}", fraction),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user