1
1
# Resources API
2
2
3
- [ Resource] ( ../terminology.md#resources ) represents the entity producing
3
+ A [ Resource] ( ../terminology.md#resources ) represents the entity producing
4
4
telemetry. The primary purpose of resources as a first-class concept in the API
5
5
is decoupling of discovery of resource information from exporters. This allows
6
6
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.
9
9
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
11
11
[ Tracer] ( tracing-api.md#tracer ) or individual
12
12
[ SpanData] ( tracing-api.md#spandata ) . When associated with ` Tracer ` , all ` Span ` s
13
13
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
23
23
24
24
## Resource creation
25
25
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:
30
28
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
35
30
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.
38
35
39
- Note that the OpenTelemetry project documents certain [ "standard
40
- labels"] ( ../semantic-conventions.md ) that have prescribed semantic meanings.
36
+ Required parameters:
41
37
42
- ### Create
38
+ - a collection of name/value labels, where name and value are both strings.
43
39
44
- Creates a new ` Resource ` out of the collection of labels. This is a static
45
- method.
40
+ ### Merge
46
41
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.
48
45
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.
50
49
51
- ### Merge
50
+ Already set labels MUST NOT be overwritten unless they are the empty string.
52
51
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.
56
54
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:
60
56
57
+ - the primary resource whose labels takes precedence.
58
+ - the secondary resource whose labels will be merged.
61
59
62
- Required parameter:
60
+ ### The empty resource
63
61
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.
65
67
66
68
## Resource operations
67
69
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.
70
77
71
- ### GetLabels
78
+ There is no need to guarantee the order of the labels.
72
79
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