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

ddtrace/tracer: remove agent_psr when rule_psr is set #2668

Merged
4 changes: 3 additions & 1 deletion ddtrace/tracer/rules_sampler.go
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
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