Skip to content

Commit

Permalink
Do not alias baggage import (#5812)
Browse files Browse the repository at this point in the history
There are not package name conflicts. Use the exported package name from
`go.opentelemetry.io/otel/baggage`.
  • Loading branch information
MrAlias authored Jun 27, 2024
1 parent edcddd7 commit 1b5af49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
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 @@ -46,7 +46,7 @@ func (processor SpanProcessor) OnStart(ctx context.Context, span trace.ReadWrite
filter = AllowAllBaggageKeys
}

for _, entry := range otelbaggage.FromContext(ctx).Members() {
for _, entry := range baggage.FromContext(ctx).Members() {
if filter(entry.Key()) {
span.SetAttributes(attribute.String(entry.Key(), entry.Value()))
}
Expand Down
42 changes: 21 additions & 21 deletions processors/baggage/baggagetrace/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
)
Expand All @@ -37,9 +37,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 @@ -61,9 +61,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 @@ -89,9 +89,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 @@ -118,10 +118,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 @@ -146,23 +146,23 @@ 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
}

func TestZeroSpanProcessorNoPanic(t *testing.T) {
sp := new(SpanProcessor)

m, err := otelbaggage.NewMember("key", "val")
m, err := baggage.NewMember("key", "val")
require.NoError(t, err)
b, err := otelbaggage.New(m)
b, err := baggage.New(m)
require.NoError(t, err)

ctx := otelbaggage.ContextWithBaggage(context.Background(), b)
ctx := baggage.ContextWithBaggage(context.Background(), b)
roS := (tracetest.SpanStub{}).Snapshot()
rwS := rwSpan{}
assert.NotPanics(t, func() {
Expand Down

0 comments on commit 1b5af49

Please sign in to comment.