Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Nov 6, 2024
1 parent 7683b59 commit a499780
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ func (t *tracer) worker(tick <-chan time.Time) {
t.sampleChunk(trace)
fmt.Printf("[DEBUG] Post-sampleChunk willSend=%v spans=%d\n", trace.willSend, len(trace.spans))
if len(trace.spans) != 0 {
fmt.Printf("[DEBUG] Actually sending trace: willSend=%v spans=%d\n", trace.willSend, len(trace.spans))
t.traceWriter.add(trace.spans)
}
case <-tick:
Expand Down Expand Up @@ -424,6 +425,7 @@ func (t *tracer) worker(tick <-chan time.Time) {
t.sampleChunk(trace)
fmt.Printf("[DEBUG] Post-sampleChunk willSend=%v spans=%d\n", trace.willSend, len(trace.spans))
if len(trace.spans) != 0 {
fmt.Printf("[DEBUG] Actually sending trace: willSend=%v spans=%d\n", trace.willSend, len(trace.spans))
t.traceWriter.add(trace.spans)
}
default:
Expand All @@ -445,9 +447,15 @@ type chunk struct {

// sampleChunk applies single-span sampling to the provided trace.
func (t *tracer) sampleChunk(c *chunk) {
fmt.Printf("[DEBUG] sampleChunk entry with willSend=%v\n", c.willSend)
if len(c.spans) > 0 {
if p, ok := c.spans[0].context.SamplingPriority(); ok && p > 0 {
// The trace is kept, no need to run single span sampling rules.
if p, ok := c.spans[0].context.SamplingPriority(); ok {
fmt.Printf("[DEBUG] Existing sampling priority: %d\n", p)
// Key change: Set willSend based on priority
c.willSend = p > 0
if !c.willSend {
fmt.Printf("[DEBUG] Setting willSend=false due to priority %d\n", p)
}
return
}
}
Expand Down Expand Up @@ -780,18 +788,14 @@ func (t *tracer) sample(span *span) {
span.setMetric(sampleRateMetricKey, rs.Rate())
}

// First try trace rules sampling
if t.rulesSampling.SampleTraceGlobalRate(span) {
fmt.Printf("[DEBUG] Global rate sampled span\n")
return
}
if sampled := t.rulesSampling.SampleTrace(span); sampled || t.rulesSampling.HasSpanRules() {
// If we have span rules or the trace was sampled, return here
fmt.Printf("[DEBUG] Rules sampling decision: %v\n", sampled)
// Check rules first
if sampled := t.rulesSampling.SampleTrace(span); !sampled {
fmt.Printf("[DEBUG] Rules sampling rejected span\n")
span.context.trace.drop()
span.context.trace.setSamplingPriority(ext.PriorityAutoReject, samplernames.RuleRate)
return
}

// Only fall back to priority sampling if no rules matched
fmt.Printf("[DEBUG] Priority sampling span\n")
t.prioritySampling.apply(span)
}
Expand Down

0 comments on commit a499780

Please sign in to comment.