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 synchronous gauge instrument, clarify temporality selection influence on metric point persistence #3540

Merged
merged 16 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
97 changes: 97 additions & 0 deletions specification/metrics/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ linkTitle: API
+ [Histogram creation](#histogram-creation)
+ [Histogram operations](#histogram-operations)
- [Record](#record)
* [Gauge](#gauge)
+ [Gauge creation](#gauge-creation)
+ [Gauge operations](#gauge-operations)
- [Record](#record-1)
* [Asynchronous Gauge](#asynchronous-gauge)
+ [Asynchronous Gauge creation](#asynchronous-gauge-creation)
+ [Asynchronous Gauge operations](#asynchronous-gauge-operations)
Expand Down Expand Up @@ -768,6 +772,99 @@ httpServerDuration.Record(50, ("http.request.method", "POST"), ("url.scheme", "h
httpServerDuration.Record(100, new HttpRequestAttributes { method = "GET", scheme = "http" });
```

### Gauge

**Status**: [Experimental](../document-status.md)

`Gauge` is a [synchronous Instrument](#synchronous-instrument-api) which can be
used to record non-additive value(s) (e.g. the background noise level - it makes
no sense to record the background noise level value from multiple rooms and sum
them up) when changes occur.

Note: If the values are additive (e.g. the process heap size - it makes sense to
report the heap size from multiple processes and sum them up, so we get the
total heap usage), use [Counter](#counter)
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
or [UpDownCounter](#asynchronous-updowncounter).

Note: Synchronous Gauge is normally used when the measurements are exposed via a
subscription to change events (
i.e. `backgroundNoiseLevel.onChange(value -> gauge.record(value))`). If the
measurement is exposed via an accessor,
use [Asynchronous Gauge](#asynchronous-gauge) to invoke the accessor in a
callback function (
i.e. `createObservableGauge(observable -> observable.record(backgroundNoiseLevel.getCurrentValue()))`.

Example uses for Gauge:

* subscribe to change events for the background noise level
* subscribe to change events for the CPU fan speed

#### Gauge creation

There MUST NOT be any API for creating a `Gauge` other than with a
[`Meter`](#meter). This MAY be called `CreateGauge`. If strong type is
desired, [OpenTelemetry API](../overview.md#api) authors MAY decide the language
idiomatic name(s), for example `CreateUInt64Gauge`, `CreateDoubleGauge`,
`CreateGauge<UInt64>`, `CreateGauge<double>`.

See the [general requirements for synchronous instruments](#synchronous-instrument-api).

Here are some examples that [OpenTelemetry API](../overview.md#api) authors
might consider:

```java
// Java

DoubleGauge componentTemperature = meter.gaugeBuilder("hw.temperature")
.setDescription("Temperature of hardware component")
.setUnit("C")
.build();
```

#### Gauge operations

##### Record

Record the Gauge current value.

This API SHOULD NOT return a value (it MAY return a dummy value if required by
certain programming languages or systems, for example `null`, `undefined`).

This API MUST accept the following parameter:

* A numeric value. The current absolute value.

The value needs to be provided by a user. If possible, this API
SHOULD be structured so a user is obligated to provide this parameter. If it
is not possible to structurally enforce this obligation, this API MUST be
documented in a way to communicate to users that this parameter is needed.
* [Attributes](../common/README.md#attribute) to associate with the increment
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
value.

Users can provide attributes to associate with the value, but it is
up to their discretion. Therefore, this API MUST be structured to accept a
variable number of attributes, including none.

The [OpenTelemetry API](../overview.md#api) authors MAY decide to allow flexible
[attributes](../common/README.md#attribute) to be passed in as arguments. If
the attribute names and types are provided during the [gauge
creation](#gauge-creation), the [OpenTelemetry API](../overview.md#api)
authors MAY allow attribute values to be passed in using a more efficient way
(e.g. strong typed struct allocated on the callstack, tuple). The API MUST allow
callers to provide flexible attributes at invocation time rather than having to
register all the possible attribute names during the instrument creation. Here
are some examples that [OpenTelemetry API](../overview.md#api) authors might
consider:

```java
// Java
Attributes memoryA = Attributes.builder().put("id", "P0 Channel A");
Attributes memoryB = Attributes.builder().put("id", "P0 Channel B");

componentTemperature.record(32.5, memoryA);
componentTemperature.record(31.9, memoryB);
```

### Asynchronous Gauge

Asynchronous Gauge is an [asynchronous Instrument](#asynchronous-instrument-api)
Expand Down
8 changes: 4 additions & 4 deletions specification/metrics/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ in OTLP represents a sampled value at a given time. A Gauge stream consists of:
- A set of data points, each containing:
- An independent set of Attribute name-value pairs.
- A sampled value (e.g. current CPU temperature)
- A timestamp when the value was sampled (`time_unix_nano`)
- (optional) A timestamp (`start_time_unix_nano`) which best represents the
first possible moment a measurement could be recorded. This is commonly
set to the timestamp when a metric collection system started.
- A time window (of `(start, end]`) time for which the Gauge was calculated.
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
- The time interval is inclusive of the end time.
- Times are specified in Value is UNIX Epoch time in nanoseconds since
`00:00:00 UTC on 1 January 1970`
- (optional) a set of examplars (see [Exemplars](#exemplars)).

In OTLP, a point within a Gauge stream represents the last-sampled event for a
Expand Down
1 change: 1 addition & 0 deletions specification/metrics/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ an aggregation and `advice` to influence aggregation configuration parameters
| [Asynchronous Counter](./api.md#asynchronous-counter) | [Sum Aggregation](./sdk.md#sum-aggregation) |
| [UpDownCounter](./api.md#updowncounter) | [Sum Aggregation](./sdk.md#sum-aggregation) |
| [Asynchronous UpDownCounter](./api.md#asynchronous-updowncounter) | [Sum Aggregation](./sdk.md#sum-aggregation) |
| [Gauge](./api.md#gauge) | [Last Value Aggregation](./sdk.md#last-value-aggregation) |
| [Asynchronous Gauge](./api.md#asynchronous-gauge) | [Last Value Aggregation](./sdk.md#last-value-aggregation) |
| [Histogram](./api.md#histogram) | [Explicit Bucket Histogram Aggregation](./sdk.md#explicit-bucket-histogram-aggregation), with `ExplicitBucketBoundaries` from [advice](./api.md#instrument-advice) if provided |

Expand Down
Loading