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

v2: remove deprecated samplingpriority #2890

Closed
wants to merge 3 commits into from
Closed
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: 3 additions & 3 deletions appsec/appsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TrackUserLoginSuccessEvent(ctx context.Context, uid string, md map[string]s
for k, v := range md {
span.SetTag(tagPrefix+k, v)
}
span.SetTag(ext.SamplingPriority, ext.PriorityUserKeep)
span.SetTag(ext.ManualKeep, true)
return SetUser(ctx, uid, opts...)
}

Expand All @@ -113,7 +113,7 @@ func TrackUserLoginFailureEvent(ctx context.Context, uid string, exists bool, md
for k, v := range md {
span.SetTag(tagPrefix+k, v)
}
span.SetTag(ext.SamplingPriority, ext.PriorityUserKeep)
span.SetTag(ext.ManualKeep, true)
}

// TrackCustomEvent sets a custom event as service entry span tags. This span is
Expand All @@ -130,7 +130,7 @@ func TrackCustomEvent(ctx context.Context, name string, md map[string]string) {

tagPrefix := "appsec.events." + name + "."
span.SetTag(tagPrefix+"track", true)
span.SetTag(ext.SamplingPriority, ext.PriorityUserKeep)
span.SetTag(ext.ManualKeep, true)
for k, v := range md {
span.SetTag(tagPrefix+k, v)
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/dimfeld/httptreemux.v5/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Example_withSpanOpts() {
router := httptrace.New(
httptrace.WithService("http.router"),
httptrace.WithSpanOptions(
tracer.Tag(ext.SamplingPriority, ext.PriorityUserKeep),
tracer.Tag(ext.ManualKeep, true),
),
)

Expand Down
2 changes: 1 addition & 1 deletion contrib/gorilla/mux/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestSpanOptions(t *testing.T) {
assert := assert.New(t)
mt := mocktracer.Start()
defer mt.Stop()
mux := NewRouter(WithSpanOptions(tracer.Tag(ext.SamplingPriority, 2)))
mux := NewRouter(WithSpanOptions(tracer.Tag(ext.ManualKeep, true)))
mux.Handle("/200", okHandler()).Host("localhost")
r := httptest.NewRequest("GET", "http://localhost/200", nil)
w := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion contrib/julienschmidt/httprouter/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Example_withSpanOpts() {
router := httptrace.New(
httptrace.WithService("http.router"),
httptrace.WithSpanOptions(
tracer.Tag(ext.SamplingPriority, ext.PriorityUserKeep),
tracer.Tag(ext.ManualKeep, true),
),
)

Expand Down
27 changes: 0 additions & 27 deletions ddtrace/ext/priority.go

This file was deleted.

4 changes: 0 additions & 4 deletions ddtrace/ext/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const (
// NetworkDestinationPort is the remote port number of the outbound connection.
NetworkDestinationPort = "network.destination.port"

// SamplingPriority is the tag that marks the sampling priority of a span.
// Deprecated in favor of ManualKeep and ManualDrop.
SamplingPriority = "sampling.priority"

// SQLType sets the sql type tag.
SQLType = "sql"

Expand Down
7 changes: 2 additions & 5 deletions ddtrace/mocktracer/mocktracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestTracerStop(t *testing.T) {
}

func TestTracerStartSpan(t *testing.T) {
parentTags := map[string]interface{}{ext.ServiceName: "root-service", ext.SamplingPriority: -1}
parentTags := map[string]interface{}{ext.ServiceName: "root-service", ext.ManualDrop: true}
// Need to round the monotonic clock so parsed UnixNano values are equal.
// See time.Time documentation for details:
// https://pkg.go.dev/time#Time
Expand All @@ -53,9 +53,6 @@ func TestTracerStartSpan(t *testing.T) {
assert.Equal("my-service", s.Tag(ext.ServiceName))
assert.Equal(parent.SpanID(), s.ParentID())
assert.Equal(parent.TraceID(), s.TraceID())
sp, ok := parent.Context().SamplingPriority()
assert.True(ok)
assert.Equal(-1, sp)
})

t.Run("inherit", func(t *testing.T) {
Expand All @@ -71,7 +68,7 @@ func TestTracerStartSpan(t *testing.T) {
assert.Equal(parent.TraceID(), s.TraceID())
sp, ok := parent.Context().SamplingPriority()
assert.True(ok)
assert.Equal(-1, sp)
assert.Equal(1, sp)
})
}

Expand Down
12 changes: 6 additions & 6 deletions ddtrace/tracer/remote_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestOnRemoteConfigUpdate(t *testing.T) {
s = tracer.StartSpan("not.web.request")
s.Finish()
require.Equal(t, 0.5, s.metrics[keyRulesSamplerAppliedRate])
if p, ok := s.context.trace.samplingPriority(); ok && p > 0 {
if p, ok := s.context.trace.samplingPriority(); ok && p > int(decisionDrop) {
require.Equal(t, samplerToDM(samplernames.RuleRate), s.context.trace.propagatingTags[keyDecisionMaker])
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func TestOnRemoteConfigUpdate(t *testing.T) {
s := tracer.StartSpan("web.request")
s.Finish()
require.Equal(t, 0.1, s.metrics[keyRulesSamplerAppliedRate])
if p, ok := s.context.trace.samplingPriority(); ok && p > 0 {
if p, ok := s.context.trace.samplingPriority(); ok && p > int(decisionDrop) {
require.Equal(t, samplerToDM(samplernames.RuleRate), s.context.trace.propagatingTags[keyDecisionMaker])
}

Expand All @@ -189,7 +189,7 @@ func TestOnRemoteConfigUpdate(t *testing.T) {
s.resource = "not_abc"
s.Finish()
require.Equal(t, 0.5, s.metrics[keyRulesSamplerAppliedRate])
if p, ok := s.context.trace.samplingPriority(); ok && p > 0 {
if p, ok := s.context.trace.samplingPriority(); ok && p > int(decisionDrop) {
require.Equal(t, samplerToDM(samplernames.RuleRate), s.context.trace.propagatingTags[keyDecisionMaker])
}

Expand Down Expand Up @@ -222,7 +222,7 @@ func TestOnRemoteConfigUpdate(t *testing.T) {
s := tracer.StartSpan("web.request")
s.Finish()
require.Equal(t, 0.1, s.metrics[keyRulesSamplerAppliedRate])
if p, ok := s.context.trace.samplingPriority(); ok && p > 0 {
if p, ok := s.context.trace.samplingPriority(); ok && p > int(decisionDrop) {
require.Equal(t, samplerToDM(samplernames.RuleRate), s.context.trace.propagatingTags[keyDecisionMaker])
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func TestOnRemoteConfigUpdate(t *testing.T) {
s.resource = "not_abc"
s.Finish()
require.Equal(t, 0.3, s.metrics[keyRulesSamplerAppliedRate])
if p, ok := s.context.trace.samplingPriority(); ok && p > 0 {
if p, ok := s.context.trace.samplingPriority(); ok && p > int(decisionDrop) {
require.Equal(
t,
samplerToDM(samplernames.RemoteDynamicRule),
Expand All @@ -272,7 +272,7 @@ func TestOnRemoteConfigUpdate(t *testing.T) {
s.resource = "not_abc"
s.Finish()
require.Equal(t, 0.1, s.metrics[keyRulesSamplerAppliedRate])
if p, ok := s.context.trace.samplingPriority(); ok && p > 0 {
if p, ok := s.context.trace.samplingPriority(); ok && p > int(decisionDrop) {
require.Equal(t, samplerToDM(samplernames.RuleRate), s.context.trace.propagatingTags[keyDecisionMaker])
}
telemetryClient.AssertNumberOfCalls(t, "ConfigChange", 2)
Expand Down
7 changes: 3 additions & 4 deletions ddtrace/tracer/rules_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"sync"
"time"

"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
"github.com/DataDog/dd-trace-go/v2/internal/log"
"github.com/DataDog/dd-trace-go/v2/internal/samplernames"

Expand Down Expand Up @@ -487,15 +486,15 @@ func (rs *traceRulesSampler) applyRate(span *Span, rate float64, now time.Time,
span.setMetric(keyRulesSamplerAppliedRate, rate)
delete(span.metrics, keySamplingPriorityRate)
if !sampledByRate(span.traceID, rate) {
span.setSamplingPriorityLocked(ext.PriorityUserReject, sampler)
span.setSamplingPriorityLocked(int(decisionDrop), sampler)
return
}

sampled, rate := rs.limiter.allowOne(now)
if sampled {
span.setSamplingPriorityLocked(ext.PriorityUserKeep, sampler)
span.setSamplingPriorityLocked(int(decisionKeep), sampler)
} else {
span.setSamplingPriorityLocked(ext.PriorityUserReject, sampler)
span.setSamplingPriorityLocked(int(decisionDrop), sampler)
}
span.setMetric(keyRulesSamplerLimiterRate, rate)
}
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/tracer/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ func (ps *prioritySampler) getRate(spn *Span) float64 {
func (ps *prioritySampler) apply(spn *Span) {
rate := ps.getRate(spn)
if sampledByRate(spn.traceID, rate) {
spn.setSamplingPriority(ext.PriorityAutoKeep, samplernames.AgentRate)
spn.setSamplingPriority(int(decisionKeep), samplernames.AgentRate)
} else {
spn.setSamplingPriority(ext.PriorityAutoReject, samplernames.AgentRate)
spn.setSamplingPriority(int(decisionDrop), samplernames.AgentRate)
}
spn.SetTag(keySamplingPriorityRate, rate)
}
22 changes: 11 additions & 11 deletions ddtrace/tracer/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ func TestPrioritySampler(t *testing.T) {
testSpan1.traceID = math.MaxUint64 - (math.MaxUint64 / 4)

ps.apply(testSpan1)
assert.EqualValues(ext.PriorityAutoKeep, testSpan1.metrics[keySamplingPriority])
assert.EqualValues(int(decisionKeep), testSpan1.metrics[keySamplingPriority])
assert.EqualValues(0.5, testSpan1.metrics[keySamplingPriorityRate])

testSpan1.traceID = math.MaxUint64 - (math.MaxUint64 / 3)
ps.apply(testSpan1)
assert.EqualValues(ext.PriorityAutoReject, testSpan1.metrics[keySamplingPriority])
assert.EqualValues(int(decisionDrop), testSpan1.metrics[keySamplingPriority])
assert.EqualValues(0.5, testSpan1.metrics[keySamplingPriorityRate])

testSpan1.service = "other-service"
testSpan1.traceID = 1
assert.EqualValues(ext.PriorityAutoReject, testSpan1.metrics[keySamplingPriority])
assert.EqualValues(int(decisionDrop), testSpan1.metrics[keySamplingPriority])
assert.EqualValues(0.5, testSpan1.metrics[keySamplingPriorityRate])
})
}
Expand Down Expand Up @@ -1012,7 +1012,7 @@ func TestRulesSampler(t *testing.T) {
result = rs.SampleTraceGlobalRate(span)
assert.True(result)
assert.Equal(rate, span.metrics[keyRulesSamplerAppliedRate])
if rate > 0.0 && (span.metrics[keySamplingPriority] != ext.PriorityUserReject) {
if rate > 0.0 && (span.metrics[keySamplingPriority] != float64(decisionDrop)) {
assert.Equal(1.0, span.metrics[keyRulesSamplerLimiterRate])
}
})
Expand All @@ -1033,25 +1033,25 @@ func TestRulesSampler(t *testing.T) {
{
rules: `[{"tags": {"tag1": "non-matching"}, "sample_rate": 0}, {"resource": "/bar", "sample_rate": 1}]`,
generalRate: "0",
samplingPriority: 2,
samplingPriority: float64(decisionKeep),
appliedRate: 1,
},
{
rules: `[{"tags": {"tag1": "non-matching"}, "sample_rate": 0}, {"tags": {"tag1": "val1"}, "sample_rate": 1}]`,
generalRate: "0",
samplingPriority: 2,
samplingPriority: float64(decisionKeep),
appliedRate: 1,
},
{
rules: `[ {"tags": {"tag1": "val1"}, "sample_rate": 0}]`,
generalRate: "1",
samplingPriority: -1,
samplingPriority: float64(decisionDrop),
appliedRate: 0,
},
{
rules: ` [{"service": "webserver", "name": "web.request", "sample_rate": 0}]`,
generalRate: "1",
samplingPriority: -1,
samplingPriority: float64(decisionDrop),
appliedRate: 0,
},
}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func TestRulesSampler(t *testing.T) {
originSpan.SetTag("tag1", "val1")
// based on the Tag("tag0", "val0") start span option, span sampling would be 'drop',
// and setting the second pair of tags doesn't invoke sampling func
assert.EqualValues(t, -1, originSpan.metrics[keySamplingPriority])
assert.EqualValues(t, float64(decisionDrop), originSpan.metrics[keySamplingPriority])
assert.EqualValues(t, 0, originSpan.metrics[keyRulesSamplerAppliedRate])
headers := TextMapCarrier(map[string]string{})

Expand Down Expand Up @@ -1320,12 +1320,12 @@ func TestRulesSamplerInternals(t *testing.T) {
// first span kept, second dropped
span := makeSpanAt("http.request", "test-service", now)
rs.traces.applyRate(span, 1.0, now, samplernames.RuleRate)
assert.EqualValues(ext.PriorityUserKeep, span.metrics[keySamplingPriority])
assert.EqualValues(int(decisionKeep), span.metrics[keySamplingPriority])
assert.Equal(1.0, span.metrics[keyRulesSamplerAppliedRate])
assert.Equal(1.0, span.metrics[keyRulesSamplerLimiterRate])
span = makeSpanAt("http.request", "test-service", now)
rs.traces.applyRate(span, 1.0, now, samplernames.RuleRate)
assert.EqualValues(ext.PriorityUserReject, span.metrics[keySamplingPriority])
assert.EqualValues(int(decisionDrop), span.metrics[keySamplingPriority])
assert.Equal(1.0, span.metrics[keyRulesSamplerAppliedRate])
assert.Equal(0.75, span.metrics[keyRulesSamplerLimiterRate])
})
Expand Down
14 changes: 5 additions & 9 deletions ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (s *Span) AddLink(spanContext *SpanContext, attributes map[string]string) {

samplingDecision, hasSamplingDecision := spanContext.SamplingPriority()
var flags uint32
if hasSamplingDecision && samplingDecision >= ext.PriorityAutoKeep {
if hasSamplingDecision && samplingDecision >= int(decisionKeep) {
flags = uint32(1<<31 | 1)
} else if hasSamplingDecision {
flags = uint32(1<<31 | 0)
Expand Down Expand Up @@ -503,11 +503,11 @@ func (s *Span) setTagBool(key string, v bool) {
}
case ext.ManualDrop:
if v {
s.setSamplingPriorityLocked(ext.PriorityUserReject, samplernames.Manual)
s.setSamplingPriorityLocked(int(decisionDrop), samplernames.Manual)
}
case ext.ManualKeep:
if v {
s.setSamplingPriorityLocked(ext.PriorityUserKeep, samplernames.Manual)
s.setSamplingPriorityLocked(int(decisionKeep), samplernames.Manual)
}
default:
if v {
Expand All @@ -528,12 +528,8 @@ func (s *Span) setMetric(key string, v float64) {
switch key {
case ext.ManualKeep:
if v == float64(samplernames.AppSec) {
s.setSamplingPriorityLocked(ext.PriorityUserKeep, samplernames.AppSec)
s.setSamplingPriorityLocked(int(decisionKeep), samplernames.AppSec)
}
case ext.SamplingPriority:
// ext.SamplingPriority is deprecated in favor of ext.ManualKeep and ext.ManualDrop.
// We have it here for backward compatibility.
s.setSamplingPriorityLocked(int(v), samplernames.Manual)
default:
s.metrics[key] = v
}
Expand Down Expand Up @@ -722,7 +718,7 @@ func obfuscatedResource(o *obfuscate.Obfuscator, typ, resource string) string {
// shouldKeep reports whether the trace should be kept.
// a single span being kept implies the whole trace being kept.
func shouldKeep(s *Span) bool {
if p, ok := s.context.SamplingPriority(); ok && p > 0 {
if p, ok := s.context.SamplingPriority(); ok && p >= int(decisionKeep) {
// positive sampling priorities stay
return true
}
Expand Down
Loading
Loading