| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package x // import "go.opentelemetry.io/contrib/otelconf/x" |
| 5 |
|
| 6 |
import ( |
| 7 |
"strings" |
| 8 |
|
| 9 |
"go.opentelemetry.io/otel/propagation" |
| 10 |
"golang.org/x/exp/maps" |
| 11 |
|
| 12 |
"go.opentelemetry.io/contrib/propagators/autoprop" |
| 13 |
) |
| 14 |
|
| 15 |
func newPropagator(p *Propagator) (propagation.TextMapPropagator, error) { |
| 16 |
if p == nil { |
| 17 |
return propagation.NewCompositeTextMapPropagator(), nil |
| 18 |
} |
| 19 |
|
| 20 |
n := len(p.Composite) |
| 21 |
if n == 0 && p.CompositeList == nil { |
| 22 |
return propagation.NewCompositeTextMapPropagator(), nil |
| 23 |
} |
| 24 |
|
| 25 |
names := map[string]struct{}{} |
| 26 |
for _, propagator := range p.Composite { |
| 27 |
if propagator.B3 != nil { |
| 28 |
names["b3"] = struct{}{} |
| 29 |
} |
| 30 |
if propagator.B3Multi != nil { |
| 31 |
names["b3multi"] = struct{}{} |
| 32 |
} |
| 33 |
if propagator.Baggage != nil { |
| 34 |
names["baggage"] = struct{}{} |
| 35 |
} |
| 36 |
if propagator.Jaeger != nil { |
| 37 |
names["jaeger"] = struct{}{} |
| 38 |
} |
| 39 |
if propagator.Ottrace != nil { |
| 40 |
names["ottrace"] = struct{}{} |
| 41 |
} |
| 42 |
if propagator.Tracecontext != nil { |
| 43 |
names["tracecontext"] = struct{}{} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
if p.CompositeList != nil { |
| 48 |
for v := range strings.SplitSeq(*p.CompositeList, ",") { |
| 49 |
names[v] = struct{}{} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
if len(names) == 0 { |
| 54 |
return autoprop.NewTextMapPropagator(), nil |
| 55 |
} |
| 56 |
|
| 57 |
return autoprop.TextMapPropagator(maps.Keys(names)...) |
| 58 |
} |