Skip to content

Commit f638013

Browse files
toumorokoshiSergey Kanzhelev
authored and
Sergey Kanzhelev
committed
Modifying resources specification to describe capabilities (open-telemetry#196)
A focus of the specification on the capabilities that should be afforded rather than strict requirements around implementation enable better flexibility to ensure libraries are compatible with the idioms of their corresponding languages. This commit incorporates feedback discussed in open-telemetry#191.
1 parent be59f41 commit f638013

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

specification/api-resources.md

+44-37
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Resources API
22

3-
[Resource](../terminology.md#resources) represents the entity producing
3+
A [Resource](../terminology.md#resources) represents the entity producing
44
telemetry. The primary purpose of resources as a first-class concept in the API
55
is decoupling of discovery of resource information from exporters. This allows
66
for independent development and easy customization for users that need to
7-
integrate with closed source environments. API MUST allow creation of
8-
`Resources` and associating them with telemetry.
7+
integrate with closed source environments. API MUST allow for creation of
8+
`Resources` and for associating them with telemetry.
99

10-
When used with distributed tracing resource can be associated with the
10+
When used with distributed tracing, a resource can be associated with the
1111
[Tracer](tracing-api.md#tracer) or individual
1212
[SpanData](tracing-api.md#spandata). When associated with `Tracer`, all `Span`s
1313
produced by this `Tracer` will automatically be associated with this `Resource`.
@@ -23,54 +23,61 @@ TODO: notes how Resources API is extended when using `SDK`. https://github.com/o
2323

2424
## Resource creation
2525

26-
API defines two ways to instantiate an instance of `Resource`. First, by
27-
providing a collection of labels - method [Create](#create). The typical use of
28-
this method is by creating resource from the list of labels taken from
29-
environment variables, metadata API call response, or other sources.
26+
The API interface must support two ways to instantiate new resources. Those
27+
are:
3028

31-
Second, by merging two `Resource`s into a new one. The method [Merge](#merge) is
32-
used when a `Resource` is constructed from multiple sources - metadata API call
33-
for the host and environment variables for the container. So a single `Resource`
34-
will contain labels for both.
29+
### Create
3530

36-
Lastly, it is a good practice for API to allow easy creation of a default or
37-
empty `Resource`.
31+
The interface MUST provide a way to create a new resource, from a collection
32+
of labels. Examples include a factory method or a constructor for
33+
a resource object. A factory method is recommended to enable support for
34+
cached objects.
3835

39-
Note that the OpenTelemetry project documents certain ["standard
40-
labels"](../semantic-conventions.md) that have prescribed semantic meanings.
36+
Required parameters:
4137

42-
### Create
38+
- a collection of name/value labels, where name and value are both strings.
4339

44-
Creates a new `Resource` out of the collection of labels. This is a static
45-
method.
40+
### Merge
4641

47-
Required parameter:
42+
The interface MUST provide a way for a primary resource to merge with a
43+
secondary resource, resulting in the creation of a brand new resource. The
44+
original resources should be unmodified.
4845

49-
Collection of name/value labels where both name and value are strings.
46+
This is utilized for merging of resources whose labels come from different
47+
sources, such as environment variables, or metadata extracted from the host or
48+
container.
5049

51-
### Merge
50+
Already set labels MUST NOT be overwritten unless they are the empty string.
5251

53-
Creates a new `Resource` that is a combination of labels of two `Resource`s. For
54-
example, from two `Resource`s - one representing the host and one representing a
55-
container, resulting `Resource` will describe both.
52+
Label key namespacing SHOULD be used to prevent collisions across different
53+
resource detection steps.
5654

57-
Already set labels MUST NOT be overwritten unless they are empty string. Label
58-
key namespacing SHOULD be used to prevent collisions across different resource
59-
detection steps.
55+
Required parameters:
6056

57+
- the primary resource whose labels takes precedence.
58+
- the secondary resource whose labels will be merged.
6159

62-
Required parameter:
60+
### The empty resource
6361

64-
`Resource` to merge into the one, on which the method was called.
62+
It is recommended, but not required, to provide a way to quickly create an empty
63+
resource.
64+
65+
Note that the OpenTelemetry project documents certain ["standard
66+
labels"](../semantic-conventions.md) that have prescribed semantic meanings.
6567

6668
## Resource operations
6769

68-
API defines a resource class with a single getter for the list of labels
69-
associated with this resource. `Resource` object should be assumed immutable.
70+
In addition to resource creation, the following operations should be provided:
71+
72+
### Retrieve labels
73+
74+
The API should provide a way to retrieve a read only collection of labels
75+
associated with a resource. The labels should consist of the name and values,
76+
both of which should be strings.
7077

71-
### GetLabels
78+
There is no need to guarantee the order of the labels.
7279

73-
Returns the read only collection of labels associated with this resource. Each
74-
label is a string to string name value pair. The order of labels in collection
75-
is not significant. The typical use of labels collection is enumeration so the
76-
fast access to the label value by it's key is not a requirement.
80+
The most common operation when retrieving labels is to enumerate over them.
81+
As such, it is recommended to optimize the resulting collection for fast
82+
enumeration over other considerations such as a way to quickly retrieve a
83+
value for a label with a specific key.

0 commit comments

Comments
 (0)