From 9f17aedb1286444c521c3f0adf5e225f3e4b02d4 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:59:50 -0700 Subject: [PATCH 01/20] processors/baggage: add baggage span processor Fixes #5397 Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- CHANGELOG.md | 2 + CODEOWNERS | 2 + processors/baggage/doc.go | 7 ++++ processors/baggage/go.mod | 20 +++++++++ processors/baggage/go.sum | 27 ++++++++++++ processors/baggage/processor.go | 35 ++++++++++++++++ processors/baggage/processor_test.go | 62 ++++++++++++++++++++++++++++ versions.yaml | 4 ++ 8 files changed, 159 insertions(+) create mode 100644 processors/baggage/doc.go create mode 100644 processors/baggage/go.mod create mode 100644 processors/baggage/go.sum create mode 100644 processors/baggage/processor.go create mode 100644 processors/baggage/processor_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index e15cbf3c8c7..f5dcf815035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) - `NewSDK` in `go.opentelemetry.io/contrib/config` now returns a configured SDK with a valid `MeterProvider`. (#4804) +- The `go.opentelemetry.io/contrib/processors/baggage` module. + This module provides a Baggage Span Processor. (#5397) ### Changed diff --git a/CODEOWNERS b/CODEOWNERS index 01ae4b69a99..887d04e79f8 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -46,6 +46,8 @@ instrumentation/net/http/httptrace/otelhttptrace/ @open-te instrumentation/net/http/otelhttp/ @open-telemetry/go-approvers @Aneurysm9 @dmathieu instrumentation/runtime/ @open-telemetry/go-approvers @MadVikingGod +processors/baggage/ @open-telemetry/go-approvers @codeboten + propagators/autoprop/ @open-telemetry/go-approvers @MrAlias propagators/aws/ @open-telemetry/go-approvers @Aneurysm9 propagators/b3/ @open-telemetry/go-approvers @pellared diff --git a/processors/baggage/doc.go b/processors/baggage/doc.go new file mode 100644 index 00000000000..ae47a4c21ec --- /dev/null +++ b/processors/baggage/doc.go @@ -0,0 +1,7 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package baggage implements the baggage span processor which duplicates +// onto a span the attributes found in Baggage in the parent context at +// the moment the span is started. +package baggage // import "go.opentelemetry.io/contrib/processors/baggage" diff --git a/processors/baggage/go.mod b/processors/baggage/go.mod new file mode 100644 index 00000000000..893dea858be --- /dev/null +++ b/processors/baggage/go.mod @@ -0,0 +1,20 @@ +module go.opentelemetry.io/contrib/processors/baggage + +go 1.21 + +require ( + github.com/stretchr/testify v1.9.0 + go.opentelemetry.io/otel v1.25.0 + go.opentelemetry.io/otel/sdk v1.25.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/otel/metric v1.25.0 // indirect + go.opentelemetry.io/otel/trace v1.25.0 // indirect + golang.org/x/sys v0.18.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/processors/baggage/go.sum b/processors/baggage/go.sum new file mode 100644 index 00000000000..c94c7b1876b --- /dev/null +++ b/processors/baggage/go.sum @@ -0,0 +1,27 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.opentelemetry.io/otel v1.25.0 h1:gldB5FfhRl7OJQbUHt/8s0a7cE8fbsPAtdpRaApKy4k= +go.opentelemetry.io/otel v1.25.0/go.mod h1:Wa2ds5NOXEMkCmUou1WA7ZBfLTHWIsp034OVD7AO+Vg= +go.opentelemetry.io/otel/metric v1.25.0 h1:LUKbS7ArpFL/I2jJHdJcqMGxkRdxpPHE0VU/D4NuEwA= +go.opentelemetry.io/otel/metric v1.25.0/go.mod h1:rkDLUSd2lC5lq2dFNrX9LGAbINP5B7WBkC78RXCpH5s= +go.opentelemetry.io/otel/sdk v1.25.0 h1:PDryEJPC8YJZQSyLY5eqLeafHtG+X7FWnf3aXMtxbqo= +go.opentelemetry.io/otel/sdk v1.25.0/go.mod h1:oFgzCM2zdsxKzz6zwpTZYLLQsFwc+K0daArPdIhuxkw= +go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1Dq6RM= +go.opentelemetry.io/otel/trace v1.25.0/go.mod h1:hCCs70XM/ljO+BeQkyFnbK28SBIJ/Emuha+ccrCRT7I= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/processors/baggage/processor.go b/processors/baggage/processor.go new file mode 100644 index 00000000000..85fa77cd782 --- /dev/null +++ b/processors/baggage/processor.go @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package baggage + +import ( + "context" + + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/baggage" + "go.opentelemetry.io/otel/sdk/trace" +) + +type baggageSpanProcessor struct{} + +var _ trace.SpanProcessor = (*baggageSpanProcessor)(nil) + +// Returns a new baggageSpanProcessor. +// +// The Baggage span processor duplicates onto a span the attributes found +// in Baggage in the parent context at the moment the span is started. +func NewBaggageSpanProcessor() trace.SpanProcessor { + return &baggageSpanProcessor{} +} + +func (processor baggageSpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) { + baggage := baggage.FromContext(ctx) + for _, entry := range baggage.Members() { + span.SetAttributes(attribute.String(entry.Key(), entry.Value())) + } +} + +func (processor baggageSpanProcessor) OnEnd(s trace.ReadOnlySpan) {} +func (processor baggageSpanProcessor) Shutdown(context.Context) error { return nil } +func (processor baggageSpanProcessor) ForceFlush(context.Context) error { return nil } diff --git a/processors/baggage/processor_test.go b/processors/baggage/processor_test.go new file mode 100644 index 00000000000..d973bbe40bc --- /dev/null +++ b/processors/baggage/processor_test.go @@ -0,0 +1,62 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package baggage + +import ( + "context" + "net/url" + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/baggage" + "go.opentelemetry.io/otel/sdk/trace" +) + +var _ trace.SpanExporter = &testExporter{} + +type testExporter struct { + spans []trace.ReadOnlySpan +} + +func (e *testExporter) Start(ctx context.Context) error { return nil } +func (e *testExporter) Shutdown(ctx context.Context) error { return nil } + +func (e *testExporter) ExportSpans(ctx context.Context, ss []trace.ReadOnlySpan) error { + e.spans = append(e.spans, ss...) + return nil +} + +func NewTestExporter() *testExporter { + return &testExporter{} +} + +func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { + // create ctx with some baggage + ctx := context.Background() + suitcase := baggage.FromContext(ctx) + packingCube, _ := baggage.NewMember("baggage.test", url.PathEscape("baggage value")) + suitcase, _ = suitcase.SetMember(packingCube) + ctx = baggage.ContextWithBaggage(ctx, suitcase) + + // create trace provider with baggage processor and test exporter + exporter := NewTestExporter() + tp := trace.NewTracerProvider( + trace.WithSpanProcessor(NewBaggageSpanProcessor()), + trace.WithSpanProcessor(trace.NewSimpleSpanProcessor(exporter)), + ) + + // create tracer and start/end span + tracer := tp.Tracer("test") + _, span := tracer.Start(ctx, "test") + span.End() + + assert.Equal(t, 1, len(exporter.spans)) + assert.Equal(t, 1, len(exporter.spans[0].Attributes())) + + for _, attr := range exporter.spans[0].Attributes() { + assert.Equal(t, attribute.Key("baggage.test"), attr.Key) + assert.Equal(t, "baggage value", attr.Value.AsString()) + } +} diff --git a/versions.yaml b/versions.yaml index 0513ed39d41..08957fe95fe 100644 --- a/versions.yaml +++ b/versions.yaml @@ -77,6 +77,10 @@ module-sets: version: v0.0.1 modules: - go.opentelemetry.io/contrib/bridges/otelslog + experimental-processors: + version: v0.0.1 + modules: + - go.opentelemetry.io/contrib/processors/baggage excluded-modules: - go.opentelemetry.io/contrib/instrgen - go.opentelemetry.io/contrib/instrgen/driver From 33e94b272d0e37741588050fc1e2f2243ac9aaea Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:14:16 -0700 Subject: [PATCH 02/20] fix lint issues + dependabot generate Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- .github/dependabot.yml | 9 +++++++++ processors/baggage/processor.go | 7 +++---- processors/baggage/processor_test.go | 9 +++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bb6bf7d7278..79d9ab9a003 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -541,6 +541,15 @@ updates: schedule: interval: weekly day: sunday + - package-ecosystem: gomod + directory: /processors/baggage + labels: + - dependencies + - go + - Skip Changelog + schedule: + interval: weekly + day: sunday - package-ecosystem: gomod directory: /propagators/autoprop labels: diff --git a/processors/baggage/processor.go b/processors/baggage/processor.go index 85fa77cd782..01a3e27e281 100644 --- a/processors/baggage/processor.go +++ b/processors/baggage/processor.go @@ -7,7 +7,7 @@ import ( "context" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/baggage" + otelbaggage "go.opentelemetry.io/otel/baggage" "go.opentelemetry.io/otel/sdk/trace" ) @@ -15,7 +15,7 @@ type baggageSpanProcessor struct{} var _ trace.SpanProcessor = (*baggageSpanProcessor)(nil) -// Returns a new baggageSpanProcessor. +// NewBaggageSpanProcessor returns a new baggageSpanProcessor. // // The Baggage span processor duplicates onto a span the attributes found // in Baggage in the parent context at the moment the span is started. @@ -24,8 +24,7 @@ func NewBaggageSpanProcessor() trace.SpanProcessor { } func (processor baggageSpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) { - baggage := baggage.FromContext(ctx) - for _, entry := range baggage.Members() { + for _, entry := range otelbaggage.FromContext(ctx).Members() { span.SetAttributes(attribute.String(entry.Key(), entry.Value())) } } diff --git a/processors/baggage/processor_test.go b/processors/baggage/processor_test.go index d973bbe40bc..7b3760697a7 100644 --- a/processors/baggage/processor_test.go +++ b/processors/baggage/processor_test.go @@ -9,8 +9,9 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/baggage" + otelbaggage "go.opentelemetry.io/otel/baggage" "go.opentelemetry.io/otel/sdk/trace" ) @@ -35,10 +36,10 @@ func NewTestExporter() *testExporter { func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { // create ctx with some baggage ctx := context.Background() - suitcase := baggage.FromContext(ctx) - packingCube, _ := baggage.NewMember("baggage.test", url.PathEscape("baggage value")) + suitcase := otelbaggage.FromContext(ctx) + packingCube, _ := otelbaggage.NewMember("baggage.test", url.PathEscape("baggage value")) suitcase, _ = suitcase.SetMember(packingCube) - ctx = baggage.ContextWithBaggage(ctx, suitcase) + ctx = otelbaggage.ContextWithBaggage(ctx, suitcase) // create trace provider with baggage processor and test exporter exporter := NewTestExporter() From b65b1297c84cc0d42725461b965f3244b8f43b98 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:52:33 -0700 Subject: [PATCH 03/20] apply review feedback Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- processors/baggage/processor.go | 2 +- processors/baggage/processor_test.go | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/processors/baggage/processor.go b/processors/baggage/processor.go index 01a3e27e281..b1424736d44 100644 --- a/processors/baggage/processor.go +++ b/processors/baggage/processor.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggage +package baggage // import "go.opentelemetry.io/contrib/processors/baggage" import ( "context" diff --git a/processors/baggage/processor_test.go b/processors/baggage/processor_test.go index 7b3760697a7..e82b97f6b0b 100644 --- a/processors/baggage/processor_test.go +++ b/processors/baggage/processor_test.go @@ -5,10 +5,10 @@ package baggage import ( "context" - "net/url" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/attribute" otelbaggage "go.opentelemetry.io/otel/baggage" @@ -37,8 +37,10 @@ func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { // create ctx with some baggage ctx := context.Background() suitcase := otelbaggage.FromContext(ctx) - packingCube, _ := otelbaggage.NewMember("baggage.test", url.PathEscape("baggage value")) - suitcase, _ = suitcase.SetMember(packingCube) + packingCube, err := otelbaggage.NewMemberRaw("baggage.test", "baggage value") + require.NoError(t, err) + suitcase, err = suitcase.SetMember(packingCube) + require.NoError(t, err) ctx = otelbaggage.ContextWithBaggage(ctx, suitcase) // create trace provider with baggage processor and test exporter @@ -53,8 +55,8 @@ func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { _, span := tracer.Start(ctx, "test") span.End() - assert.Equal(t, 1, len(exporter.spans)) - assert.Equal(t, 1, len(exporter.spans[0].Attributes())) + assert.Len(t, exporter.spans, 1) + assert.Len(t, exporter.spans[0].Attributes(), 1) for _, attr := range exporter.spans[0].Attributes() { assert.Equal(t, attribute.Key("baggage.test"), attr.Key) From cfa0e234b1790badbb1798630a0c8eb75330c8e1 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:57:36 -0700 Subject: [PATCH 04/20] more review feedback Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- processors/baggage/processor_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/processors/baggage/processor_test.go b/processors/baggage/processor_test.go index e82b97f6b0b..6a12bdf0f4a 100644 --- a/processors/baggage/processor_test.go +++ b/processors/baggage/processor_test.go @@ -34,14 +34,13 @@ func NewTestExporter() *testExporter { } func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { - // create ctx with some baggage - ctx := context.Background() - suitcase := otelbaggage.FromContext(ctx) + suitcase, err := otelbaggage.New() + require.NoError(t, err) packingCube, err := otelbaggage.NewMemberRaw("baggage.test", "baggage value") require.NoError(t, err) suitcase, err = suitcase.SetMember(packingCube) require.NoError(t, err) - ctx = otelbaggage.ContextWithBaggage(ctx, suitcase) + ctx := otelbaggage.ContextWithBaggage(context.Background(), suitcase) // create trace provider with baggage processor and test exporter exporter := NewTestExporter() From 8e648db5ce44d35245a7fd56e195ced1165d86f5 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:58:11 -0700 Subject: [PATCH 05/20] Update processors/baggage/processor_test.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert Pająk --- processors/baggage/processor_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/processors/baggage/processor_test.go b/processors/baggage/processor_test.go index 6a12bdf0f4a..890d23ec06a 100644 --- a/processors/baggage/processor_test.go +++ b/processors/baggage/processor_test.go @@ -57,8 +57,6 @@ func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { assert.Len(t, exporter.spans, 1) assert.Len(t, exporter.spans[0].Attributes(), 1) - for _, attr := range exporter.spans[0].Attributes() { - assert.Equal(t, attribute.Key("baggage.test"), attr.Key) - assert.Equal(t, "baggage value", attr.Value.AsString()) - } + want := []attribute.KeyValue{ attribute.String("baggage.test", "baggage value") } + assert.Equal(t, want, exporter.spans[0].Attributes()) } From 9ed502091dac1a542996f591114d72aced378e27 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:13:48 -0700 Subject: [PATCH 06/20] lint Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- processors/baggage/processor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processors/baggage/processor_test.go b/processors/baggage/processor_test.go index 890d23ec06a..8cf3ee19ce0 100644 --- a/processors/baggage/processor_test.go +++ b/processors/baggage/processor_test.go @@ -57,6 +57,6 @@ func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { assert.Len(t, exporter.spans, 1) assert.Len(t, exporter.spans[0].Attributes(), 1) - want := []attribute.KeyValue{ attribute.String("baggage.test", "baggage value") } + want := []attribute.KeyValue{attribute.String("baggage.test", "baggage value")} assert.Equal(t, want, exporter.spans[0].Attributes()) } From fa28a2f828d1163a304236d81e454e73d503e58b Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Fri, 19 Apr 2024 08:55:21 -0700 Subject: [PATCH 07/20] feedback from review Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- README.md | 1 + processors/baggage/processor.go | 16 ++++++++-------- processors/baggage/processor_test.go | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6ce390cd594..913696a4041 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Collection of 3rd-party packages for [OpenTelemetry-Go](https://github.com/open- - [Exporters](./exporters/): Packages providing OpenTelemetry exporters for 3rd-party export formats. - [Samplers](./samplers/): Packages providing additional implementations of OpenTelemetry samplers. - [Bridges](./bridges/): Packages providing adapters for 3rd-party instrumentation frameworks. +- [Processors](./processors/): Packages providing additional implementations of OpenTelemetry processors. ## Project Status diff --git a/processors/baggage/processor.go b/processors/baggage/processor.go index b1424736d44..c266c0f1482 100644 --- a/processors/baggage/processor.go +++ b/processors/baggage/processor.go @@ -11,24 +11,24 @@ import ( "go.opentelemetry.io/otel/sdk/trace" ) -type baggageSpanProcessor struct{} +type SpanProcessor struct{} -var _ trace.SpanProcessor = (*baggageSpanProcessor)(nil) +var _ trace.SpanProcessor = (*SpanProcessor)(nil) -// NewBaggageSpanProcessor returns a new baggageSpanProcessor. +// NewBaggageSpanProcessor returns a new SpanProcessor. // // The Baggage span processor duplicates onto a span the attributes found // in Baggage in the parent context at the moment the span is started. func NewBaggageSpanProcessor() trace.SpanProcessor { - return &baggageSpanProcessor{} + return &SpanProcessor{} } -func (processor baggageSpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) { +func (processor SpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) { for _, entry := range otelbaggage.FromContext(ctx).Members() { span.SetAttributes(attribute.String(entry.Key(), entry.Value())) } } -func (processor baggageSpanProcessor) OnEnd(s trace.ReadOnlySpan) {} -func (processor baggageSpanProcessor) Shutdown(context.Context) error { return nil } -func (processor baggageSpanProcessor) ForceFlush(context.Context) error { return nil } +func (processor SpanProcessor) OnEnd(s trace.ReadOnlySpan) {} +func (processor SpanProcessor) Shutdown(context.Context) error { return nil } +func (processor SpanProcessor) ForceFlush(context.Context) error { return nil } diff --git a/processors/baggage/processor_test.go b/processors/baggage/processor_test.go index 8cf3ee19ce0..dacf29a672c 100644 --- a/processors/baggage/processor_test.go +++ b/processors/baggage/processor_test.go @@ -33,7 +33,7 @@ func NewTestExporter() *testExporter { return &testExporter{} } -func TestBaggageSpanProcessorAppendsBaggageAttributes(t *testing.T) { +func TestSpanProcessorAppendsBaggageAttributes(t *testing.T) { suitcase, err := otelbaggage.New() require.NoError(t, err) packingCube, err := otelbaggage.NewMemberRaw("baggage.test", "baggage value") From 26a0d60ff7f09ae2f8a97f85fc5aa2e3a2d1c1aa Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Fri, 19 Apr 2024 08:58:22 -0700 Subject: [PATCH 08/20] rename baggage -> baggagetrace Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- processors/baggage/{ => baggagetrace}/doc.go | 4 ++-- processors/baggage/{ => baggagetrace}/go.mod | 0 processors/baggage/{ => baggagetrace}/go.sum | 0 processors/baggage/{ => baggagetrace}/processor.go | 2 +- processors/baggage/{ => baggagetrace}/processor_test.go | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename processors/baggage/{ => baggagetrace}/doc.go (51%) rename processors/baggage/{ => baggagetrace}/go.mod (100%) rename processors/baggage/{ => baggagetrace}/go.sum (100%) rename processors/baggage/{ => baggagetrace}/processor.go (91%) rename processors/baggage/{ => baggagetrace}/processor_test.go (98%) diff --git a/processors/baggage/doc.go b/processors/baggage/baggagetrace/doc.go similarity index 51% rename from processors/baggage/doc.go rename to processors/baggage/baggagetrace/doc.go index ae47a4c21ec..66a58d3e191 100644 --- a/processors/baggage/doc.go +++ b/processors/baggage/baggagetrace/doc.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -// Package baggage implements the baggage span processor which duplicates +// package baggagetrace implements the baggage span processor which duplicates // onto a span the attributes found in Baggage in the parent context at // the moment the span is started. -package baggage // import "go.opentelemetry.io/contrib/processors/baggage" +package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" diff --git a/processors/baggage/go.mod b/processors/baggage/baggagetrace/go.mod similarity index 100% rename from processors/baggage/go.mod rename to processors/baggage/baggagetrace/go.mod diff --git a/processors/baggage/go.sum b/processors/baggage/baggagetrace/go.sum similarity index 100% rename from processors/baggage/go.sum rename to processors/baggage/baggagetrace/go.sum diff --git a/processors/baggage/processor.go b/processors/baggage/baggagetrace/processor.go similarity index 91% rename from processors/baggage/processor.go rename to processors/baggage/baggagetrace/processor.go index c266c0f1482..a47c94875fd 100644 --- a/processors/baggage/processor.go +++ b/processors/baggage/baggagetrace/processor.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggage // import "go.opentelemetry.io/contrib/processors/baggage" +package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" import ( "context" diff --git a/processors/baggage/processor_test.go b/processors/baggage/baggagetrace/processor_test.go similarity index 98% rename from processors/baggage/processor_test.go rename to processors/baggage/baggagetrace/processor_test.go index dacf29a672c..3293ef2c731 100644 --- a/processors/baggage/processor_test.go +++ b/processors/baggage/baggagetrace/processor_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggage +package baggagetrace import ( "context" From 1a7949489320eaa661053204a16fe73520f712d0 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:01:04 -0700 Subject: [PATCH 09/20] more fixes Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- .github/dependabot.yml | 2 +- versions.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 79d9ab9a003..7d956abcb08 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -542,7 +542,7 @@ updates: interval: weekly day: sunday - package-ecosystem: gomod - directory: /processors/baggage + directory: /processors/baggage/baggagetrace labels: - dependencies - go diff --git a/versions.yaml b/versions.yaml index 08957fe95fe..c9dfe59984c 100644 --- a/versions.yaml +++ b/versions.yaml @@ -80,7 +80,7 @@ module-sets: experimental-processors: version: v0.0.1 modules: - - go.opentelemetry.io/contrib/processors/baggage + - go.opentelemetry.io/contrib/processors/baggage/baggagetrace excluded-modules: - go.opentelemetry.io/contrib/instrgen - go.opentelemetry.io/contrib/instrgen/driver From 9bd6d4e1368d49fa1bbd97c40c8ce71737c5290a Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:04:26 -0700 Subject: [PATCH 10/20] docs Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- processors/baggage/baggagetrace/processor.go | 15 +++++++++++---- processors/baggage/baggagetrace/processor_test.go | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/processors/baggage/baggagetrace/processor.go b/processors/baggage/baggagetrace/processor.go index a47c94875fd..2782ffd73e7 100644 --- a/processors/baggage/baggagetrace/processor.go +++ b/processors/baggage/baggagetrace/processor.go @@ -15,20 +15,27 @@ type SpanProcessor struct{} var _ trace.SpanProcessor = (*SpanProcessor)(nil) -// NewBaggageSpanProcessor returns a new SpanProcessor. +// New returns a new SpanProcessor. // // The Baggage span processor duplicates onto a span the attributes found // in Baggage in the parent context at the moment the span is started. -func NewBaggageSpanProcessor() trace.SpanProcessor { +func New() trace.SpanProcessor { return &SpanProcessor{} } +// OnStart is called when a span is started and adds span attributes for baggage contents. func (processor SpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) { for _, entry := range otelbaggage.FromContext(ctx).Members() { span.SetAttributes(attribute.String(entry.Key(), entry.Value())) } } -func (processor SpanProcessor) OnEnd(s trace.ReadOnlySpan) {} -func (processor SpanProcessor) Shutdown(context.Context) error { return nil } +// OnEnd is called when span is finished and is a no-op for this processor. +func (processor SpanProcessor) OnEnd(s trace.ReadOnlySpan) {} + +// Shutdown is called when the SDK shuts down and is a no-op for this processor. +func (processor SpanProcessor) Shutdown(context.Context) error { return nil } + +// ForceFlush exports all ended spans to the configured Exporter that have not yet +// been exported and is a no-op for this processor. func (processor SpanProcessor) ForceFlush(context.Context) error { return nil } diff --git a/processors/baggage/baggagetrace/processor_test.go b/processors/baggage/baggagetrace/processor_test.go index 3293ef2c731..3b50bcf3eac 100644 --- a/processors/baggage/baggagetrace/processor_test.go +++ b/processors/baggage/baggagetrace/processor_test.go @@ -45,7 +45,7 @@ func TestSpanProcessorAppendsBaggageAttributes(t *testing.T) { // create trace provider with baggage processor and test exporter exporter := NewTestExporter() tp := trace.NewTracerProvider( - trace.WithSpanProcessor(NewBaggageSpanProcessor()), + trace.WithSpanProcessor(New()), trace.WithSpanProcessor(trace.NewSimpleSpanProcessor(exporter)), ) From 5e10970b1123dcd5142b9f765385f4c3f45844eb Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:08:10 -0700 Subject: [PATCH 11/20] lint fixes Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- processors/baggage/baggagetrace/doc.go | 2 +- processors/baggage/baggagetrace/processor.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/processors/baggage/baggagetrace/doc.go b/processors/baggage/baggagetrace/doc.go index 66a58d3e191..0060b306b0c 100644 --- a/processors/baggage/baggagetrace/doc.go +++ b/processors/baggage/baggagetrace/doc.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -// package baggagetrace implements the baggage span processor which duplicates +// Package baggagetrace implements the baggage span processor which duplicates // onto a span the attributes found in Baggage in the parent context at // the moment the span is started. package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" diff --git a/processors/baggage/baggagetrace/processor.go b/processors/baggage/baggagetrace/processor.go index 2782ffd73e7..7207bb59706 100644 --- a/processors/baggage/baggagetrace/processor.go +++ b/processors/baggage/baggagetrace/processor.go @@ -11,6 +11,7 @@ import ( "go.opentelemetry.io/otel/sdk/trace" ) +// SpanProcessor is a processing pipeline for spans in the trace signal. type SpanProcessor struct{} var _ trace.SpanProcessor = (*SpanProcessor)(nil) From 2d8ed5d8c79bbed0ae1588ce5f91853ce31be34a Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:25:45 -0700 Subject: [PATCH 12/20] generate Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- processors/baggage/baggagetrace/doc.go | 2 +- processors/baggage/baggagetrace/processor.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processors/baggage/baggagetrace/doc.go b/processors/baggage/baggagetrace/doc.go index 0060b306b0c..d4ba212656e 100644 --- a/processors/baggage/baggagetrace/doc.go +++ b/processors/baggage/baggagetrace/doc.go @@ -4,4 +4,4 @@ // Package baggagetrace implements the baggage span processor which duplicates // onto a span the attributes found in Baggage in the parent context at // the moment the span is started. -package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" +package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage" diff --git a/processors/baggage/baggagetrace/processor.go b/processors/baggage/baggagetrace/processor.go index 7207bb59706..d3164a13f33 100644 --- a/processors/baggage/baggagetrace/processor.go +++ b/processors/baggage/baggagetrace/processor.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" +package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage" import ( "context" From e689203ff3e1ad9fd467be7b9fa6170046813c48 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Mon, 22 Apr 2024 07:04:43 -0700 Subject: [PATCH 13/20] Update CHANGELOG.md Co-authored-by: Damien Mathieu <42@dmathieu.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5dcf815035..b2f95df11c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) - `NewSDK` in `go.opentelemetry.io/contrib/config` now returns a configured SDK with a valid `MeterProvider`. (#4804) - The `go.opentelemetry.io/contrib/processors/baggage` module. - This module provides a Baggage Span Processor. (#5397) + This module provides a Baggage Span Processor. (#5404) ### Changed From 32a3bc463290c651bf0c5f243ee59f65365d6e10 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Mon, 22 Apr 2024 07:05:04 -0700 Subject: [PATCH 14/20] Update CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2f95df11c9..9219c51eaf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) - `NewSDK` in `go.opentelemetry.io/contrib/config` now returns a configured SDK with a valid `MeterProvider`. (#4804) -- The `go.opentelemetry.io/contrib/processors/baggage` module. - This module provides a Baggage Span Processor. (#5404) +- The `go.opentelemetry.io/contrib/processors/baggage` module. This module provides a Baggage Span Processor. (#5404) ### Changed From 262dda0d92baaecf5492a0a02a507e6906ed789a Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Mon, 22 Apr 2024 07:06:03 -0700 Subject: [PATCH 15/20] Update processors/baggage/baggagetrace/doc.go --- processors/baggage/baggagetrace/doc.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/processors/baggage/baggagetrace/doc.go b/processors/baggage/baggagetrace/doc.go index d4ba212656e..7ac1a41f413 100644 --- a/processors/baggage/baggagetrace/doc.go +++ b/processors/baggage/baggagetrace/doc.go @@ -1,7 +1,5 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -// Package baggagetrace implements the baggage span processor which duplicates -// onto a span the attributes found in Baggage in the parent context at -// the moment the span is started. +// Package baggagetrace implements a baggage span processor. package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage" From d7104141c70ebd91af03ec50ec325bd58cbb8901 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Mon, 22 Apr 2024 08:10:13 -0700 Subject: [PATCH 16/20] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert Pająk --- CHANGELOG.md | 2 +- CODEOWNERS | 2 +- processors/baggage/baggagetrace/doc.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9219c51eaf8..20d95f67c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) - `NewSDK` in `go.opentelemetry.io/contrib/config` now returns a configured SDK with a valid `MeterProvider`. (#4804) -- The `go.opentelemetry.io/contrib/processors/baggage` module. This module provides a Baggage Span Processor. (#5404) +- The `go.opentelemetry.io/contrib/processors/baggage/baggagetrace` module. This module provides a Baggage Span Processor. (#5404) ### Changed diff --git a/CODEOWNERS b/CODEOWNERS index 887d04e79f8..ab82b1e96e7 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -46,7 +46,7 @@ instrumentation/net/http/httptrace/otelhttptrace/ @open-te instrumentation/net/http/otelhttp/ @open-telemetry/go-approvers @Aneurysm9 @dmathieu instrumentation/runtime/ @open-telemetry/go-approvers @MadVikingGod -processors/baggage/ @open-telemetry/go-approvers @codeboten +processors/baggage/baggagetrace @open-telemetry/go-approvers @codeboten propagators/autoprop/ @open-telemetry/go-approvers @MrAlias propagators/aws/ @open-telemetry/go-approvers @Aneurysm9 diff --git a/processors/baggage/baggagetrace/doc.go b/processors/baggage/baggagetrace/doc.go index 7ac1a41f413..c2af10501d0 100644 --- a/processors/baggage/baggagetrace/doc.go +++ b/processors/baggage/baggagetrace/doc.go @@ -2,4 +2,4 @@ // SPDX-License-Identifier: Apache-2.0 // Package baggagetrace implements a baggage span processor. -package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage" +package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" From 85ecca9de76d95e4f8b73c025bfa2f9b197a07b2 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Mon, 22 Apr 2024 08:10:37 -0700 Subject: [PATCH 17/20] Update processors/baggage/baggagetrace/processor.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert Pająk --- processors/baggage/baggagetrace/processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processors/baggage/baggagetrace/processor.go b/processors/baggage/baggagetrace/processor.go index d3164a13f33..7207bb59706 100644 --- a/processors/baggage/baggagetrace/processor.go +++ b/processors/baggage/baggagetrace/processor.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage" +package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" import ( "context" From 2d837294d96af7075b741d75037361b278d90ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Mon, 22 Apr 2024 18:00:23 +0200 Subject: [PATCH 18/20] Apply suggestions from code review --- processors/baggage/baggagetrace/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processors/baggage/baggagetrace/go.mod b/processors/baggage/baggagetrace/go.mod index 893dea858be..92f72785eab 100644 --- a/processors/baggage/baggagetrace/go.mod +++ b/processors/baggage/baggagetrace/go.mod @@ -1,4 +1,4 @@ -module go.opentelemetry.io/contrib/processors/baggage +module go.opentelemetry.io/contrib/processors/baggage/baggagetrace go 1.21 From ad3171e7e3054b25a832e4cd539754030a1ed5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 25 Apr 2024 08:26:38 +0200 Subject: [PATCH 19/20] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c63ec7ce1..dae2c3d7a20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) +- The `go.opentelemetry.io/contrib/processors/baggage/baggagetrace` module. This module provides a Baggage Span Processor. (#5404) ## [1.26.0/0.51.0/0.20.0/0.6.0/0.1.0] - 2024-04-24 ### Added - `NewSDK` in `go.opentelemetry.io/contrib/config` now returns a configured SDK with a valid `MeterProvider`. (#4804) -- The `go.opentelemetry.io/contrib/processors/baggage/baggagetrace` module. This module provides a Baggage Span Processor. (#5404) ### Changed From 72110962a4fb0823ce42ad6b1f7e43c6c529d1fc Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Thu, 2 May 2024 14:06:07 +0200 Subject: [PATCH 20/20] Update CODEOWNERS Co-authored-by: Mike Goldsmith --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index ab82b1e96e7..197c0971bd8 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -46,7 +46,7 @@ instrumentation/net/http/httptrace/otelhttptrace/ @open-te instrumentation/net/http/otelhttp/ @open-telemetry/go-approvers @Aneurysm9 @dmathieu instrumentation/runtime/ @open-telemetry/go-approvers @MadVikingGod -processors/baggage/baggagetrace @open-telemetry/go-approvers @codeboten +processors/baggage/baggagetrace @open-telemetry/go-approvers @codeboten @MikeGoldsmith propagators/autoprop/ @open-telemetry/go-approvers @MrAlias propagators/aws/ @open-telemetry/go-approvers @Aneurysm9