Skip to content

Commit

Permalink
tracer: support b3multi alias for b3 carrier (#1594)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
katiehockman committed Nov 23, 2022
1 parent 01e9de7 commit 5ac4f70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ddtrace/tracer/textmap.go
Expand Up @@ -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{})
Expand Down
14 changes: 10 additions & 4 deletions ddtrace/tracer/textmap_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5ac4f70

Please sign in to comment.