From 1b5af498b2d8765ad8c48f1ccf5f73ebc7e2ffd3 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Thu, 27 Jun 2024 14:20:14 -0700 Subject: [PATCH] Do not alias baggage import (#5812) There are not package name conflicts. Use the exported package name from `go.opentelemetry.io/otel/baggage`. --- processors/baggage/baggagetrace/processor.go | 4 +- .../baggage/baggagetrace/processor_test.go | 42 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/processors/baggage/baggagetrace/processor.go b/processors/baggage/baggagetrace/processor.go index 0ed50064de9..c899e7bda6e 100644 --- a/processors/baggage/baggagetrace/processor.go +++ b/processors/baggage/baggagetrace/processor.go @@ -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" ) @@ -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())) } diff --git a/processors/baggage/baggagetrace/processor_test.go b/processors/baggage/baggagetrace/processor_test.go index d4ee0ca3200..f39e6d4f771 100644 --- a/processors/baggage/baggagetrace/processor_test.go +++ b/processors/baggage/baggagetrace/processor_test.go @@ -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" ) @@ -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() @@ -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.") @@ -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 { @@ -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" @@ -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() {