Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Remove the deprecated `Extract` and `Inject` functions from `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#7952)
- Add the `http.route` metric attribute to `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`. (#7966)

### Added

- Add support for configuring propagators in `go.opentelemetry.io/contrib/config`. (#7977)

<!-- Released section -->
<!-- Don't change this section unless doing release -->

Expand Down
6 changes: 6 additions & 0 deletions otelconf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ go 1.24.0
require (
github.com/prometheus/client_golang v1.23.2
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/contrib/propagators/autoprop v0.63.0
go.opentelemetry.io/contrib/propagators/aws v1.38.0
go.opentelemetry.io/contrib/propagators/b3 v1.38.0
go.opentelemetry.io/contrib/propagators/jaeger v1.38.0
go.opentelemetry.io/contrib/propagators/ot v1.38.0
go.opentelemetry.io/otel v1.38.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.14.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0
Expand Down Expand Up @@ -45,6 +50,7 @@ require (
github.com/prometheus/procfs v0.17.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sys v0.36.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions otelconf/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/contrib/propagators/autoprop v0.63.0 h1:S3+4UwR3Y1tUKklruMwOacAFInNvtuOexz4ZTmJNAyw=
go.opentelemetry.io/contrib/propagators/autoprop v0.63.0/go.mod h1:qpIuOggbbw2T9nKRaO1je/oTRKd4zslAcJonN8LYbTg=
go.opentelemetry.io/contrib/propagators/aws v1.38.0 h1:eRZ7asSbLc5dH7+TBzL6hFKb1dabz0IV51uUUwYRZts=
go.opentelemetry.io/contrib/propagators/aws v1.38.0/go.mod h1:wXqc9NTGcXapBExHBDVLEZlByu6quiQL8w7Tjgv8TCg=
go.opentelemetry.io/contrib/propagators/b3 v1.38.0 h1:uHsCCOSKl0kLrV2dLkFK+8Ywk9iKa/fptkytc6aFFEo=
go.opentelemetry.io/contrib/propagators/b3 v1.38.0/go.mod h1:wMRSZJZcY8ya9mApLLhwIMjqmApy2o/Ml+62lhvxyHU=
go.opentelemetry.io/contrib/propagators/jaeger v1.38.0 h1:nXGeLvT1QtCAhkASkP/ksjkTKZALIaQBIW+JSIw1KIc=
go.opentelemetry.io/contrib/propagators/jaeger v1.38.0/go.mod h1:oMvOXk78ZR3KEuPMBgp/ThAMDy9ku/eyUVztr+3G6Wo=
go.opentelemetry.io/contrib/propagators/ot v1.38.0 h1:k4gSyyohaDXI8F9BDXYC3uO2vr5sRNeQFMsN9Zn0EoI=
go.opentelemetry.io/contrib/propagators/ot v1.38.0/go.mod h1:2hDsuiHRO39SRUMhYGqmj64z/IuMRoxE4bBSFR82Lo8=
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.14.0 h1:OMqPldHt79PqWKOMYIAQs3CxAi7RLgPxwfFSwr4ZxtM=
Expand Down Expand Up @@ -89,6 +99,8 @@ go.opentelemetry.io/proto/otlp v1.8.0 h1:fRAZQDcAFHySxpJ1TwlA1cJ4tvcrw7nXl9xWWC8
go.opentelemetry.io/proto/otlp v1.8.0/go.mod h1:tIeYOeNBU4cvmPqpaji1P+KbB4Oloai8wN4rWzRrFF0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
Expand Down
42 changes: 42 additions & 0 deletions otelconf/v0.3.0/propagator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otelconf // import "go.opentelemetry.io/contrib/otelconf/v0.3.0"

import (
"errors"

"go.opentelemetry.io/otel/propagation"

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

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

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

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

var names []string
for _, name := range cfg.opentelemetryConfig.Propagator.Composite {
if name == nil {
return nil, errInvalidPropagatorNil
}
if *name == "" {
continue
}

names = append(names, *name)
}
if len(names) == 0 {
return autoprop.NewTextMapPropagator(), nil
}

return autoprop.TextMapPropagator(names...)
}
195 changes: 195 additions & 0 deletions otelconf/v0.3.0/propagator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otelconf

import (
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/propagation"

"go.opentelemetry.io/contrib/propagators/aws/xray"
"go.opentelemetry.io/contrib/propagators/b3"
"go.opentelemetry.io/contrib/propagators/jaeger"
"go.opentelemetry.io/contrib/propagators/ot"
)

func TestPropagator(t *testing.T) {
tests := []struct {
name string
cfg configOptions
want propagation.TextMapPropagator
wantErr bool
errMsg string
}{
{
name: "nil propagator config",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: nil,
},
},
want: propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}),
wantErr: false,
},
{
name: "valid tracecontext",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("tracecontext")},
},
},
},
want: propagation.TraceContext{},
wantErr: false,
},
{
name: "valid baggage",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("baggage")},
},
},
},
want: propagation.Baggage{},
wantErr: false,
},
{
name: "valid b3",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("b3")},
},
},
},
want: b3.New(),
wantErr: false,
},
{
name: "valid b3multi",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("b3multi")},
},
},
},
want: b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader)),
wantErr: false,
},
{
name: "valid jaeger",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("jaeger")},
},
},
},
want: jaeger.Jaeger{},
wantErr: false,
},
{
name: "valid xray",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("xray")},
},
},
},
want: xray.Propagator{},
wantErr: false,
},
{
name: "valid ottrace",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("ottrace")},
},
},
},
want: ot.OT{},
wantErr: false,
},
{
name: "multiple propagators",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("tracecontext"), ptr("baggage"), ptr("b3")},
},
},
},
want: propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, b3.New()),
wantErr: false,
},
{
name: "empty composite",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{},
},
},
},
want: propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}),
wantErr: false,
Comment on lines +132 to +142
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this following the specification? Should it not be a noop propagator?

},
{
name: "empty propagator name",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr(""), ptr("tracecontext")},
},
},
},
want: propagation.TraceContext{},
wantErr: false,
},
Comment on lines +144 to +155
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it mean that somebody explicitly set an empty string? Is not an error scenario? Shouldn't we failed the parsing if anything is wrong in the YAML file?

{
name: "nil propagator name",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{nil, ptr("tracecontext")},
},
},
},
want: nil,
wantErr: true,
},
{
name: "unsupported propagator",
cfg: configOptions{
opentelemetryConfig: OpenTelemetryConfiguration{
Propagator: &Propagator{
Composite: []*string{ptr("unknown")},
},
},
},
want: propagation.NewCompositeTextMapPropagator(),
wantErr: true,
errMsg: "unknown propagator",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := propagator(tt.cfg)
if tt.wantErr {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.errMsg)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}