Skip to content

Commit

Permalink
v2: remove sampling priority (#2906)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahkm authored Oct 9, 2024
1 parent 1843e7b commit 4bdbe4c
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 48 deletions.
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 @@ -52,7 +52,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 @@ -54,7 +54,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
4 changes: 0 additions & 4 deletions ddtrace/ext/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,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
2 changes: 1 addition & 1 deletion ddtrace/mocktracer/mocktracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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 Down
4 changes: 0 additions & 4 deletions ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,6 @@ func (s *Span) setMetric(key string, v float64) {
if v == float64(samplernames.AppSec) {
s.setSamplingPriorityLocked(ext.PriorityUserKeep, 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
6 changes: 3 additions & 3 deletions ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestAddSpanLink(t *testing.T) {

// Test adding a link with a sampling decision
linkedSpanSampled := newSpan("linked_sampled", "service", "res", 3, 4, 0)
linkedSpanSampled.Context().setSamplingPriority(2, samplernames.Manual)
linkedSpanSampled.Context().setSamplingPriority(ext.PriorityUserKeep, samplernames.Manual)
rootSpan.AddLink(linkedSpanSampled.Context(), map[string]string{})
assert.Equal(len(rootSpan.spanLinks), 2)
spanLinkSampled := rootSpan.spanLinks[1]
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestShouldDrop(t *testing.T) {
} {
t.Run("", func(t *testing.T) {
s := newSpan("", "", "", 1, 1, 0)
s.SetTag(ext.SamplingPriority, tt.prio)
s.setSamplingPriority(tt.prio, samplernames.Default)
s.SetTag(ext.EventSampleRate, tt.rate)
atomic.StoreInt32(&s.context.errors, tt.errors)
assert.Equal(t, shouldKeep(s), tt.want)
Expand Down Expand Up @@ -836,7 +836,7 @@ func TestSpanSamplingPriority(t *testing.T) {
ext.PriorityUserKeep,
999, // not used, but we should allow it
} {
span.SetTag(ext.SamplingPriority, priority)
span.setSamplingPriority(priority, samplernames.Default)
v, ok := span.metrics[keySamplingPriority]
assert.True(ok)
assert.EqualValues(priority, v)
Expand Down
18 changes: 9 additions & 9 deletions ddtrace/tracer/spancontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func testAsyncSpanRace(t *testing.T) {
for i := 0; i < 100; i++ {
// The test has 100 iterations because it is not easy to reproduce the race.
t.Run("", func(t *testing.T) {
root, ctx := StartSpanFromContext(context.Background(), "root", Tag(ext.SamplingPriority, ext.PriorityUserKeep))
root, ctx := StartSpanFromContext(context.Background(), "root", Tag(ext.ManualKeep, true))
var wg sync.WaitGroup
done := make(chan struct{})
wg.Add(1)
Expand Down Expand Up @@ -116,7 +116,7 @@ func testAsyncSpanRace(t *testing.T) {
for i := 0; i < 50; i++ {
// to trigger the bug, the child should be created after the root was finished,
// as its being flushed
child, _ := StartSpanFromContext(ctx, "child", Tag(ext.SamplingPriority, ext.PriorityUserKeep))
child, _ := StartSpanFromContext(ctx, "child", Tag(ext.ManualKeep, true))
child.Finish()
}
}()
Expand Down Expand Up @@ -306,12 +306,12 @@ func TestSpanFinishPriority(t *testing.T) {

root := tracer.StartSpan(
"root",
Tag(ext.SamplingPriority, 1),
)
root.setSamplingPriority(ext.PriorityAutoKeep, samplernames.Manual)
child := tracer.StartSpan(
"child",
ChildOf(root.Context()),
Tag(ext.SamplingPriority, 2),
Tag(ext.ManualKeep, true),
)
child.Finish()
root.Finish()
Expand Down Expand Up @@ -837,35 +837,35 @@ func TestSetSamplingPriorityLocked(t *testing.T) {
tr := trace{
propagatingTags: map[string]string{},
}
tr.setSamplingPriorityLocked(0, samplernames.RemoteRate)
tr.setSamplingPriorityLocked(ext.PriorityAutoReject, samplernames.RemoteRate)
assert.Empty(t, tr.propagatingTags[keyDecisionMaker])
})
t.Run("UnknownSamplerIsIgnored", func(t *testing.T) {
tr := trace{
propagatingTags: map[string]string{},
}
tr.setSamplingPriorityLocked(0, samplernames.Unknown)
tr.setSamplingPriorityLocked(ext.PriorityAutoReject, samplernames.Unknown)
assert.Empty(t, tr.propagatingTags[keyDecisionMaker])
})
t.Run("NoPriorAndP1IsAccepted", func(t *testing.T) {
tr := trace{
propagatingTags: map[string]string{},
}
tr.setSamplingPriorityLocked(1, samplernames.RemoteRate)
tr.setSamplingPriorityLocked(ext.PriorityAutoKeep, samplernames.RemoteRate)
assert.Equal(t, "-2", tr.propagatingTags[keyDecisionMaker])
})
t.Run("PriorAndP1AndSameDMIsIgnored", func(t *testing.T) {
tr := trace{
propagatingTags: map[string]string{keyDecisionMaker: "-1"},
}
tr.setSamplingPriorityLocked(1, samplernames.AgentRate)
tr.setSamplingPriorityLocked(ext.PriorityAutoKeep, samplernames.AgentRate)
assert.Equal(t, "-1", tr.propagatingTags[keyDecisionMaker])
})
t.Run("PriorAndP1DifferentDMAccepted", func(t *testing.T) {
tr := trace{
propagatingTags: map[string]string{keyDecisionMaker: "-1"},
}
tr.setSamplingPriorityLocked(1, samplernames.RemoteRate)
tr.setSamplingPriorityLocked(ext.PriorityAutoKeep, samplernames.RemoteRate)
assert.Equal(t, "-2", tr.propagatingTags[keyDecisionMaker])
})
}
Expand Down
5 changes: 3 additions & 2 deletions ddtrace/tracer/sqlcomment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

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

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -180,7 +181,7 @@ func TestSQLCommentCarrier(t *testing.T) {
if tc.injectSpan {
traceID = uint64(10)
root := tracer.StartSpan("service.calling.db", WithSpanID(traceID))
root.SetTag(ext.SamplingPriority, tc.samplingPriority)
root.setSamplingPriority(tc.samplingPriority, samplernames.Default)
spanCtx = root.Context()
}

Expand Down Expand Up @@ -346,7 +347,7 @@ func BenchmarkSQLCommentExtraction(b *testing.B) {
func setupBenchmark() (*tracer, *SpanContext, SQLCommentCarrier) {
tracer, _ := newTracer(WithService("whiskey-service !#$%&'()*+,/:;=?@[]"), WithEnv("test-env"), WithServiceVersion("1.0.0"))
root := tracer.StartSpan("service.calling.db", WithSpanID(10))
root.SetTag(ext.SamplingPriority, 2)
root.SetTag(ext.ManualKeep, true)
spanCtx := root.Context()
carrier := SQLCommentCarrier{Query: "SELECT 1 FROM dual", Mode: DBMPropagationModeFull, DBServiceName: "whiskey-db"}
return tracer, spanCtx, carrier
Expand Down
8 changes: 4 additions & 4 deletions ddtrace/tracer/textmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,9 @@ func (*propagatorB3SingleHeader) extractTextMap(reader TextMapReader) (*SpanCont
case "":
break
case "1", "d": // Treat 'debug' traces as priority 1
ctx.setSamplingPriority(1, samplernames.Unknown)
ctx.setSamplingPriority(ext.PriorityAutoKeep, samplernames.Unknown)
case "0":
ctx.setSamplingPriority(0, samplernames.Unknown)
ctx.setSamplingPriority(ext.PriorityAutoReject, samplernames.Unknown)
default:
return ErrSpanContextCorrupted
}
Expand Down Expand Up @@ -1187,11 +1187,11 @@ func parseTracestate(ctx *SpanContext, header string) {
}
if parentP == 1 && stateP <= 0 {
// Auto keep (1) and set the decision maker to default
ctx.setSamplingPriority(1, samplernames.Default)
ctx.setSamplingPriority(ext.PriorityAutoKeep, samplernames.Default)
}
if parentP == 0 && stateP > 0 {
// Auto drop (0) and drop the decision maker
ctx.setSamplingPriority(0, samplernames.Unknown)
ctx.setSamplingPriority(ext.PriorityAutoReject, samplernames.Unknown)
dropDM = true
}
} else if key == "p" {
Expand Down
24 changes: 12 additions & 12 deletions ddtrace/tracer/textmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func TestTextMapPropagatorInjectHeader(t *testing.T) {

root := tracer.StartSpan("web.request")
root.SetBaggageItem("item", "x")
root.SetTag(ext.SamplingPriority, 0)
root.setSamplingPriority(ext.PriorityAutoReject, samplernames.Default)
ctx := root.Context()
headers := http.Header{}

Expand Down Expand Up @@ -411,7 +411,7 @@ func Test257CharacterDDTracestateLengh(t *testing.T) {
defer tracer.Stop()
assert := assert.New(t)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, ext.PriorityUserKeep)
root.SetTag(ext.ManualKeep, true)
ctx := root.Context()
ctx.origin = "rum"
ctx.traceID = traceIDFrom64Bits(1)
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestTextMapPropagator(t *testing.T) {
defer tracer.Stop()
assert.NoError(t, err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
ctx := root.Context()
headers := TextMapCarrier(map[string]string{})
Expand Down Expand Up @@ -1042,7 +1042,7 @@ func TestEnvVars(t *testing.T) {
defer tracer.Stop()
assert.NoError(t, err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
ctx := root.Context()
ctx.traceID = traceIDFrom64Bits(tc.in[0])
Expand Down Expand Up @@ -1558,7 +1558,7 @@ func TestEnvVars(t *testing.T) {
assert := assert.New(t)
assert.Nil(err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, tc.priority)
root.setSamplingPriority(tc.priority, samplernames.Default)
ctx := root.Context()
ctx.origin = tc.origin
ctx.traceID = tc.tid
Expand Down Expand Up @@ -1588,7 +1588,7 @@ func TestEnvVars(t *testing.T) {
assert := assert.New(t)
assert.Nil(err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, ext.PriorityUserKeep)
root.SetTag(ext.ManualKeep, true)
ctx := root.Context()
ctx.origin = "old_tracestate"
ctx.traceID = traceIDFrom64Bits(1229782938247303442)
Expand Down Expand Up @@ -1945,7 +1945,7 @@ func TestNonePropagator(t *testing.T) {
defer tracer.Stop()
assert.NoError(t, err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
ctx := root.Context()
ctx.traceID = traceIDFrom64Bits(1)
Expand All @@ -1968,7 +1968,7 @@ func TestNonePropagator(t *testing.T) {
// reinitializing to capture log output, since propagators are parsed before logger is set
tracer.config.propagator = NewPropagator(&PropagatorConfig{})
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
ctx := root.Context()
ctx.traceID = traceIDFrom64Bits(1)
Expand All @@ -1991,7 +1991,7 @@ func TestNonePropagator(t *testing.T) {
defer tracer.Stop()
assert.NoError(err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
headers := TextMapCarrier(map[string]string{})

Expand All @@ -2008,7 +2008,7 @@ func TestNonePropagator(t *testing.T) {
defer tracer.Stop()
assert.NoError(t, err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
ctx := root.Context()
ctx.traceID = traceIDFrom64Bits(1)
Expand All @@ -2029,7 +2029,7 @@ func TestNonePropagator(t *testing.T) {
assert.NoError(t, err)
defer tracer.Stop()
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
ctx := root.Context()
ctx.traceID = traceIDFrom64Bits(1)
Expand All @@ -2051,7 +2051,7 @@ func TestNonePropagator(t *testing.T) {
defer tracer.Stop()
assert.NoError(t, err)
root := tracer.StartSpan("web.request")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
root.SetBaggageItem("item", "x")
ctx := root.Context()
ctx.traceID = traceIDFrom64Bits(1)
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestTracerStartSpan(t *testing.T) {
tracer, err := newTracer()
defer tracer.Stop()
assert.NoError(t, err)
span := tracer.StartSpan("web.request", Tag(ext.SamplingPriority, ext.PriorityUserKeep))
span := tracer.StartSpan("web.request", Tag(ext.ManualKeep, true))
assert.Equal(t, float64(ext.PriorityUserKeep), span.metrics[keySamplingPriority])
assert.Equal(t, "-4", span.context.trace.propagatingTags[keyDecisionMaker])
})
Expand Down Expand Up @@ -892,7 +892,7 @@ func TestPropagationDefaults(t *testing.T) {
assert.Nil(err)
root := tracer.StartSpan("web.request")
root.SetBaggageItem("x", "y")
root.SetTag(ext.SamplingPriority, -1)
root.SetTag(ext.ManualDrop, true)
ctx := root.Context()
headers := http.Header{}

Expand Down Expand Up @@ -935,7 +935,7 @@ func TestTracerSamplingPriorityPropagation(t *testing.T) {
tracer, err := newTracer()
defer tracer.Stop()
assert.Nil(err)
root := tracer.StartSpan("web.request", Tag(ext.SamplingPriority, 2))
root := tracer.StartSpan("web.request", Tag(ext.ManualKeep, true))
child := tracer.StartSpan("db.query", ChildOf(root.Context()))
assert.EqualValues(2, root.metrics[keySamplingPriority])
assert.Equal("-4", root.context.trace.propagatingTags[keyDecisionMaker])
Expand Down

0 comments on commit 4bdbe4c

Please sign in to comment.