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

Do not alias baggage import #5812

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 2 deletions processors/baggage/baggagetrace/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"

"go.opentelemetry.io/otel/attribute"
otelbaggage "go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/sdk/trace"
)

Expand Down Expand Up @@ -37,7 +37,7 @@ func New(baggageKeyPredicate BaggageKeyPredicate) trace.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() {
for _, entry := range baggage.FromContext(ctx).Members() {
if processor.baggageKeyPredicate(entry.Key()) {
span.SetAttributes(attribute.String(entry.Key(), entry.Value()))
}
Expand Down
36 changes: 18 additions & 18 deletions processors/baggage/baggagetrace/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
otelbaggage "go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/sdk/trace"
)

Expand All @@ -35,9 +35,9 @@ func NewTestExporter() *testExporter {
}

func TestSpanProcessorAppendsAllBaggageAttributes(t *testing.T) {
baggage, _ := otelbaggage.New()
baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value")
ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage)
b, _ := baggage.New()
b = addEntryToBaggage(t, b, "baggage.test", "baggage value")
ctx := baggage.ContextWithBaggage(context.Background(), b)

// create trace provider with baggage processor and test exporter
exporter := NewTestExporter()
Expand All @@ -59,9 +59,9 @@ func TestSpanProcessorAppendsAllBaggageAttributes(t *testing.T) {
}

func TestSpanProcessorAppendsBaggageAttributesWithHaPrefixPredicate(t *testing.T) {
baggage, _ := otelbaggage.New()
baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value")
ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage)
b, _ := baggage.New()
b = addEntryToBaggage(t, b, "baggage.test", "baggage value")
ctx := baggage.ContextWithBaggage(context.Background(), b)

baggageKeyPredicate := func(key string) bool {
return strings.HasPrefix(key, "baggage.")
Expand All @@ -87,9 +87,9 @@ func TestSpanProcessorAppendsBaggageAttributesWithHaPrefixPredicate(t *testing.T
}

func TestSpanProcessorAppendsBaggageAttributesWithRegexPredicate(t *testing.T) {
baggage, _ := otelbaggage.New()
baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value")
ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage)
b, _ := baggage.New()
b = addEntryToBaggage(t, b, "baggage.test", "baggage value")
ctx := baggage.ContextWithBaggage(context.Background(), b)

expr := regexp.MustCompile(`^baggage\..*`)
baggageKeyPredicate := func(key string) bool {
Expand All @@ -116,10 +116,10 @@ func TestSpanProcessorAppendsBaggageAttributesWithRegexPredicate(t *testing.T) {
}

func TestOnlyAddsBaggageEntriesThatMatchPredicate(t *testing.T) {
baggage, _ := otelbaggage.New()
baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value")
baggage = addEntryToBaggage(t, baggage, "foo", "bar")
ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage)
b, _ := baggage.New()
b = addEntryToBaggage(t, b, "baggage.test", "baggage value")
b = addEntryToBaggage(t, b, "foo", "bar")
ctx := baggage.ContextWithBaggage(context.Background(), b)

baggageKeyPredicate := func(key string) bool {
return key == "baggage.test"
Expand All @@ -144,10 +144,10 @@ func TestOnlyAddsBaggageEntriesThatMatchPredicate(t *testing.T) {
require.Equal(t, want, exporter.spans[0].Attributes()[0])
}

func addEntryToBaggage(t *testing.T, baggage otelbaggage.Baggage, key, value string) otelbaggage.Baggage {
member, err := otelbaggage.NewMemberRaw(key, value)
func addEntryToBaggage(t *testing.T, b baggage.Baggage, key, value string) baggage.Baggage {
member, err := baggage.NewMemberRaw(key, value)
require.NoError(t, err)
baggage, err = baggage.SetMember(member)
b, err = b.SetMember(member)
require.NoError(t, err)
return baggage
return b
}