Skip to content

Commit 7cb952b

Browse files
committed
Merge branch 'main' into filter-bag-mem
2 parents bd14f79 + edcddd7 commit 7cb952b

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2323
- Use `c.FullPath()` method to set `http.route` attribute in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#5734)
2424
- The double setup in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace/example` that caused duplicate traces. (#5564)
2525
- Out-of-bounds panic in case of invalid span ID in `go.opentelemetry.io/contrib/propagators/b3`. (#5754)
26+
- Do not panic if a zero-value `SpanProcessor` is used from `go.opentelemetry.io/contrib/processors/baggage/baggagetrace`. (#5811)
2627

2728
### Deprecated
2829

@@ -47,7 +48,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
4748
- Update `go.opentelemetry.io/contrib/config` to latest released configuration schema which introduces breaking changes where `Attributes` is now a `map[string]interface{}`. (#5758)
4849
- Rename `BaggageKeyPredicate` to `Filter` in `go.opentelemetry.io/contrib/processors/baggage/baggagetrace`. (#5809)
4950
- Return `*SpanProcessor` from `"go.opentelemetry.io/contrib/processors/baggage/baggagetrace".New` instead of the `trace.SpanProcessor` interface. (#5810)
50-
- The `BaggageKeyPredicate` in `go.opentelemetry.io/contrib/processors/baggage/baggagetrace` now accepts a `baggage.Member` as a parameter instead of a string. (#5813)
51+
- The `Filter` in `go.opentelemetry.io/contrib/processors/baggage/baggagetrace` now accepts a `baggage.Member` as a parameter instead of a string. (#5813)
5152

5253
## [1.27.0/0.52.0/0.21.0/0.7.0/0.2.0] - 2024-05-21
5354

processors/baggage/baggagetrace/processor.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var _ trace.SpanProcessor = (*SpanProcessor)(nil)
3030
// The Baggage span processor duplicates onto a span the attributes found
3131
// in Baggage in the parent context at the moment the span is started.
3232
// The passed filter determines which baggage members are added to the span.
33+
//
34+
// If filter is nil, all baggage members will be added.
3335
func New(filter Filter) *SpanProcessor {
3436
return &SpanProcessor{
3537
filter: filter,
@@ -38,8 +40,13 @@ func New(filter Filter) *SpanProcessor {
3840

3941
// OnStart is called when a span is started and adds span attributes for baggage contents.
4042
func (processor SpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) {
43+
filter := processor.filter
44+
if filter == nil {
45+
filter = AllowAllMembers
46+
}
47+
4148
for _, member := range otelbaggage.FromContext(ctx).Members() {
42-
if processor.filter(member) {
49+
if filter(member) {
4350
span.SetAttributes(attribute.String(member.Key(), member.Value()))
4451
}
4552
}

processors/baggage/baggagetrace/processor_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314

1415
"go.opentelemetry.io/otel/attribute"
1516
otelbaggage "go.opentelemetry.io/otel/baggage"
1617
"go.opentelemetry.io/otel/sdk/trace"
18+
"go.opentelemetry.io/otel/sdk/trace/tracetest"
1719
)
1820

1921
var _ trace.SpanExporter = &testExporter{}
@@ -151,3 +153,28 @@ func addEntryToBaggage(t *testing.T, baggage otelbaggage.Baggage, key, value str
151153
require.NoError(t, err)
152154
return baggage
153155
}
156+
157+
func TestZeroSpanProcessorNoPanic(t *testing.T) {
158+
sp := new(SpanProcessor)
159+
160+
m, err := otelbaggage.NewMember("key", "val")
161+
require.NoError(t, err)
162+
b, err := otelbaggage.New(m)
163+
require.NoError(t, err)
164+
165+
ctx := otelbaggage.ContextWithBaggage(context.Background(), b)
166+
roS := (tracetest.SpanStub{}).Snapshot()
167+
rwS := rwSpan{}
168+
assert.NotPanics(t, func() {
169+
sp.OnStart(ctx, rwS)
170+
sp.OnEnd(roS)
171+
_ = sp.ForceFlush(ctx)
172+
_ = sp.Shutdown(ctx)
173+
})
174+
}
175+
176+
type rwSpan struct {
177+
trace.ReadWriteSpan
178+
}
179+
180+
func (s rwSpan) SetAttributes(kv ...attribute.KeyValue) {}

0 commit comments

Comments
 (0)