Skip to content

Commit 8c497e3

Browse files
Support maps and heterogeneous arrays as attribute values
Resolves open-telemetry#376 Use cases where this is necessary or useful: 1. Specify more than one resource in the telemetry: open-telemetry#579 2. Data coming from external source, e.g. AWS Metadata: open-telemetry#596 (comment) or open-telemetry#376 (comment) 3. Capturing HTTP headers: open-telemetry#376 (comment) 4. Structured stack traces: open-telemetry#2841 5. Payloads as attributes: open-telemetry/oteps#219 (comment) This is a draft PR to see what the change looks like. If this PR is merged it will be nice to follow it up with: - A standard way of flattening maps and nested objects when converting from OTLP to formats that don't support maps/nested objects. - Recommendations for semantic conventions to use/not use complex objects.
1 parent 6d1c567 commit 8c497e3

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ release.
3737
- Clarify that attribute keys are case-sensitive.
3838
([#3784](https://github.com/open-telemetry/opentelemetry-specification/pull/3784))
3939

40+
- Support maps and heterogeneous arrays as attribute values
41+
([#2888](https://github.com/open-telemetry/opentelemetry-specification/pull/2888))
42+
4043
### Supplementary Guidelines
4144

4245
## v1.28.0 (2023-12-07)

spec-compliance-matrix.md

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ formats is required. Implementing more than one format is optional.
215215
| A metric Producer accepts an optional metric Filter | | | | | | | | | | | | |
216216
| The metric Reader implementation supports registering metric Filter and passing them its registered metric Producers | | | | | | | | | | | | |
217217
| The metric SDK's metric Producer implementations uses the metric Filter | | | | | | | | | | | | |
218+
| Non-homogeneous arrays and maps (including nested) | | | | | | | | | | | | |
218219

219220
## Logs
220221

@@ -242,6 +243,7 @@ Disclaimer: this list of features is still a work in progress, please refer to t
242243
| Feature | Optional | Go | Java | JS | Python | Ruby | Erlang | PHP | Rust | C++ | .NET | Swift |
243244
|---------------------------------------------------------------------------------------------------------------------------------------------|----------|----|------|----|--------|------|--------|-----|------|-----|------|-------|
244245
| Create from Attributes | | + | + | + | + | + | + | + | + | + | + | + |
246+
| Non-homogeneous arrays and maps (including nested) for attribute values | | | | | | | | | | | | |
245247
| Create empty | | + | + | + | + | + | + | + | + | + | + | + |
246248
| [Merge (v2)](specification/resource/sdk.md#merge) | | + | + | | + | + | + | + | + | + | + | |
247249
| Retrieve attributes | | + | + | + | + | + | + | + | + | + | + | + |

specification/common/README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ An `Attribute` is a key-value pair, which MUST have the following properties:
2929

3030
- The attribute key MUST be a non-`null` and non-empty string.
3131
- Case sensitivity of keys is preserved. Keys that differ in casing are treated as distinct keys.
32-
- The attribute value is either:
32+
- The attribute value can be of `any` type, where any is defined as one of the following:
3333
- A primitive type: string, boolean, double precision floating point (IEEE 754-1985) or signed 64 bit integer.
34-
- An array of primitive type values. The array MUST be homogeneous,
35-
i.e., it MUST NOT contain values of different types.
34+
- A homogeneous array of values of primitive type [before 1.29.0].
35+
- An array of `any` values [since 1.29.0].
36+
- A key/value map, where key is string and value is `any` value [since 1.29.0].
3637

37-
For protocols that do not natively support non-string values, non-string values SHOULD be represented as JSON-encoded strings. For example, the expression `int64(100)` will be encoded as `100`, `float64(1.5)` will be encoded as `1.5`, and an empty array of any type will be encoded as `[]`.
38+
Complex attribute types (such as homogenous arrays, arrays of any, and maps) SHOULD be
39+
used sparingly, in situations where their use minimizes manipulation of the data’s
40+
original structure.
41+
42+
When exporting to protocols that do not natively support a particular non-string
43+
value type the value should be converted to a string JSON-encoding of the value.
44+
45+
For example, the expression `int64(100)` will be encoded as `100`, `float64(1.5)` will
46+
be encoded as `1.5`, and an empty array of any type will be encoded as `[]`.
3847

3948
Attribute values expressing a numerical value of zero, an empty string, or an
4049
empty array are considered meaningful and MUST be stored and passed on to

specification/trace/sdk_exporters/jaeger.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ OpenTelemetry Span `Attribute`(s) MUST be reported as `tags` to Jaeger.
138138

139139
Primitive types MUST be represented by the corresponding types of Jaeger tags.
140140

141-
Array values MUST be serialized to string like a JSON list as mentioned in
142-
[semantic conventions](../../overview.md#semantic-conventions).
141+
Array and map values MUST be serialized to a JSON and recorded as a tag of string type
142+
as mentioned in [attribute value definition](../../common/README.md#attribute).
143143

144144
### Links
145145

specification/trace/sdk_exporters/zipkin.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ document maps to the strongly-typed fields of Zipkin spans.
131131
Primitive types MUST be converted to string using en-US culture settings.
132132
Boolean values MUST use lower case strings `"true"` and `"false"`.
133133

134-
Array values MUST be serialized to string like a JSON list as mentioned in
135-
[semantic conventions](../../overview.md#semantic-conventions).
134+
Array and map values MUST be serialized to a JSON and recorded as a tag of string type
135+
as mentioned in [attribute value definition](../../common/README.md#attribute).
136136

137137
TBD: add examples
138138

0 commit comments

Comments
 (0)