Skip to content

Commit

Permalink
ddtrace/tracer: remove agent_psr when rule_psr is set (#2668)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianashevchenko committed May 8, 2024
1 parent 7f6597f commit 93ee25e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ddtrace/tracer/rules_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ func (rs *traceRulesSampler) sampleRules(span *span) bool {
}

func (rs *traceRulesSampler) applyRate(span *span, rate float64, now time.Time, sampler samplernames.SamplerName) {
span.SetTag(keyRulesSamplerAppliedRate, rate)
span.setMetric(keyRulesSamplerAppliedRate, rate)
delete(span.Metrics, keySamplingPriorityRate)
if !sampledByRate(span.TraceID, rate) {
span.setSamplingPriority(ext.PriorityUserReject, sampler)
return
Expand Down Expand Up @@ -614,6 +615,7 @@ func (rs *singleSpanRulesSampler) apply(span *span) bool {
return false
}
}
delete(span.Metrics, keySamplingPriorityRate)
span.setMetric(keySpanSamplingMechanism, float64(samplernames.SingleSpan))
span.setMetric(keySingleSpanSamplingRuleRate, rate)
if rule.MaxPerSecond != 0 {
Expand Down
13 changes: 13 additions & 0 deletions ddtrace/tracer/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,19 @@ func TestRulesSampler(t *testing.T) {
s.Finish()
assert.EqualValues(t, s.(*span).Metrics[keySamplingPriority], 2)
})

t.Run("no-agent_psr-with-rules-sampling", func(t *testing.T) {
t.Setenv("DD_TRACE_SAMPLING_RULES", `[{"resource": "keep_me", "sample_rate": 0}]`)
_, _, _, stop := startTestTracer(t)
defer stop()

s, _ := StartSpanFromContext(context.Background(), "whatever")
s.SetTag(ext.ResourceName, "keep_me")
s.Finish()
span := s.(*span)
assert.NotContains(t, span.Metrics, keySamplingPriorityRate)
assert.Contains(t, span.Metrics, keyRulesSamplerAppliedRate)
})
}

func TestSamplingRuleUnmarshal(t *testing.T) {
Expand Down

0 comments on commit 93ee25e

Please sign in to comment.