Skip to content

Commit 2944511

Browse files
authored
Add clarification about async vs. sync instruments (open-telemetry#1733)
1 parent 8d5d2b3 commit 2944511

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

specification/metrics/api.md

+44-17
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,35 @@ instrument. It MUST be treated as an opaque string from the API and SDK.
224224
* It MUST support at least 1023 characters. Individual language clients can
225225
decide if they want to support more.
226226

227+
Instruments can be categorized based on whether they are synchronous or
228+
asynchronous:
229+
230+
<a name="synchronous-instrument"></a>
231+
232+
* Synchronous instruments (e.g. [Counter](#counter)) are meant to be invoked
233+
inline with application/business processing logic. For example, an HTTP client
234+
could use a Counter to record the number of bytes it has received.
235+
[Measurements](#measurement) recorded by synchronous instruments can be
236+
associated with the [Context](../context/context.md).
237+
238+
<a name="asynchronous-instrument"></a>
239+
240+
* Asynchronous instruments (e.g. [Asynchronous Gauge](#asynchronous-gauge)) give
241+
the user a way to register callback function, and the callback function will
242+
only be invoked upon collection. For example, a piece of embedded software
243+
could use an asynchronous gauge to collect the temperature from a sensor every
244+
15 seconds, which means the callback function will only be invoked every 15
245+
seconds. [Measurements](#measurement) recorded by asynchronous instruments
246+
cannot be associated with the [Context](../context/context.md).
247+
248+
Please note that the term _synchronous_ and _asynchronous_ have nothing to do
249+
with the [asynchronous
250+
pattern](https://en.wikipedia.org/wiki/Asynchronous_method_invocation).
251+
227252
### Counter
228253

229-
`Counter` is a synchronous Instrument which supports non-negative increments.
254+
`Counter` is a [synchronous Instrument](#synchronous-instrument) which supports
255+
non-negative increments.
230256

231257
Example uses for `Counter`:
232258

@@ -317,9 +343,9 @@ counterPowerUsed.Add(200, new PowerConsumption { customer = "Jerry" }, ("is_gree
317343

318344
### Asynchronous Counter
319345

320-
Asynchronous Counter is an asynchronous Instrument which reports
321-
[monotonically](https://wikipedia.org/wiki/Monotonic_function) increasing
322-
value(s) when the instrument is being observed.
346+
Asynchronous Counter is an [asynchronous Instrument](#asynchronous-instrument)
347+
which reports [monotonically](https://wikipedia.org/wiki/Monotonic_function)
348+
increasing value(s) when the instrument is being observed.
323349

324350
Example uses for Asynchronous Counter:
325351

@@ -441,9 +467,9 @@ operation is provided by the `callback`, which is registered during the
441467

442468
### Histogram
443469

444-
`Histogram` is a synchronous Instrument which can be used to report arbitrary
445-
values that are likely to be statistically meaningful. It is intended for
446-
statistics such as histograms, summaries, and percentile.
470+
`Histogram` is a [synchronous Instrument](#synchronous-instrument) which can be
471+
used to report arbitrary values that are likely to be statistically meaningful.
472+
It is intended for statistics such as histograms, summaries, and percentile.
447473

448474
Example uses for `Histogram`:
449475

@@ -525,10 +551,10 @@ httpServerDuration.Record(100, new HttpRequestAttributes { method = "GET", schem
525551

526552
### Asynchronous Gauge
527553

528-
Asynchronous Gauge is an asynchronous Instrument which reports non-additive
529-
value(s) (_e.g. the room temperature - it makes no sense to report the
530-
temperature value from multiple rooms and sum them up_) when the instrument is
531-
being observed.
554+
Asynchronous Gauge is an [asynchronous Instrument](#asynchronous-instrument)
555+
which reports non-additive value(s) (_e.g. the room temperature - it makes no
556+
sense to report the temperature value from multiple rooms and sum them up_) when
557+
the instrument is being observed.
532558

533559
Note: if the values are additive (_e.g. the process heap size - it makes sense
534560
to report the heap size from multiple processes and sum them up, so we get the
@@ -652,8 +678,8 @@ operation is provided by the `callback`, which is registered during the
652678

653679
### UpDownCounter
654680

655-
`UpDownCounter` is a synchronous Instrument which supports increments and
656-
decrements.
681+
`UpDownCounter` is a [synchronous Instrument](#synchronous-instrument) which
682+
supports increments and decrements.
657683

658684
Note: if the value grows
659685
[monotonically](https://wikipedia.org/wiki/Monotonic_function), use
@@ -790,10 +816,11 @@ customersInStore.Add(-1, new Account { Type = "residential" });
790816

791817
### Asynchronous UpDownCounter
792818

793-
Asynchronous UpDownCounter is an asynchronous Instrument which reports additive
794-
value(s) (_e.g. the process heap size - it makes sense to report the heap size
795-
from multiple processes and sum them up, so we get the total heap usage_) when
796-
the instrument is being observed.
819+
Asynchronous UpDownCounter is an [asynchronous
820+
Instrument](#asynchronous-instrument) which reports additive value(s) (_e.g. the
821+
process heap size - it makes sense to report the heap size from multiple
822+
processes and sum them up, so we get the total heap usage_) when the instrument
823+
is being observed.
797824

798825
Note: if the value grows
799826
[monotonically](https://wikipedia.org/wiki/Monotonic_function), use

0 commit comments

Comments
 (0)