From 5ac4f70a322b41cdaa784767d6935e4b82996b29 Mon Sep 17 00:00:00 2001 From: Katie Hockman Date: Wed, 23 Nov 2022 10:14:27 -0500 Subject: [PATCH] tracer: support `b3multi` alias for `b3` carrier (#1594) ### What does this PR do? Adds b3multi as a supported propagator for trace context extraction and injection, which will act as a new alias for the existing b3 propagator. ### Motivation This is to align with the OTel specification. ### Describe how to test/QA your changes Set `DD_PROPAGATION_STYLE_INJECT` and `DD_PROPAGATION_STYLE_EXTRACT` to `"b3"` and ensure that any headers headers propagate as expected. Then do the same for setting it to `"b3multi"` and verify that the behavior didn't change. --- ddtrace/tracer/textmap.go | 2 +- ddtrace/tracer/textmap_test.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ddtrace/tracer/textmap.go b/ddtrace/tracer/textmap.go index 3373dbcfb9..139714a27b 100644 --- a/ddtrace/tracer/textmap.go +++ b/ddtrace/tracer/textmap.go @@ -185,7 +185,7 @@ func getPropagators(cfg *PropagatorConfig, env string) []Propagator { switch strings.ToLower(v) { case "datadog": list = append(list, dd) - case "b3": + case "b3", "b3multi": if !cfg.B3 { // propagatorB3 hasn't already been added, add a new one. list = append(list, &propagatorB3{}) diff --git a/ddtrace/tracer/textmap_test.go b/ddtrace/tracer/textmap_test.go index e2d7c699af..2c50c91bfb 100644 --- a/ddtrace/tracer/textmap_test.go +++ b/ddtrace/tracer/textmap_test.go @@ -355,9 +355,9 @@ func TestTextMapPropagator(t *testing.T) { }) } -func TestB3(t *testing.T) { +func testB3(t *testing.T, b3Header string) { t.Run("inject", func(t *testing.T) { - os.Setenv("DD_PROPAGATION_STYLE_INJECT", "B3") + os.Setenv("DD_PROPAGATION_STYLE_INJECT", b3Header) defer os.Unsetenv("DD_PROPAGATION_STYLE_INJECT") var tests = []struct { @@ -409,7 +409,7 @@ func TestB3(t *testing.T) { }) t.Run("extract", func(t *testing.T) { - os.Setenv("DD_PROPAGATION_STYLE_EXTRACT", "b3") + os.Setenv("DD_PROPAGATION_STYLE_EXTRACT", b3Header) defer os.Unsetenv("DD_PROPAGATION_STYLE_EXTRACT") var tests = []struct { @@ -455,7 +455,7 @@ func TestB3(t *testing.T) { }) t.Run("multiple", func(t *testing.T) { - os.Setenv("DD_PROPAGATION_STYLE_EXTRACT", "Datadog,B3") + os.Setenv("DD_PROPAGATION_STYLE_EXTRACT", fmt.Sprintf("Datadog,%s", b3Header)) defer os.Unsetenv("DD_PROPAGATION_STYLE_EXTRACT") b3Headers := TextMapCarrier(map[string]string{ @@ -496,6 +496,12 @@ func TestB3(t *testing.T) { assert.Equal(2, p) }) +} + +func TestB3(t *testing.T) { + testB3(t, "b3") + testB3(t, "b3multi") + t.Run("config", func(t *testing.T) { os.Setenv("DD_PROPAGATION_STYLE_INJECT", "datadog") defer os.Unsetenv("DD_PROPAGATION_STYLE_INJECT")