Skip to content

Commit d2665fd

Browse files
Centralize attributes definition (#722)
* Centralize attributes definition Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com> * Update specification/common/common.md Co-authored-by: Christian Neumüller <christian+github@neumueller.me> * Update specification/common/common.md Co-authored-by: Christian Neumüller <christian+github@neumueller.me> * Update specification/common/common.md Co-authored-by: Christian Neumüller <christian+github@neumueller.me> * Update specification/common/common.md Co-authored-by: Christian Neumüller <christian+github@neumueller.me> * Update specification/common/common.md Co-authored-by: Christian Neumüller <christian+github@neumueller.me> * Update specification/common/common.md Co-authored-by: Christian Neumüller <christian+github@neumueller.me> * Update specification/overview.md Co-authored-by: Christian Neumüller <christian+github@neumueller.me> Co-authored-by: Christian Neumüller <christian+github@neumueller.me>
1 parent 36a95cd commit d2665fd

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

specification/common/common.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Common specification concepts
2+
3+
<details>
4+
<summary>
5+
Table of Contents
6+
</summary>
7+
8+
- [Attributes](#attribute)
9+
10+
</details>
11+
12+
## Attributes
13+
14+
Attributes are a list of zero or more key-value pairs. An `Attribute` MUST have the following properties:
15+
16+
- The attribute key, which MUST be a non-`null` and non-empty string.
17+
- The attribute value, which is either:
18+
- A primitive type: string, boolean, double precision floating point (IEEE 754-1985) or signed 64 bit integer.
19+
- An array of primitive type values. The array MUST be homogeneous,
20+
i.e. it MUST NOT contain values of different types. For protocols that do
21+
not natively support array values such values SHOULD be represented as JSON strings.
22+
23+
`null` values within arrays MUST be preserved as-is (i.e., passed on to span
24+
processors / exporters as `null`). If exporters do not support exporting `null`
25+
values, they MAY replace those values by 0, `false`, or empty strings.
26+
This is required for map/dictionary structures represented as two arrays with
27+
indices that are kept in sync (e.g., two attributes `header_keys` and `header_values`,
28+
both containing an array of strings to represent a mapping
29+
`header_keys[i] -> header_values[i]`).

specification/overview.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,8 @@ Each **Span** encapsulates the following state:
5454

5555
- An operation name
5656
- A start and finish timestamp
57-
- A set of zero or more key:value **Attributes**. The keys must be strings. The
58-
values may be strings, bools, or numeric types.
59-
- A set of zero or more **Events**, each of which is itself a key:value map
60-
paired with a timestamp. The keys must be strings, though the values may be of
61-
the same types as Span **Attributes**.
57+
- [**Attributes**](./common/common.md#attributes): A list of key-value pairs.
58+
- A set of zero or more **Events**, each of which is itself a tuple (timestamp, name, [**Attributes**](./common/common.md#attributes)). The name must be strings.
6259
- Parent's **Span** identifier.
6360
- [**Links**](#links-between-spans) to zero or more causally-related **Spans**
6461
(via the **SpanContext** of those related **Spans**).
@@ -300,6 +297,4 @@ Span attributes.
300297
* [Metrics Conventions](metrics/semantic_conventions/README.md)
301298

302299
The type of the attribute SHOULD be specified in the semantic convention
303-
for that attribute. Array values are allowed for attributes. For
304-
protocols that do not natively support array values such values MUST be
305-
represented as JSON strings.
300+
for that attribute. See more details about [Attributes](./common/common.md#attributes).

specification/resource/sdk.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ The SDK must support two ways to instantiate new resources. Those are:
3030

3131
### Create
3232

33-
The interface MUST provide a way to create a new resource, from a collection of
34-
attributes. Examples include a factory method or a constructor for a resource
33+
The interface MUST provide a way to create a new resource, from [`Attributes`](../common/common.md#attributes).
34+
Examples include a factory method or a constructor for a resource
3535
object. A factory method is recommended to enable support for cached objects.
3636

3737
Required parameters:
3838

39-
- a collection of name/value attributes, where name is a string and value can be one
40-
of: string, int64, double, bool.
39+
- [`Attributes`](../common/common.md#attributes)
4140

4241
### Merge
4342

specification/trace/api.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ the entire operation and, optionally, one or more sub-spans for its sub-operatio
203203
- A [`SpanKind`](#spankind)
204204
- A start timestamp
205205
- An end timestamp
206-
- [`Attribute`s](#set-attributes), a collection of key-value pairs
206+
- [`Attributes`](../common/common.md#attributes)
207207
- A list of [`Link`s](#add-links) to other `Span`s
208208
- A list of timestamped [`Event`s](#add-events)
209209
- A [`Status`](#set-status).
@@ -282,8 +282,7 @@ The API MUST accept the following parameters:
282282
See [Determining the Parent Span from a Context](#determining-the-parent-span-from-a-context)
283283
for guidance on `Span` parenting from explicit and implicit `Context`s.
284284
- [`SpanKind`](#spankind), default to `SpanKind.Internal` if not specified.
285-
- `Attribute`s - A collection of key-value pairs, with the same semantics as
286-
the ones settable with [Span::SetAttributes](#set-attributes). Additionally,
285+
- [`Attributes`](../common/common.md#attributes). Additionally,
287286
these attributes may be used to make a sampling decision as noted in [sampling
288287
description](sdk.md#sampling). An empty collection will be assumed if
289288
not specified.
@@ -335,8 +334,7 @@ description](../overview.md#links-between-spans).
335334
A `Link` is defined by the following properties:
336335

337336
- (Required) `SpanContext` of the `Span` to link to.
338-
- (Optional) One or more `Attribute`s with the same restrictions as defined for
339-
[Span Attributes](#set-attributes).
337+
- (Optional) One or more `Attribute`s as defined [here](../).
340338

341339
The `Link` SHOULD be an immutable type.
342340

@@ -394,15 +392,7 @@ propagators.
394392

395393
#### Set Attributes
396394

397-
A `Span` MUST have the ability to set attributes associated with it.
398-
399-
An `Attribute` is defined by the following properties:
400-
401-
- (Required) The attribute key, which MUST be a non-`null` and non-empty string.
402-
- (Required) The attribute value, which is either:
403-
- A primitive type: string, boolean or numeric.
404-
- An array of primitive type values. The array MUST be homogeneous,
405-
i.e. it MUST NOT contain values of different types.
395+
A `Span` MUST have the ability to set [`Attributes`](../common/common.md#attributes) associated with it.
406396

407397
The Span interface MUST provide:
408398

@@ -421,14 +411,6 @@ that `SetAttribute` call had never been made.
421411
As an exception to this, if overwriting of values is supported, this results in
422412
clearing the previous value and dropping the attribute key from the set of attributes.
423413

424-
`null` values within arrays MUST be preserved as-is (i.e., passed on to span
425-
processors / exporters as `null`). If exporters do not support exporting `null`
426-
values, they MAY replace those values by 0, `false`, or empty strings.
427-
This is required for map/dictionary structures represented as two arrays with
428-
indices that are kept in sync (e.g., two attributes `header_keys` and `header_values`,
429-
both containing an array of strings to represent a mapping
430-
`header_keys[i] -> header_values[i]`).
431-
432414
Note that the OpenTelemetry project documents certain ["standard
433415
attributes"](semantic_conventions/README.md) that have prescribed semantic meanings.
434416

@@ -440,8 +422,7 @@ with the moment when they are added to the `Span`.
440422
An `Event` is defined by the following properties:
441423

442424
- (Required) Name of the event.
443-
- (Optional) One or more `Attribute`s with the same restrictions as defined for
444-
[Span Attributes](#set-attributes).
425+
- (Optional) [`Attributes`](../common/common.md#attributes).
445426
- (Optional) Timestamp for the event.
446427

447428
The `Event` SHOULD be an immutable type.

0 commit comments

Comments
 (0)