Skip to content

Commit e2fda02

Browse files
authored
[processor/tailsampling] fix InvertNotSampled decision precedence when inside and sub policy (#33671)
**Description:** This fixes the handling of AND policies that contain a sub-policy with invert_match=true. 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. This is related to the changes made in #9768 that introduced support for using invert_match within and sub policies. **Link to tracking Issue:** #33656 **Testing:** I tested manually that this fixes the issue described in #33656 and also updated the tests. If you have any suggestions for more tests we could add let me know. **Documentation:**
1 parent 40b334a commit e2fda02

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
change_type: bug_fix
2+
component: tailsamplingprocessor
3+
note: Fix precedence of inverted match in and policy
4+
issues: [33671]
5+
subtext: |
6+
Previously if the decision from a policy evaluation was `NotSampled` or `InvertNotSampled` it would return a `NotSampled` decision regardless, effectively downgrading the result.
7+
8+
This was breaking the documented behaviour that inverted decisions should take precedence over all others.
9+
change_logs: [user]

processor/tailsamplingprocessor/internal/sampling/and.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ func NewAnd(
3030
// Evaluate looks at the trace data and returns a corresponding SamplingDecision.
3131
func (c *And) Evaluate(ctx context.Context, traceID pcommon.TraceID, trace *TraceData) (Decision, error) {
3232
// The policy iterates over all sub-policies and returns Sampled if all sub-policies returned a Sampled Decision.
33-
// If any subpolicy returns NotSampled, it returns NotSampled Decision.
33+
// If any subpolicy returns NotSampled or InvertNotSampled it returns that
3434
for _, sub := range c.subpolicies {
3535
decision, err := sub.Evaluate(ctx, traceID, trace)
3636
if err != nil {
3737
return Unspecified, err
3838
}
3939
if decision == NotSampled || decision == InvertNotSampled {
40-
return NotSampled, nil
40+
return decision, nil
4141
}
4242

4343
}

processor/tailsamplingprocessor/internal/sampling/and_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ func TestAndEvaluatorStringInvertNotSampled(t *testing.T) {
113113
}
114114
decision, err := and.Evaluate(context.Background(), traceID, trace)
115115
require.NoError(t, err, "Failed to evaluate and policy: %v", err)
116-
assert.Equal(t, decision, NotSampled)
116+
assert.Equal(t, decision, InvertNotSampled)
117117

118118
}

0 commit comments

Comments
 (0)