Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processors/baggage: add baggage span processor #5404

Merged
merged 26 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9f17aed
processors/baggage: add baggage span processor
codeboten Apr 18, 2024
33e94b2
fix lint issues + dependabot generate
codeboten Apr 18, 2024
b65b129
apply review feedback
codeboten Apr 18, 2024
cfa0e23
more review feedback
codeboten Apr 18, 2024
8e648db
Update processors/baggage/processor_test.go
codeboten Apr 18, 2024
9ed5020
lint
codeboten Apr 18, 2024
fa28a2f
feedback from review
codeboten Apr 19, 2024
26a0d60
rename baggage -> baggagetrace
codeboten Apr 19, 2024
1a79494
more fixes
codeboten Apr 19, 2024
9bd6d4e
docs
codeboten Apr 19, 2024
5e10970
lint fixes
codeboten Apr 19, 2024
2d8ed5d
generate
codeboten Apr 19, 2024
e689203
Update CHANGELOG.md
codeboten Apr 22, 2024
32a3bc4
Update CHANGELOG.md
codeboten Apr 22, 2024
262dda0
Update processors/baggage/baggagetrace/doc.go
codeboten Apr 22, 2024
a75b628
Merge branch 'main' into codeboten/processor-baggage
pellared Apr 22, 2024
d710414
Apply suggestions from code review
codeboten Apr 22, 2024
85ecca9
Update processors/baggage/baggagetrace/processor.go
codeboten Apr 22, 2024
2d83729
Apply suggestions from code review
pellared Apr 22, 2024
a54abb1
Merge branch 'main' into codeboten/processor-baggage
pellared Apr 25, 2024
ad3171e
Update CHANGELOG.md
pellared Apr 25, 2024
55fad94
Merge branch 'main' into codeboten/processor-baggage
codeboten Apr 30, 2024
7211096
Update CODEOWNERS
dmathieu May 2, 2024
fa1d812
Merge branch 'main' into codeboten/processor-baggage
codeboten May 2, 2024
782cf2f
Merge branch 'main' into codeboten/processor-baggage
MadVikingGod May 6, 2024
407c7df
Merge branch 'main' into codeboten/processor-baggage
codeboten May 6, 2024
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
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,15 @@ updates:
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /processors/baggage/baggagetrace
labels:
- dependencies
- go
- Skip Changelog
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /propagators/autoprop
labels:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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

Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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/baggagetrace @open-telemetry/go-approvers @codeboten @MikeGoldsmith

propagators/autoprop/ @open-telemetry/go-approvers @MrAlias
propagators/aws/ @open-telemetry/go-approvers @Aneurysm9
propagators/b3/ @open-telemetry/go-approvers @pellared
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions processors/baggage/baggagetrace/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package baggagetrace implements a baggage span processor.
package baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace"
20 changes: 20 additions & 0 deletions processors/baggage/baggagetrace/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module go.opentelemetry.io/contrib/processors/baggage/baggagetrace

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
)
27 changes: 27 additions & 0 deletions processors/baggage/baggagetrace/go.sum
Original file line number Diff line number Diff line change
@@ -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=
42 changes: 42 additions & 0 deletions processors/baggage/baggagetrace/processor.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 baggagetrace // import "go.opentelemetry.io/contrib/processors/baggage/baggagetrace"

import (
"context"

"go.opentelemetry.io/otel/attribute"
otelbaggage "go.opentelemetry.io/otel/baggage"
"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)

// 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 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()))
}
}

// 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 }

Check warning on line 38 in processors/baggage/baggagetrace/processor.go

View check run for this annotation

Codecov / codecov/patch

processors/baggage/baggagetrace/processor.go#L38

Added line #L38 was not covered by tests

// 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 }

Check warning on line 42 in processors/baggage/baggagetrace/processor.go

View check run for this annotation

Codecov / codecov/patch

processors/baggage/baggagetrace/processor.go#L42

Added line #L42 was not covered by tests
62 changes: 62 additions & 0 deletions processors/baggage/baggagetrace/processor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package baggagetrace

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
otelbaggage "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 TestSpanProcessorAppendsBaggageAttributes(t *testing.T) {
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(context.Background(), suitcase)

// create trace provider with baggage processor and test exporter
exporter := NewTestExporter()
tp := trace.NewTracerProvider(
trace.WithSpanProcessor(New()),
trace.WithSpanProcessor(trace.NewSimpleSpanProcessor(exporter)),
)

// create tracer and start/end span
tracer := tp.Tracer("test")
_, span := tracer.Start(ctx, "test")
span.End()

assert.Len(t, exporter.spans, 1)
assert.Len(t, exporter.spans[0].Attributes(), 1)

want := []attribute.KeyValue{attribute.String("baggage.test", "baggage value")}
assert.Equal(t, want, exporter.spans[0].Attributes())
}
4 changes: 4 additions & 0 deletions versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ module-sets:
version: v0.1.0
modules:
- go.opentelemetry.io/contrib/bridges/otelslog
experimental-processors:
version: v0.0.1
modules:
- go.opentelemetry.io/contrib/processors/baggage/baggagetrace
excluded-modules:
- go.opentelemetry.io/contrib/instrgen
- go.opentelemetry.io/contrib/instrgen/driver
Expand Down