Skip to content

Commit 2b13cdf

Browse files
committed
[processor/tailsampling] fix inverted not sampled AND policy
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 open-telemetry#9768 that introduced support for using invert_match within and sub policies.
1 parent b097d46 commit 2b13cdf

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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)