attribute: add String method for Value type#8142
Merged
pellared merged 13 commits intoopen-telemetry:mainfrom Apr 8, 2026
Merged
attribute: add String method for Value type#8142pellared merged 13 commits intoopen-telemetry:mainfrom
pellared merged 13 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8142 +/- ##
=======================================
+ Coverage 81.8% 82.0% +0.2%
=======================================
Files 308 308
Lines 23802 24057 +255
=======================================
+ Hits 19480 19741 +261
+ Misses 3944 3939 -5
+ Partials 378 377 -1
🚀 New features to boost your workflow:
|
Member
Author
|
CC @bboreham |
dashpole
reviewed
Apr 7, 2026
dashpole
reviewed
Apr 7, 2026
MrAlias
approved these changes
Apr 7, 2026
dashpole
approved these changes
Apr 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a String() method to attribute.Value so values print in a human-readable form consistent with the OpenTelemetry AnyValue (non-OTLP) string representation, with an allocation-conscious implementation and accompanying tests/benchmarks.
Changes:
- Implement
Value.String()with spec-aligned formatting for scalars and JSON-array formatting for slice types (with fast paths for small fixed arrays). - Inline JSON string escaping for string-slice formatting to avoid
encoding/jsonallocations/reflection. - Add unit tests and benchmarks covering the new
String()behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| CHANGELOG.md | Documents the addition of Value.String() in the “Added” section. |
| attribute/value.go | Adds Value.String() and supporting formatters (including inlined JSON-string escaping). |
| attribute/value_test.go | Adds comprehensive tests for Value.String() across types and edge cases. |
| attribute/benchmark_test.go | Adds String() benchmarks alongside existing Emit() benchmarks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dmathieu
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Towards #7810
Fixes #8143
String representation follows: https://opentelemetry.io/docs/specs/otel/common/#anyvalue-representation-for-non-otlp-protocols
This uses optimizations like #8039 and we inline the JSON-array/string encoding logic so we avoid the extra allocations and reflection overhead of marshaling through encoding/json (the code is inlined here not to reimplement JSON broadly, but to provide a spec-specific, allocation-conscious formatter for a constrained data model).
Benchmarks of both
StringandEmit(that is going to be deprecated) showcase thatStringis even more efficient.