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: introduce priorities PriorityRuleSamplerKeep (3) and PriorityRuleSamplerReject (-3) for rulesSampler choices. #1012

Merged
merged 2 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions ddtrace/ext/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ package ext
// In a distributed context, it should be set before any context propagation (fork, RPC calls) to be effective.

const (
// PriorityRuleSamplerReject specifies that the rule sampler has decided that this trace should be rejected.
PriorityRuleSamplerReject = -3

// PriorityUserReject informs the backend that a trace should be rejected and not stored.
// This should be used by user code overriding default priority.
PriorityUserReject = -1
Expand All @@ -24,4 +27,7 @@ const (
// PriorityUserKeep informs the backend that a trace should be kept and not stored.
// This should be used by user code overriding default priority.
PriorityUserKeep = 2

// PriorityRuleSamplerKeep specifies that the rule sampler has decided that this trace should be kept.
PriorityRuleSamplerKeep = 3
)
6 changes: 3 additions & 3 deletions ddtrace/tracer/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,15 @@ func (rs *rulesSampler) apply(span *span) bool {
func (rs *rulesSampler) applyRate(span *span, rate float64, now time.Time) {
span.SetTag(keyRulesSamplerAppliedRate, rate)
if !sampledByRate(span.TraceID, rate) {
span.SetTag(ext.SamplingPriority, ext.PriorityAutoReject)
span.SetTag(ext.SamplingPriority, ext.PriorityRuleSamplerReject)
return
}

sampled, rate := rs.limiter.allowOne(now)
if sampled {
span.SetTag(ext.SamplingPriority, ext.PriorityAutoKeep)
span.SetTag(ext.SamplingPriority, ext.PriorityRuleSamplerKeep)
} else {
span.SetTag(ext.SamplingPriority, ext.PriorityAutoReject)
span.SetTag(ext.SamplingPriority, ext.PriorityRuleSamplerReject)
}
span.SetTag(keyRulesSamplerLimiterRate, rate)
}
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/tracer/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ func TestRulesSamplerInternals(t *testing.T) {
// first span kept, second dropped
span := makeSpanAt("http.request", "test-service", now)
rs.applyRate(span, 1.0, now)
assert.EqualValues(ext.PriorityAutoKeep, span.Metrics[keySamplingPriority])
assert.EqualValues(ext.PriorityRuleSamplerKeep, span.Metrics[keySamplingPriority])
assert.Equal(1.0, span.Metrics["_dd.rule_psr"])
assert.Equal(1.0, span.Metrics["_dd.limit_psr"])
span = makeSpanAt("http.request", "test-service", now)
rs.applyRate(span, 1.0, now)
assert.EqualValues(ext.PriorityAutoReject, span.Metrics[keySamplingPriority])
assert.EqualValues(ext.PriorityRuleSamplerReject, span.Metrics[keySamplingPriority])
assert.Equal(1.0, span.Metrics["_dd.rule_psr"])
assert.Equal(0.75, span.Metrics["_dd.limit_psr"])
})
Expand Down