Skip to content

Commit adbab30

Browse files
authored
Add suggested string representation of complex attributes for non-OTLP protocols (#4848)
I think the only concrete impact this has in the specification is for the Prometheus exporter. It could apply to the Zipkin exporter but that's been deprecated, so I think it's up to language implementations if they want to update their Zipkin exporter to emit complex attributes or not.
1 parent a309502 commit adbab30

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ release.
3131

3232
### Entities
3333

34+
### Common
35+
36+
- Add string representation guidance for complex attribute value types (byte arrays,
37+
empty values, arrays, and maps) for non-OTLP protocols.
38+
([#4485](https://github.com/open-telemetry/opentelemetry-specification/pull/4485))
39+
3440
### OpenTelemetry Protocol
3541

3642
### Compatibility

specification/common/README.md

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ path_base_for_github_subdir:
1717

1818
- [AnyValue](#anyvalue)
1919
* [map](#mapstring-anyvalue)
20+
* [AnyValue representation for non-OTLP protocols](#anyvalue-representation-for-non-otlp-protocols)
21+
+ [Strings](#strings)
22+
+ [Booleans](#booleans)
23+
+ [Integers](#integers)
24+
+ [Floating Point Numbers](#floating-point-numbers)
25+
+ [Byte Arrays](#byte-arrays)
26+
+ [Empty Values](#empty-values)
27+
+ [Arrays](#arrays)
28+
+ [Maps](#maps)
2029
- [Attribute](#attribute)
2130
* [Attribute Collections](#attribute-collections)
2231
- [Attribute Limits](#attribute-limits)
@@ -47,11 +56,6 @@ allows to represent an equivalent of a JSON object).
4756
APIs SHOULD be documented in a way to communicate to users that using array and
4857
map values may carry higher performance overhead compared to primitive values.
4958

50-
For protocols that do not natively support some of the value types, corresponding values
51-
SHOULD be represented as JSON-encoded strings. For example, the expression
52-
`int64(100)` will be encoded as `100`, `float64(1.5)` will be encoded as `1.5`,
53-
and an empty array of any type will be encoded as `[]`.
54-
5559
AnyValues expressing an empty value, a numerical value of zero, an empty string,
5660
or an empty array are considered meaningful and MUST be stored and passed on to
5761
processors / exporters.
@@ -93,6 +97,85 @@ Maps are equal when they contain the same key-value pairs,
9397
irrespective of the order in which those elements appear
9498
(unordered collection equality).
9599

100+
### AnyValue representation for non-OTLP protocols
101+
102+
For protocols that do not natively support some of the AnyValue types,
103+
those values SHOULD be represented as strings following the encoding rules below.
104+
105+
> [!NOTE]
106+
> This string representation is lossy. Type information is lost as all
107+
> values are converted to strings, and precision loss may occur for numeric values
108+
> (particularly for floating point numbers and large integers that exceed the
109+
> precision capabilities of the receiving system's string-to-number conversion).
110+
111+
#### Strings
112+
113+
Strings SHOULD be represented as-is without any additional encoding.
114+
They SHOULD NOT be encoded as JSON strings (with explicit surrounding quotes).
115+
116+
Examples: `hello world`, (the empty string)
117+
118+
#### Booleans
119+
120+
Booleans SHOULD be represented as
121+
[JSON booleans](https://datatracker.ietf.org/doc/html/rfc8259#section-3).
122+
123+
Examples: `true`, `false`
124+
125+
#### Integers
126+
127+
Integers SHOULD be represented as
128+
[JSON numbers](https://datatracker.ietf.org/doc/html/rfc8259#section-6).
129+
130+
Examples: `42`, `-123`
131+
132+
#### Floating Point Numbers
133+
134+
Floating point numbers SHOULD be represented as
135+
[JSON numbers](https://datatracker.ietf.org/doc/html/rfc8259#section-6).
136+
137+
The special floating point values NaN and Infinity SHOULD be represented as
138+
`NaN`, `Infinity`, and `-Infinity`.
139+
They SHOULD NOT be encoded as JSON strings (with explicit surrounding quotes).
140+
141+
Examples: `3.14159`, `1.23e10`, `NaN`, `Infinity`, `-Infinity`
142+
143+
#### Byte Arrays
144+
145+
Byte arrays SHOULD be [Base64-encoded](https://datatracker.ietf.org/doc/html/rfc4648#section-4).
146+
They SHOULD NOT be encoded as JSON strings (with explicit surrounding quotes).
147+
148+
Example: `aGVsbG8gd29ybGQ=`
149+
150+
#### Empty Values
151+
152+
Empty values SHOULD be represented as the empty string.
153+
They SHOULD NOT be encoded as a JSON string (with explicit surrounding quotes).
154+
155+
#### Arrays
156+
157+
Arrays, except for byte arrays, SHOULD be represented as JSON arrays.
158+
159+
Nested byte arrays SHOULD be represented as
160+
[Base64-encoded](https://datatracker.ietf.org/doc/html/rfc4648#section-4) JSON strings.
161+
Nested empty values SHOULD be represented as JSON null.
162+
The special floating point values NaN and Infinity SHOULD be represented as
163+
JSON strings `"NaN"`, `"Infinity"`, and `"-Infinity"`.
164+
165+
Examples: `[]`, `[1, "-Infinity", "a", true, {"nested": "aGVsbG8gd29ybGQ="}]`
166+
167+
#### Maps
168+
169+
Maps SHOULD be represented as JSON objects.
170+
171+
Nested byte arrays SHOULD be represented as
172+
[Base64-encoded](https://datatracker.ietf.org/doc/html/rfc4648#section-4) JSON strings.
173+
Nested empty values SHOULD be represented as JSON null.
174+
The special floating point values NaN and Infinity SHOULD be represented as
175+
JSON strings `"NaN"`, `"Infinity"`, and `"-Infinity"`.
176+
177+
Examples: `{}`, `{"a": "-Infinity", "b": 2, "c": [3, null]}`
178+
96179
## Attribute
97180

98181
<a id="attributes"></a>

0 commit comments

Comments
 (0)