From 407667e7dd0f7f387ef3ac51847a501fc181e775 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 9 Jul 2024 10:57:16 -0700 Subject: [PATCH] Add TestSpanStartConfigAttributeMutability Follow up to #5567. Test the immutability of configured attributes. --- trace/config_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/trace/config_test.go b/trace/config_test.go index 6e1c7e0335b..9a613ace2c9 100644 --- a/trace/config_test.go +++ b/trace/config_test.go @@ -163,6 +163,19 @@ func TestNewSpanConfig(t *testing.T) { } } +func TestSpanStartConfigAttributeMutability(t *testing.T) { + a := attribute.String("a", "val") + b := attribute.String("b", "val") + attrs := []attribute.KeyValue{a, b} + conf := NewSpanStartConfig(WithAttributes(attrs...)) + + // Mutating passed arg should not change configured attributes. + attrs[0] = attribute.String("c", "val") + + want := SpanConfig{attributes: []attribute.KeyValue{a, b}} + assert.Equal(t, want, conf) +} + func TestEndSpanConfig(t *testing.T) { timestamp := time.Unix(0, 0)