Skip to content

[DO NOT MERGE] attribute: add BYTES type support#7948

Open
NesterovYehor wants to merge 7 commits intoopen-telemetry:mainfrom
NesterovYehor:feat/attribute-bytes-value
Open

[DO NOT MERGE] attribute: add BYTES type support#7948
NesterovYehor wants to merge 7 commits intoopen-telemetry:mainfrom
NesterovYehor:feat/attribute-bytes-value

Conversation

@NesterovYehor
Copy link
Contributor

@NesterovYehor NesterovYehor commented Feb 24, 2026

Caution

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

Fixes #7933

Add BYTES type to https://pkg.go.dev/go.opentelemetry.io/otel/attribute

  • Introduces BYTES type and byte
  • Adds Bytes / BytesValue constructors
  • Implements hashing support
  • Adds base64 representation in Emit()
  • Adds test coverage for constructors, hashing, and set equality
$  go test -run=^$ -bench='BenchmarkBytesValue|BenchmarkAsBytes' -benchmem
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/attribute/internal
cpu: Apple M1
BenchmarkBytesValue-8   	17996593	        66.35 ns/op	       6 B/op	       2 allocs/op
BenchmarkAsBytes-8      	47359774	        26.59 ns/op	       2 B/op	       1 allocs/op
PASS
ok  	go.opentelemetry.io/otel/attribute/internal	2.995s
$  go test -run=^$ -bench=BenchmarkBytes -benchmem
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/attribute
cpu: Apple M1
BenchmarkBytes/Value-8         	15589729	        69.47 ns/op	      32 B/op	       2 allocs/op
BenchmarkBytes/KeyValue-8      	16409461	        80.14 ns/op	      32 B/op	       2 allocs/op
BenchmarkBytes/AsBytes-8       	40278198	        29.09 ns/op	      16 B/op	       1 allocs/op
BenchmarkBytes/Emit-8          	22664637	        51.59 ns/op	      32 B/op	       2 allocs/op
PASS
ok  	go.opentelemetry.io/otel/attribute	5.180s

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 86.84211% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.7%. Comparing base (248da95) to head (95b2ce9).

Files with missing lines Patch % Lines
log/keyvalue.go 0.0% 3 Missing ⚠️
attribute/internal/attribute.go 83.3% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7948   +/-   ##
=====================================
  Coverage   81.7%   81.7%           
=====================================
  Files        304     304           
  Lines      23287   23325   +38     
=====================================
+ Hits       19039   19074   +35     
- Misses      3862    3865    +3     
  Partials     386     386           
Files with missing lines Coverage Δ
attribute/hash.go 90.1% <100.0%> (+1.0%) ⬆️
attribute/key.go 100.0% <100.0%> (ø)
attribute/kv.go 100.0% <100.0%> (ø)
attribute/type_string.go 60.0% <ø> (ø)
attribute/value.go 93.2% <100.0%> (+0.6%) ⬆️
attribute/internal/attribute.go 83.3% <83.3%> (ø)
log/keyvalue.go 95.6% <0.0%> (-1.5%) ⬇️

... and 1 file with indirect coverage changes

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

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Overall LGTM. I left a few comments.
Please also add the benchmark results for ``BenchmarkBytes` in the PR description.

@pellared pellared added this to the v1.42.0 milestone Feb 24, 2026
@pellared pellared changed the title attribute: add BYTES type support [DO NOT MERGE] attribute: add BYTES type support Feb 24, 2026
@pellared pellared moved this from Todo to In Progress in Go: Logs (GA) Feb 24, 2026
@NesterovYehor NesterovYehor force-pushed the feat/attribute-bytes-value branch from 87ff3a1 to 95b2ce9 Compare February 24, 2026 22:27
@pellared pellared changed the title [DO NOT MERGE] attribute: add BYTES type support attribute: add BYTES type support Feb 25, 2026
@pellared pellared changed the title attribute: add BYTES type support [DO NOT MERGE] attribute: add BYTES type support Feb 25, 2026
@pellared
Copy link
Member

pellared commented Feb 25, 2026

@NesterovYehor

We would also need to comply with SDK attribute value limits https://opentelemetry.io/docs/specs/otel/common/#anyvalue

if it is a byte array, if its length exceeds that limit (counting each byte as 1), SDKs MUST truncate that value, so that its length is at most equal to the limit,

I propose to do this in a separate PR and also track it in a separate issue. The important thing is that both PRs would need to be shipped in the same release. If you want you can already start working it in a separate branch / draft PR

EDIT: I created #7954

@pellared pellared modified the milestones: v1.42.0, v1.41.0 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

Status: In Progress

Development

Successfully merging this pull request may close these issues.

attribute: Add BYTES type

2 participants