11# Record API Overview
2- The stats library allows users to record metrics for their applications or libraries. The core
2+ The stats library allows users to record metrics for their applications or libraries. The core
33data types used are:
44* ` Measure ` : describes the type of the individual values recorded by an application.
55* ` Measurement ` : describes a data point to be collected for a ` Measure ` .
@@ -11,16 +11,16 @@ for the data. This provides the fundamental type used for recording data.
1111
1212A Measure describes a value with the following metadata:
1313* ` name ` : a string by which the measure will be referred to, e.g. "rpc_server_latency", or
14- "vm_cpu_cycles". Names MUST be unique within the library. It is recommended to use names
14+ "vm_cpu_cycles". Names MUST be unique within the library. It is recommended to use names
1515compatible with the intended end usage, e.g, use host/path pattern.
1616* ` description ` : a string describing the measure, e.g. "RPC latency in seconds", "Virtual cycles
1717executed on VM".
1818* ` unit ` : a string describing the unit used for the ` Measure ` . Follows the format described by
1919[ Unified Code for Units of Measure] ( http://unitsofmeasure.org/ucum.html ) .
2020* ` type ` : the only supported types are ` int64 ` and ` double ` .
2121
22- Implementations MAY define a ` Measure ` data type, constructed from the parameters above.
23- Measure MAY have getters for retrieving all of the information used in ` Measure ` definition.
22+ Implementations MAY define a ` Measure ` data type, constructed from the parameters above.
23+ Measure MAY have getters for retrieving all of the information used in ` Measure ` definition.
2424Once created, Measure metadata is immutable.
2525
2626Example in Java:
@@ -32,7 +32,7 @@ private static final MeasureDouble RPC_LATENCY =
3232References to Measures in the system MAY be obtained from querying of registered Measures. This
3333functionality is required to decouple the recording of the data from the exporting of the data.
3434
35- For languages that do not allow private properties/metadata and if they are needed implementations
35+ For languages that do not allow private properties/metadata and if they are needed implementations
3636MAY define a ` MeasureDescription ` data type which contains all the read-only fields from the
3737` Measure ` definition such as: ` name ` , ` description ` , ` unit ` and ` type ` .
3838
@@ -44,26 +44,32 @@ measure name instead of the `Measure`.
4444
4545Implementations MAY define a ` MeasurementMap ` which describes a set of data points to be collected
4646for a set of Measures. Adding this functionality may improve the efficiency of the record usage API.
47- Additionally, when recording Measurements, ` MeasurementMap ` should optionally take a map of string
48- key-value pairs to record an exemplar. The string map is called ` attachments ` and represents the
47+ Additionally, when recording Measurements, ` MeasurementMap ` should optionally take a map of string
48+ key-value pairs to record an exemplar. The string map is called ` attachments ` and represents the
4949contextual information of an exemplar, for example trace id, span id or dropped labels.
5050
5151## Recording Stats
5252
53- Users should record Measurements against a context, either an explicit context or the implicit
54- current context. Tags from the context are recorded with the Measurements if they are any.
53+ Users should record Measurements against a context, either an explicit context or the implicit
54+ current context. Tags from the context are recorded with the Measurements if they are any.
5555When recording against an explicit context, implementations should allow users to add extra tags,
5656and those tags should not be added to the current context.
5757
5858Note that there is no implicit recording for exemplars. If you want to record a ` Measurement `
5959against an exemplar, you have to explicitly pass a string-string map.
6060
61- Implementations SHOULD provide a means of recording multiple Measurements at once. This
61+ Implementations SHOULD provide a means of recording multiple Measurements at once. This
6262functionality can be provided through one of the following options:
6363* As a method in a class/package (recommended name Stats/stats), taking a list of Measurement as
6464argument. e.g. ` record(List<Measurement>) ` or ` record(...Measurement) ` .
6565* As a ` record ` method of the appropriate data type. e.g. ` MeasurementMap.record() ` .
6666
67+ ### Record semantics
68+
69+ Record may defer view updates to a background thread or process. Therefore, updates to views
70+ may not take effect right away. No guarantees are necessarily provided about the order in
71+ which Record calls are processed.
72+
6773Example in Java:
6874
6975``` java
0 commit comments