diff --git a/.chloggen/fix-tailsampling-and-policy-precedence.yaml b/.chloggen/fix-tailsampling-and-policy-precedence.yaml new file mode 100644 index 000000000000..51f119520020 --- /dev/null +++ b/.chloggen/fix-tailsampling-and-policy-precedence.yaml @@ -0,0 +1,9 @@ +change_type: bug_fix +component: tailsamplingprocessor +note: Fix precedence of inverted match in and policy +issues: [33671] +subtext: | + Previously if the decision from a policy evaluation was `NotSampled` or `InvertNotSampled` it would return a `NotSampled` decision regardless, effectively downgrading the result. + + This was breaking the documented behaviour that inverted decisions should take precedence over all others. +change_logs: [user] diff --git a/processor/tailsamplingprocessor/internal/sampling/and.go b/processor/tailsamplingprocessor/internal/sampling/and.go index ec2fc075deaf..b5779fb82c9d 100644 --- a/processor/tailsamplingprocessor/internal/sampling/and.go +++ b/processor/tailsamplingprocessor/internal/sampling/and.go @@ -30,14 +30,14 @@ func NewAnd( // Evaluate looks at the trace data and returns a corresponding SamplingDecision. func (c *And) Evaluate(ctx context.Context, traceID pcommon.TraceID, trace *TraceData) (Decision, error) { // The policy iterates over all sub-policies and returns Sampled if all sub-policies returned a Sampled Decision. - // If any subpolicy returns NotSampled, it returns NotSampled Decision. + // If any subpolicy returns NotSampled or InvertNotSampled it returns that for _, sub := range c.subpolicies { decision, err := sub.Evaluate(ctx, traceID, trace) if err != nil { return Unspecified, err } if decision == NotSampled || decision == InvertNotSampled { - return NotSampled, nil + return decision, nil } } diff --git a/processor/tailsamplingprocessor/internal/sampling/and_test.go b/processor/tailsamplingprocessor/internal/sampling/and_test.go index 89f62a955be6..6c68279cf183 100644 --- a/processor/tailsamplingprocessor/internal/sampling/and_test.go +++ b/processor/tailsamplingprocessor/internal/sampling/and_test.go @@ -113,6 +113,6 @@ func TestAndEvaluatorStringInvertNotSampled(t *testing.T) { } decision, err := and.Evaluate(context.Background(), traceID, trace) require.NoError(t, err, "Failed to evaluate and policy: %v", err) - assert.Equal(t, decision, NotSampled) + assert.Equal(t, decision, InvertNotSampled) }