From 277b822d470f958f07d6a5a53d0c8ee1bfe33ea1 Mon Sep 17 00:00:00 2001 From: Diana Shevchenko Date: Wed, 7 Dec 2022 14:34:31 +0100 Subject: [PATCH 1/3] Added none as a supported propagator for trace context extraction and injection --- ddtrace/tracer/textmap.go | 3 ++ ddtrace/tracer/textmap_test.go | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/ddtrace/tracer/textmap.go b/ddtrace/tracer/textmap.go index 139714a27b..85869903c2 100644 --- a/ddtrace/tracer/textmap.go +++ b/ddtrace/tracer/textmap.go @@ -177,6 +177,9 @@ func getPropagators(cfg *PropagatorConfig, env string) []Propagator { if ps == "" { return defaultPs } + if ps == "none" { + return nil + } var list []Propagator if cfg.B3 { list = append(list, &propagatorB3{}) diff --git a/ddtrace/tracer/textmap_test.go b/ddtrace/tracer/textmap_test.go index 2c50c91bfb..b27b0ef347 100644 --- a/ddtrace/tracer/textmap_test.go +++ b/ddtrace/tracer/textmap_test.go @@ -501,6 +501,7 @@ func testB3(t *testing.T, b3Header string) { func TestB3(t *testing.T) { testB3(t, "b3") testB3(t, "b3multi") + testB3(t, "none,b3multi") t.Run("config", func(t *testing.T) { os.Setenv("DD_PROPAGATION_STYLE_INJECT", "datadog") @@ -555,6 +556,64 @@ func TestB3(t *testing.T) { }) } +func TestNonePropagator(t *testing.T) { + t.Run("inject/none", func(t *testing.T) { + t.Setenv("DD_PROPAGATION_STYLE_INJECT", "none") + tracer := newTracer() + root := tracer.StartSpan("web.request").(*span) + root.SetTag(ext.SamplingPriority, -1) + root.SetBaggageItem("item", "x") + ctx, ok := root.Context().(*spanContext) + ctx.traceID = 1 + ctx.spanID = 1 + headers := TextMapCarrier(map[string]string{}) + err := tracer.Inject(ctx, headers) + + assert := assert.New(t) + assert.True(ok) + assert.Nil(err) + assert.Len(headers, 0) + }) + + t.Run("extract/none", func(t *testing.T) { + t.Setenv("DD_PROPAGATION_STYLE_EXTRACT", "none") + assert := assert.New(t) + tracer := newTracer() + root := tracer.StartSpan("web.request").(*span) + root.SetTag(ext.SamplingPriority, -1) + root.SetBaggageItem("item", "x") + headers := TextMapCarrier(map[string]string{}) + + _, err := tracer.Extract(headers) + + assert.Equal(err, ErrSpanContextNotFound) + assert.Len(headers, 0) + }) + + t.Run("inject,extract/none", func(t *testing.T) { + t.Setenv("DD_PROPAGATION_STYLE_INJECT", "none") + t.Setenv("DD_PROPAGATION_STYLE_EXTRACT", "none") + tracer := newTracer() + root := tracer.StartSpan("web.request").(*span) + root.SetTag(ext.SamplingPriority, -1) + root.SetBaggageItem("item", "x") + ctx, ok := root.Context().(*spanContext) + ctx.traceID = 1 + ctx.spanID = 1 + headers := TextMapCarrier(map[string]string{}) + err := tracer.Inject(ctx, headers) + + assert := assert.New(t) + assert.True(ok) + assert.Nil(err) + assert.Len(headers, 0) + + _, err = tracer.Extract(headers) + assert.Equal(err, ErrSpanContextNotFound) + assert.Len(headers, 0) + }) +} + func assertTraceTags(t *testing.T, expected, actual string) { assert.ElementsMatch(t, strings.Split(expected, ","), strings.Split(actual, ",")) } From 8344747221ac2f54355bae30167c72accf07816a Mon Sep 17 00:00:00 2001 From: Diana Shevchenko Date: Wed, 7 Dec 2022 17:13:58 +0100 Subject: [PATCH 2/3] removed redundant test assertion --- ddtrace/tracer/textmap_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ddtrace/tracer/textmap_test.go b/ddtrace/tracer/textmap_test.go index b27b0ef347..f37f038711 100644 --- a/ddtrace/tracer/textmap_test.go +++ b/ddtrace/tracer/textmap_test.go @@ -610,7 +610,6 @@ func TestNonePropagator(t *testing.T) { _, err = tracer.Extract(headers) assert.Equal(err, ErrSpanContextNotFound) - assert.Len(headers, 0) }) } From 82093ab8dd158da5120dfdce0d2555dbba02cfd0 Mon Sep 17 00:00:00 2001 From: Diana Shevchenko Date: Thu, 8 Dec 2022 14:25:45 +0100 Subject: [PATCH 3/3] Updated a log message; updated a test --- ddtrace/tracer/textmap.go | 3 +++ ddtrace/tracer/textmap_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ddtrace/tracer/textmap.go b/ddtrace/tracer/textmap.go index 85869903c2..beebb22ca4 100644 --- a/ddtrace/tracer/textmap.go +++ b/ddtrace/tracer/textmap.go @@ -193,6 +193,9 @@ func getPropagators(cfg *PropagatorConfig, env string) []Propagator { // propagatorB3 hasn't already been added, add a new one. list = append(list, &propagatorB3{}) } + case "none": + log.Warn("Propagator \"none\" has no effect when combined with other propagators. "+ + "To disable the propagator, set `%s=none`", env) default: log.Warn("unrecognized propagator: %s\n", v) } diff --git a/ddtrace/tracer/textmap_test.go b/ddtrace/tracer/textmap_test.go index f37f038711..2e1e860ffc 100644 --- a/ddtrace/tracer/textmap_test.go +++ b/ddtrace/tracer/textmap_test.go @@ -575,6 +575,30 @@ func TestNonePropagator(t *testing.T) { assert.Len(headers, 0) }) + t.Run("inject/none,b3", func(t *testing.T) { + t.Setenv("DD_PROPAGATION_STYLE_INJECT", "none,b3") + tp := new(testLogger) + tracer := newTracer(WithLogger(tp)) + // reinitializing to capture log output, since propagators are parsed before logger is set + tracer.config.propagator = NewPropagator(&PropagatorConfig{}) + root := tracer.StartSpan("web.request").(*span) + root.SetTag(ext.SamplingPriority, -1) + root.SetBaggageItem("item", "x") + ctx, ok := root.Context().(*spanContext) + ctx.traceID = 1 + ctx.spanID = 1 + headers := TextMapCarrier(map[string]string{}) + err := tracer.Inject(ctx, headers) + + assert := assert.New(t) + assert.True(ok) + assert.Nil(err) + assert.Equal("0000000000000001", headers[b3TraceIDHeader]) + assert.Equal("0000000000000001", headers[b3SpanIDHeader]) + assert.Contains(tp.lines[0], "Propagator \"none\" has no effect when combined with other propagators. "+ + "To disable the propagator, set `DD_PROPAGATION_STYLE_INJECT=none`") + }) + t.Run("extract/none", func(t *testing.T) { t.Setenv("DD_PROPAGATION_STYLE_EXTRACT", "none") assert := assert.New(t)