Skip to content

attribute: add SLICE type support#8166

Open
pellared wants to merge 13 commits intoopen-telemetry:mainfrom
pellared:add-slice
Open

attribute: add SLICE type support#8166
pellared wants to merge 13 commits intoopen-telemetry:mainfrom
pellared:add-slice

Conversation

@pellared
Copy link
Copy Markdown
Member

@pellared pellared commented Apr 9, 2026

Fixes #7934

$ 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/Len3/Value-20                    25297926                52.56 ns/op          144 B/op          1 allocs/op
BenchmarkSlice/Len3/KeyValue-20                 21315132                55.97 ns/op          144 B/op          1 allocs/op
BenchmarkSlice/Len3/AsSlice-20                  24214248                50.03 ns/op          144 B/op          1 allocs/op
BenchmarkSlice/Len3/String-20                   14148270                86.48 ns/op           48 B/op          1 allocs/op
BenchmarkSlice/Len3/Emit-20                     13605388                85.18 ns/op           48 B/op          1 allocs/op
BenchmarkSlice/Len5Nested/Value-20              16086171                71.30 ns/op          240 B/op          1 allocs/op
BenchmarkSlice/Len5Nested/KeyValue-20           15547844                75.81 ns/op          240 B/op          1 allocs/op
BenchmarkSlice/Len5Nested/AsSlice-20            17806996                66.16 ns/op          240 B/op          1 allocs/op
BenchmarkSlice/Len5Nested/String-20              7409064               165.2 ns/op            64 B/op          1 allocs/op
BenchmarkSlice/Len5Nested/Emit-20                7666302               161.0 ns/op            64 B/op          1 allocs/op
PASS
ok      go.opentelemetry.io/otel/attribute      12.980s

@pellared pellared changed the title attribute: add SLICE type support [WIP] attribute: add SLICE type support Apr 9, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 95.82173% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.5%. Comparing base (56cd7ab) to head (22f4b51).

Files with missing lines Patch % Lines
trace/auto.go 0.0% 6 Missing ⚠️
attribute/value.go 98.7% 3 Missing and 1 partial ⚠️
...dk/metric/metricdata/metricdatatest/comparisons.go 0.0% 3 Missing ⚠️
attribute/hash.go 89.4% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #8166     +/-   ##
=======================================
+ Coverage   82.3%   82.5%   +0.1%     
=======================================
  Files        309     309             
  Lines      24238   24513    +275     
=======================================
+ Hits       19963   20227    +264     
- Misses      3898    3909     +11     
  Partials     377     377             
Files with missing lines Coverage Δ
attribute/key.go 100.0% <100.0%> (ø)
attribute/kv.go 100.0% <100.0%> (ø)
attribute/type_string.go 60.0% <ø> (ø)
log/keyvalue.go 97.1% <100.0%> (+<0.1%) ⬆️
attribute/hash.go 92.9% <89.4%> (+0.9%) ⬆️
...dk/metric/metricdata/metricdatatest/comparisons.go 96.9% <0.0%> (-0.6%) ⬇️
attribute/value.go 97.6% <98.7%> (+0.4%) ⬆️
trace/auto.go 95.6% <0.0%> (-1.7%) ⬇️

... and 3 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 changed the title [WIP] attribute: add SLICE type support attribute: add SLICE type support Apr 10, 2026
@pellared pellared marked this pull request as ready for review April 10, 2026 16:21
//
// If creating both a key and value at the same time, use the provided
// convenience function instead -- Slice(name, value).
func (k Key) Slice(v []Value) KeyValue {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be more ergonomic for this to be variadic?

// variadic
myKey.Slice(IntValue(1), IntValue(2), IntValue(3))
// vs slice
myKey.Slice([]Value(IntValue(1), IntValue(2), IntValue(3)))

Not sure if we would want to change func Slice(k string, v []Value) KeyValue to func Slice(k string, v ...Value) KeyValue` as well though... so maybe consistency is more important?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 to variadic

h = h.Uint64(byteSliceID)
h = h.String(kv.Value.stringly)
h = h.String(v.stringly)
case SLICE:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have benchmarks for hashing for slices?

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

3 participants