@@ -8,13 +8,67 @@ Table of Contents:
8
8
9
9
* [ Guidelines for instrumentation library
10
10
authors] ( #guidelines-for-instrumentation-library-authors )
11
+ * [ Instrument selection] ( #instrument-selection )
12
+ * [ Semantic convention] ( #semantic-convention )
11
13
* [ Guidelines for SDK authors] ( #guidelines-for-sdk-authors )
12
14
* [ Aggregation temporality] ( #aggregation-temporality )
13
15
* [ Memory management] ( #memory-management )
14
16
15
17
## Guidelines for instrumentation library authors
16
18
17
- TBD
19
+ ### Instrument selection
20
+
21
+ The [ Instruments] ( ./api.md#instrument ) are part of the [ Metrics API] ( ./api.md ) .
22
+ They allow [ Measurements] ( ./api.md#measurement ) to be recorded
23
+ [ synchronously] ( ./api.md#synchronous-instrument ) or
24
+ [ asynchronously] ( ./api.md#asynchronous-instrument ) .
25
+
26
+ Choosing the correct instrument is important, because:
27
+
28
+ * It helps the library to achieve better efficiency. For example, if we want to
29
+ report room temperature to [ Prometheus] ( https://prometheus.io ) , we want to
30
+ consider using an [ Asynchronous Gauge] ( ./api.md#asynchronous-gauge ) rather
31
+ than periodically poll the sensor, so that we only access the sensor when
32
+ scraping happened.
33
+ * It makes the consumption easier for the user of the library. For example, if
34
+ we want to report HTTP server request latency, we want to consider a
35
+ [ Histogram] ( ./api.md#histogram ) , so most of the users can get a reasonable
36
+ experience (e.g. default buckets, min/max) by simply enabling the metrics
37
+ stream, rather than doing extra configurations.
38
+ * It generates clarity to the semantic of the metrics stream, so the consumers
39
+ have better understanding of the results. For example, if we want to report
40
+ the process heap size, by using an [ Asynchronous
41
+ UpDownCounter] ( ./api.md#asynchronous-updowncounter ) rather than an
42
+ [ Asynchronous Gauge] ( ./api.md#asynchronous-gauge ) , we've made it explicit that
43
+ the consumer can add up the numbers across all processes to get the "total
44
+ heap size".
45
+
46
+ Here is one way of choosing the correct instrument:
47
+
48
+ * I want to ** count** something (by recording a delta value):
49
+ * If the value is monotonically increasing (the delta value is always
50
+ non-negative) - use a [ Counter] ( ./api.md#counter ) .
51
+ * If the value is NOT monotonically increasing (the delta value can be
52
+ positive, negative or zero) - use an
53
+ [ UpDownCounter] ( ./api.md#updowncounter ) .
54
+ * I want to ** record** or ** time** something, and the ** statistics** about this
55
+ thing are likely to be meaningful - use a [ Histogram] ( ./api.md#histogram ) .
56
+ * I want to ** measure** something (by reporting an absolute value):
57
+ * If it makes NO sense to add up the values across different dimensions, use
58
+ an [ Asynchronous Gauge] ( ./api.md#asynchronous-gauge ) .
59
+ * If it makes sense to add up the values across different dimensions:
60
+ * If the value is monotonically increasing - use an [ Asynchronous
61
+ Counter] ( ./api.md#asynchronous-counter ) .
62
+ * If the value is NOT monotonically increasing - use an [ Asynchronous
63
+ UpDownCounter] ( ./api.md#asynchronous-updowncounter ) .
64
+
65
+ ### Semantic convention
66
+
67
+ Once you decided [ which instrument(s) to be used] ( #instrument-selection ) , you
68
+ will need to decide the names for the instruments and attributes.
69
+
70
+ It is highly recommended that you align with the `OpenTelemetry Semantic
71
+ Conventions`, rather than inventing your own semantics.
18
72
19
73
## Guidelines for SDK authors
20
74
0 commit comments