Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics supplementary guideline for instrumentation authors #1981

Merged
merged 7 commits into from
Oct 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion specification/metrics/supplementary-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,65 @@ Table of Contents:

* [Guidelines for instrumentation library
authors](#guidelines-for-instrumentation-library-authors)
* [Instrument selection](#instrument-selection)
* [Semantic convention](#semantic-convention)
* [Guidelines for SDK authors](#guidelines-for-sdk-authors)
* [Aggregation temporality](#aggregation-temporality)
* [Memory management](#memory-management)

## Guidelines for instrumentation library authors

TBD
### Instrument selection

The [Instruments](./api.md#instrument) are part of the [Metrics API](./api.md).
They allow [Measurements](./api.md#measurement) to be recorded
[synchronously](./api.md#synchronous-instrument) or
[asynchronously](./api.md#asynchronous-instrument).

Choosing the correct instrument is important, because:

* It helps the library to achieve better efficiency. For example, if we want to
report room temperature to [Prometheus](https://prometheus.io), we want to
consider [Asynchronous Gauge](./api.md#asynchronous-gauge) rather than
reyang marked this conversation as resolved.
Show resolved Hide resolved
periodically poll the sensor, so that we only access the sensor when scraping
happened.
* It makes the consumption easier for the user of the library. For example, if
we want to report HTTP server request latency, we want to consider
[Histogram](./api.md#histogram), so most of the users can get a reasonable
reyang marked this conversation as resolved.
Show resolved Hide resolved
experience (e.g. default buckets, min/max) by simply enabling the metrics
stream, rather than doing extra configurations.
* It generates clarity to the semantic of the metrics stream, so the consumers
have better understanding of the results. For example, if we want to report
the process heap size, by using [Asynchronous
reyang marked this conversation as resolved.
Show resolved Hide resolved
UpDownCounter](./api.md#asynchronous-updowncounter) rather than [Asynchronous
reyang marked this conversation as resolved.
Show resolved Hide resolved
Gauge](./api.md#asynchronous-gauge), we've made it explicit that the consumer
can add up the numbers across all processes to get the "total heap size".

Here is one way of choosing the correct instrument:

* I want to **count** something (by recording a delta value):
* If the value is monotonically increasing (the delta value is always
non-negative) - use [Counter](./api.md#counter).
reyang marked this conversation as resolved.
Show resolved Hide resolved
* If the value is NOT monotonically increasing (the delta value can be
positive, negative or zero) - use [UpDownCounter](./api.md#updowncounter).
reyang marked this conversation as resolved.
Show resolved Hide resolved
* I want to **measure** something (by reporting an absolute value):
* If it makes NO sense to add up the values across different dimensions, use
[Asynchronous Gauge](./api.md#asynchronous-gauge).
reyang marked this conversation as resolved.
Show resolved Hide resolved
* If it makes sense to add up the values across different dimensions:
* If the value is monotonically increasing - use [Asynchronous
reyang marked this conversation as resolved.
Show resolved Hide resolved
Counter](./api.md#asynchronous-counter).
* If the value is NOT monotonically increasing - use [Asynchronous
reyang marked this conversation as resolved.
Show resolved Hide resolved
UpDownCounter](./api.md#asynchronous-updowncounter).
* I want to **record** something, and the statistics about this thing are likely
reyang marked this conversation as resolved.
Show resolved Hide resolved
to be meaningful - use [Histogram](./api.md#histogram).

### Semantic convention

Once you decided [which instrument(s) to be used](#instrument-selection), you
will need to decide the names for the instruments and attributes.

It is highly recommended that you align with the `OpenTelemetry Semantic
reyang marked this conversation as resolved.
Show resolved Hide resolved
Conventions`, rather than inventing your own semantics.

## Guidelines for SDK authors

Expand Down