Skip to content

[DO NOT MERGE] [WIP] attribute: add SLICE Type#7944

Draft
pellared wants to merge 13 commits intoopen-telemetry:mainfrom
pellared:attr-array
Draft

[DO NOT MERGE] [WIP] attribute: add SLICE Type#7944
pellared wants to merge 13 commits intoopen-telemetry:mainfrom
pellared:attr-array

Conversation

@pellared
Copy link
Member

@pellared pellared commented Feb 23, 2026

Caution

This should not be merged before we have a v1.41.0 release.

Fixes #7934

Prototype PR: #6809

I decided to print the slice values in Emit implementation in a similar way to the other homogeneous slice values that is based on JSON.

$ go test -run=^$ -bench=BenchmarkSlice
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/attribute
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkSlice/Value-20                  6015592               235.7 ns/op           288 B/op             2 allocs/op
BenchmarkSlice/KeyValue-20               3891439               288.6 ns/op           288 B/op             2 allocs/op
BenchmarkSlice/AsSlice-20                9490549               119.2 ns/op           144 B/op             1 allocs/op
BenchmarkSlice/Emit-20                   5796704               249.9 ns/op           168 B/op             3 allocs/op

I also made a prototype for efficient (not safe) retrieval of the slice value (mainly for the SDK): #7949

@pellared pellared marked this pull request as ready for review February 23, 2026 17:23
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.4%. Comparing base (248da95) to head (dedc8f7).

Files with missing lines Patch % Lines
attribute/value.go 76.7% 1 Missing and 9 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #7944     +/-   ##
=======================================
- Coverage   81.7%   81.4%   -0.4%     
=======================================
  Files        304     304             
  Lines      23287   23366     +79     
=======================================
- Hits       19039   19031      -8     
- Misses      3862    3890     +28     
- Partials     386     445     +59     
Files with missing lines Coverage Δ
attribute/hash.go 90.3% <100.0%> (+1.2%) ⬆️
attribute/key.go 100.0% <100.0%> (ø)
attribute/kv.go 100.0% <100.0%> (ø)
attribute/type_string.go 60.0% <ø> (ø)
attribute/value.go 58.4% <76.7%> (-34.2%) ⬇️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pellared pellared marked this pull request as draft February 24, 2026 17:18
Comment on lines +85 to +90
h = h.Uint64(sliceID)
rv := reflect.ValueOf(kv.Value.slice)
for i := 0; i < rv.Len(); i++ {
v := rv.Index(i).Interface().(Value)
h = hashKV(h, KeyValue{Key: "", Value: v})
}
Copy link
Member Author

@pellared pellared Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dashpole, PTAL

I think that this is correct, but I prefer to double-check with you.

@pellared pellared marked this pull request as ready for review February 24, 2026 17:48
}
if val.Type() == STRING {
b.WriteRune('"') //nolint:revive // No need to check error for strings.Builder.
b.WriteString(val.Emit()) //nolint:revive // No need to check error for strings.Builder.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it contains "? The value would have to be escaped.

b.WriteString(val.Emit()) //nolint:revive // No need to check error for strings.Builder.
b.WriteRune('"') //nolint:revive // No need to check error for strings.Builder.
} else {
b.WriteString(val.Emit()) //nolint:revive // No need to check error for strings.Builder.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a FLOAT64 contains NaN, +Inf, -Inf?

@pellared pellared marked this pull request as draft February 25, 2026 14:30
@pellared pellared changed the title [DO NOT MERGE] attribute: add SLICE Type [DO NOT MERGE] [WIP] attribute: add SLICE Type Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

attribute: Add SLICE type

1 participant