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: allow changes of priority even when the root is non-local #1241

Merged
merged 4 commits into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions ddtrace/tracer/span_test.go
Expand Up @@ -8,13 +8,15 @@ package tracer
import (
"errors"
"fmt"
"math"
"os"
"strings"
"sync/atomic"
"testing"
"time"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/internal/samplernames"

"github.com/DataDog/datadog-agent/pkg/obfuscate"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -348,6 +350,33 @@ func TestSpanSetTagError(t *testing.T) {
})
}

func TestTraceManualKeepAndManualDrop(t *testing.T) {
for _, scenario := range []struct {
tag string
shouldBeKept bool
initialPriority int
dumontg marked this conversation as resolved.
Show resolved Hide resolved
}{
{ext.ManualKeep, true, 0},
{ext.ManualDrop, false, 1},
} {
t.Run(fmt.Sprintf("%s on span with local root", scenario.tag), func(t *testing.T) {
dumontg marked this conversation as resolved.
Show resolved Hide resolved
tracer := newTracer()
span := tracer.newRootSpan("root span", "my service", "my resource")
span.SetTag(scenario.tag, true)
assert.Equal(t, scenario.shouldBeKept, shouldKeep(span))
})

t.Run(fmt.Sprintf("%s on span with non-local root", scenario.tag), func(t *testing.T) {
dumontg marked this conversation as resolved.
Show resolved Hide resolved
tracer := newTracer()
spanCtx := &spanContext{traceID: 42, spanID: 42}
spanCtx.setSamplingPriority("", scenario.initialPriority, samplernames.Upstream, math.NaN())
span := tracer.StartSpan("non-local root span", ChildOf(spanCtx)).(*span)
span.SetTag(scenario.tag, true)
assert.Equal(t, scenario.shouldBeKept, shouldKeep(span))
})
}
}

func TestSpanSetDatadogTags(t *testing.T) {
assert := assert.New(t)

Expand Down
5 changes: 0 additions & 5 deletions ddtrace/tracer/spancontext.go
Expand Up @@ -221,11 +221,6 @@ func (t *trace) setSamplingPriorityLocked(service string, p int, sampler sampler
if t.locked {
return
}
if t.root == nil {
// this trace is distributed (no local root); modifications
// to the sampling priority are not allowed.
t.locked = true
}
if t.priority == nil {
t.priority = new(float64)
}
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/tracer/spancontext_test.go
Expand Up @@ -254,7 +254,7 @@ func TestTracePriorityLocked(t *testing.T) {
assert.Nil(err)
sctx, ok := ctx.(*spanContext)
assert.True(ok)
assert.True(sctx.trace.locked)
assert.False(sctx.trace.locked)
dumontg marked this conversation as resolved.
Show resolved Hide resolved
}

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