Skip to content

attribute: add SLICE type support#8166

Merged
pellared merged 23 commits intoopen-telemetry:mainfrom
pellared:add-slice
Apr 16, 2026
Merged

attribute: add SLICE type support#8166
pellared merged 23 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
$ go test -run=^$ -bench=BenchmarkHashKVs
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/attribute
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkHashKVs-20      1268742               940.5 ns/op             0 B/op          0 allocs/op
PASS
ok      go.opentelemetry.io/otel/attribute      1.198s

@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.96774% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.5%. Comparing base (bb6804e) to head (d6906e5).
⚠️ Report is 1 commits behind head on main.

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 94.4% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #8166     +/-   ##
=======================================
+ Coverage   82.3%   82.5%   +0.1%     
=======================================
  Files        310     310             
  Lines      24267   24555    +288     
=======================================
+ Hits       19990   20261    +271     
- Misses      3901    3916     +15     
- Partials     376     378      +2     
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 94.5% <94.4%> (+2.5%) ⬆️
...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
Comment thread attribute/key.go Outdated
Comment thread attribute/hash.go
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Overall, looks good.

I assume we're going to address the attribute limits and exporter support in a follow-up, right?

Comment thread attribute/hash.go
Comment thread attribute/hash_test.go
Comment thread attribute/value.go Outdated
@pellared
Copy link
Copy Markdown
Member Author

I assume we're going to address the attribute limits and exporter support in a follow-up, right?

Correct:

alliasgher added a commit to alliasgher/opentelemetry-go that referenced this pull request Apr 14, 2026
Replace reflect.ValueOf + reflection-based iteration with direct typed
slice access (asBoolSlice, asInt64Slice, asFloat64Slice, asStringSlice)
for BOOLSLICE, INT64SLICE, FLOAT64SLICE, and STRINGSLICE in hashKV.

This avoids the per-element reflection overhead — the same improvement
applied to the SLICE type in open-telemetry#8166.

Fixes open-telemetry#8200

Signed-off-by: alliasgher <alliasgher123@gmail.com>
@pellared
Copy link
Copy Markdown
Member Author

pellared commented Apr 14, 2026

I am going to create a separate PR for improving the speed execution of TestHashKVsEquality which even on my machine runs for almost 10s.

EDIT: My idea is to change the test so that it only checks if hashKVs generates unique hashes. I do not think we should also check the equality operators (this is a separate concern). I have an idea how to change the test from O(n^2) to O(n). Going to submit a PR tomorrow.
EDIT 2: PR #8204

pellared added a commit that referenced this pull request Apr 15, 2026
Unblocks #8166

Per
#8166 (comment)

## Why

This updates `TestHashKVsEquality` to avoid the quadratic pairwise
comparison that was causing slow runs and timeouts in CI.

Below are the results from my machine.

Old:

```
$ go test -run=TestHashKVs -count=1 
PASS
ok      go.opentelemetry.io/otel/attribute      2.063s
```

New:

```
$ go test -run=TestHashKVs -count=1 
PASS
ok      go.opentelemetry.io/otel/attribute      0.024s
```

Instead of collecting every generated testcase and comparing each hash
against every other hash, the test now checks uniqueness as each case is
generated by storing previously seen hashes in a map. Note that it also
does not use the equality operator of `KeyValue` to determine if the
hash should be equal or different.

## What 

- Rename the test from `TestHashKVsEquality` to `TestHashKVs`
- Replace the O(n^2) post-processing loop with an O(n) streaming
uniqueness check
- Simplify failure reporting by removing the dedicated `msg` helper

Side note: for me it also makes the test more readable (however, this is
opinionated).
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class support for heterogeneous SLICE attribute values (arrays of attribute.Value) across the attribute package and downstream conversions, aligning with the OTel AnyValue array concept.

Changes:

  • Introduce attribute.SLICE plus Slice/SliceValue constructors and Value.AsSlice()/string formatting support.
  • Propagate SLICE handling into trace auto-conversion, log attribute conversion, hashing, and metric test comparisons.
  • Add/extend unit tests, fuzz/bench coverage, and update changelog.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
trace/auto.go Convert attribute.SLICE into telemetry nested slice values.
sdk/metric/metricdata/metricdatatest/comparisons.go Extend attribute equality helper to handle SLICE.
log/keyvalue.go Convert attribute.SLICE into log SliceValue recursively.
log/keyvalue_test.go Add test coverage for SLICE conversion to log values.
log/keyvalue_bench_test.go Add benchmark case for SLICE conversion.
attribute/value.go Add SLICE type, constructors/accessors, formatting, and base64 writer helper.
attribute/value_test.go Add tests for SLICE value behavior, AsSlice, and string formatting.
attribute/type_string.go Regenerate Type.String() backing tables to include SLICE.
attribute/kv.go Add attribute.Slice convenience constructor.
attribute/key.go Add Key.Slice constructor.
attribute/kv_test.go Add constructor/validity/incorrect-cast tests for SLICE.
attribute/key_test.go Add Emit/String tests for SLICE formatting behavior.
attribute/hash.go Add hashing support for SLICE values (including nested).
attribute/hash_test.go Extend hash test generators + add SLICE fuzz/bench coverage.
attribute/benchmark_test.go Add slice benchmarks for construction/access/string/emit.
CHANGELOG.md Document new SLICE attribute type API additions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk/metric/metricdata/metricdatatest/comparisons.go
Comment thread attribute/value_test.go
@pellared pellared merged commit d13f8ec into open-telemetry:main Apr 16, 2026
34 checks passed
@pellared pellared deleted the add-slice branch April 16, 2026 10:38
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

5 participants