Skip to content
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
7 changes: 5 additions & 2 deletions ddtrace/opentelemetry/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ func TestTracerOptions(t *testing.T) {
assert.Contains(fmt.Sprint(sp), "dd.env=wrapper_env")
}

func TestSpanContext(t *testing.T) {
func TestParentContext(t *testing.T) {
assert := assert.New(t)
tp := NewTracerProvider()
// Start tracer with trace sample rules, which should be ignored in favor of the sampling priority inherited from tracer.Extract
tp := NewTracerProvider(tracer.WithSamplingRules([]tracer.SamplingRule{
{Rate: 0}, // This should be applied only when a brand new root span is started
}))
defer tp.Shutdown()
otel.SetTracerProvider(tp)
tr := otel.Tracer("")
Expand Down
2 changes: 2 additions & 0 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ func (t *tracer) StartSpan(operationName string, options ...ddtrace.StartSpanOpt
span.ParentID = context.spanID
if p, ok := context.SamplingPriority(); ok {
span.setMetric(keySamplingPriority, float64(p))
// TODO: Check whether prio is trace rules or span rules?
context.trace.setLocked(true)
}
if context.span != nil {
// local parent, inherit service
Expand Down
18 changes: 18 additions & 0 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,24 @@ func TestStartSpanOrigin(t *testing.T) {
assert.Equal("synthetics", carrier2[originHeader])
}

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

tracer := newTracer(WithSamplingRules([]SamplingRule{
{Rate: 0},
}))
defer tracer.Stop()
root := tracer.StartSpan("web.request").(*span)
root.SetBaggageItem("x", "y")
root.setMetric(keySamplingPriority, float64(2))
ctx := root.Context().(*spanContext)
headers := http.Header{}
carrier := HTTPHeadersCarrier(headers)
tracer.Inject(ctx, carrier)

assert.Equal("2", headers.Get(DefaultPriorityHeader))
}

func TestPropagationDefaults(t *testing.T) {
t.Setenv(headerPropagationStyleExtract, "datadog")
t.Setenv(headerPropagationStyleInject, "datadog")
Expand Down
Loading