Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/tailsampling] Fix SpanCount sampler not using the correct span count for decision #13386

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ func NewSpanCount(logger *zap.Logger, minSpans int32) PolicyEvaluator {
func (c *spanCount) Evaluate(_ pcommon.TraceID, traceData *TraceData) (Decision, error) {
c.logger.Debug("Evaluating spans counts in filter")

traceData.Lock()
batches := traceData.ReceivedBatches
traceData.Unlock()

for _, trace := range batches {
if trace.SpanCount() >= int(c.minSpans) {
return Sampled, nil
}
if int(traceData.SpanCount.Load()) >= int(c.minSpans) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a new test, to demonstrate the problem and ensure we don't have a regression in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like 1 of the tests was already covering this but with the incorrect expected outcome. Fixed it and should now cover this logic.

return Sampled, nil
}
return NotSampled, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/atomic"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -75,6 +76,7 @@ func TestEvaluate_NumberSpans(t *testing.T) {

func newTraceWithMultipleSpans(numberSpans []int32) *TraceData {
var traceBatches []ptrace.Traces
var totalNumberSpans = int32(0)

// For each trace, going to create the number of spans defined in the array
for i := range numberSpans {
Expand All @@ -89,9 +91,11 @@ func newTraceWithMultipleSpans(numberSpans []int32) *TraceData {
span.SetSpanID(pcommon.NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
}
traceBatches = append(traceBatches, traces)
totalNumberSpans += numberSpans[i]
}

return &TraceData{
ReceivedBatches: traceBatches,
SpanCount: atomic.NewInt64(int64(totalNumberSpans)),
}
}
16 changes: 16 additions & 0 deletions unreleased/fix-span-count-incorrect-tracking.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: tailsamplingprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes SpanCount sampler not using the correct span count for decision.

# One or more tracking issues related to the change
issues: []

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: