Skip to content

Commit 9ceb9fa

Browse files
reyangjkwatsonjsuereth
authored
Add metrics supplementary guideline for instrumentation authors (#1981)
* Add metrics supplementary guideline for instrumentation authors * address the review comments * Apply suggestions from code review Co-authored-by: John Watson <[email protected]> * Update specification/metrics/supplementary-guidelines.md Co-authored-by: John Watson <[email protected]> * rewrap Co-authored-by: John Watson <[email protected]> Co-authored-by: Josh Suereth <[email protected]>
1 parent 2d72f95 commit 9ceb9fa

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

specification/metrics/supplementary-guidelines.md

+55-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,67 @@ Table of Contents:
88

99
* [Guidelines for instrumentation library
1010
authors](#guidelines-for-instrumentation-library-authors)
11+
* [Instrument selection](#instrument-selection)
12+
* [Semantic convention](#semantic-convention)
1113
* [Guidelines for SDK authors](#guidelines-for-sdk-authors)
1214
* [Aggregation temporality](#aggregation-temporality)
1315
* [Memory management](#memory-management)
1416

1517
## Guidelines for instrumentation library authors
1618

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.
1872

1973
## Guidelines for SDK authors
2074

0 commit comments

Comments
 (0)