Skip to content

Commit

Permalink
crosslink and be more strict with nil/empty
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling committed Feb 15, 2025
1 parent 8e0d0d0 commit d336f76
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
9 changes: 8 additions & 1 deletion config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,12 @@ require (
google.golang.org/protobuf v1.36.5 // indirect
)

// remove after v0.59.0 of autoprop
replace go.opentelemetry.io/contrib/propagators/autoprop => ../propagators/autoprop

replace go.opentelemetry.io/contrib/propagators/jaeger => ../propagators/jaeger

replace go.opentelemetry.io/contrib/propagators/b3 => ../propagators/b3

replace go.opentelemetry.io/contrib/propagators/aws => ../propagators/aws

replace go.opentelemetry.io/contrib/propagators/ot => ../propagators/ot
23 changes: 20 additions & 3 deletions config/v0.3.0/propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@
package config // import "go.opentelemetry.io/contrib/config/v0.3.0"

import (
"errors"

"go.opentelemetry.io/contrib/propagators/autoprop"
"go.opentelemetry.io/otel/propagation"
)

var (
errInvalidPropagatorEmpty = errors.New("invalid propagator name: empty")
errInvalidPropagatorNil = errors.New("invalid propagator name: nil")
)

func propagator(cfg configOptions) (propagation.TextMapPropagator, error) {
if cfg.opentelemetryConfig.Propagator == nil {
return autoprop.NewTextMapPropagator(), nil
}

names := make([]string, 0, len(cfg.opentelemetryConfig.Propagator.Composite))
n := len(cfg.opentelemetryConfig.Propagator.Composite)
if n == 0 {
return autoprop.NewTextMapPropagator(), nil
}

names := make([]string, 0, n)
for _, name := range cfg.opentelemetryConfig.Propagator.Composite {
if name != nil && *name != "" {
names = append(names, *name)
if name == nil {
return nil, errInvalidPropagatorNil
}
if *name == "" {
return nil, errInvalidPropagatorEmpty
}

names = append(names, *name)
}

return autoprop.TextMapPropagator(names...)
Expand Down
4 changes: 2 additions & 2 deletions config/v0.3.0/propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func TestPropagator(t *testing.T) {
},
},
},
want: propagation.TraceContext{},
wantErr: false,
want: nil,
wantErr: true,
},
{
name: "unsupported propagator",
Expand Down

0 comments on commit d336f76

Please sign in to comment.