Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 242e90f

Browse files
committed
stats updates, specify parameters/output format
1 parent e07e155 commit 242e90f

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

text/metrics/0113-exemplars.md

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Exemplars are meaningful for all aggregations where relevant traces can provide
1919
An exemplar is defined as:
2020

2121
```
22-
message Exemplar {
22+
message RawValue {
2323
// Numerical value of the measurement that was recorded. Only one of these two fields is
2424
// used for the data, depending on its type
2525
double double_value = 0;
@@ -31,37 +31,57 @@ message Exemplar {
3131
// 'label:value' map of all labels that were provided by the user recording the measurement
3232
repeated opentelemetry.proto.common.v1.StringKeyValue labels = 3;
3333
34-
// Span ID of the current trace [Optional]
35-
string span_id = 4;
34+
// Span ID of the current trace
35+
optional string span_id = 4;
3636
37-
// Trace ID of the current trace [Optional]
38-
string trace_id = 5;
37+
// Trace ID of the current trace
38+
optional string trace_id = 5;
39+
40+
// When sample_count is non-zero, this exemplar has been chosen in a statistically
41+
// unbiased way such that the exemplar is representative of `sample_count` individual events
42+
optional double sample_count = 6;
3943
}
4044
```
4145

42-
Exemplar collection should be enabled through an optional parameter, and when not enabled, there should be no collection/logic performed related to exemplars. This is to ensure that when necessary, aggregations are as high performance as possible.
46+
Exemplar collection should be enabled through an optional parameter (disabled by default), and when not enabled, there should be no collection/logic performed related to exemplars. This is to ensure that when necessary, aggregations are as high performance as possible. Aggregations should also have a parameter to determine whether exemplars should only be collected if they are recorded during a sampled trace, or if tracing should have no effect on which exemplars are sampled. This allows aggregations to prioritize either the link between metrics and traces or the statistical significance of exemplars, when necessary.
47+
4348

4449
[#347](https://github.com/open-telemetry/opentelemetry-specification/pull/347) describes a set of standard aggregations in the metrics SDK. Here we describe how exemplars could be implemented for each aggregation.
4550

4651
### Exemplar behaviour for standard aggregations
4752

4853
#### HistogramAggregator
4954

50-
Every bucket in the HistogramAggregator MUST (when enabled) maintain a list of exemplars whose values are within the boundaries of the bucket (for buckets containing a population of one or more). Implementations SHOULD attempt to retain at least one exemplar per bucket, with a preference for exemplars with a sampled trace context and exemplars that were recorded later in the time period. They SHOULD NOT retain an unbounded number of exemplars.
55+
The HistogramAggregator MUST (when enabled) maintain a list of exemplars whose values are distributed across all buckets of the histogram (there should be one or more exemplars in every bucket that has a population of at least one sample-able measurement). Implementations SHOULD NOT retain an unbounded number of exemplars.
5156

5257
#### Sketch
5358

54-
A Sketch aggregation SHOULD maintain a list of exemplars whose values are spaced out across the distribution. There is no specific number of exemplars that should be retained (although the amount SHOULD NOT be unbounded), but the implementation SHOULD pick exemplars that represent as much of the distribution as possible. Preference SHOULD be given to exemplars with a sampled trace context. (Specific details not defined, see open questions.)
59+
A Sketch aggregation SHOULD maintain a list of exemplars whose values are spaced out across the distribution. There is no specific number of exemplars that should be retained (although the amount SHOULD NOT be unbounded), but the implementation SHOULD pick exemplars that represent as much of the distribution as possible. (Specific details not defined, see open questions.)
5560

5661
#### Last-Value
5762

5863
Most (if not all) Gauges operate asynchronously and do not ever interact with traces. Since the value of a Gauge is the last measurement (essentially the other parts of an exemplar), exemplars are not worth implementing for Gauge.
5964

6065
#### Exact
6166

62-
The Exact aggregator does not aggregate measurements. If exemplars are enabled, implementations may attach a separate exemplar to each measurement in an exact aggregation including the trace context and full set of labels.
67+
The Exact aggregation will function by maintaining a list of `RawValue`s, which contain all of the information exemplars would carry. Therefore the Exact aggregation will not need to maintain any exemplars.
68+
69+
#### Counter
70+
71+
Exemplars give value to counter aggregations in two ways: One, by tying metric and trace data together, and two, by providing necessary information to re-create the input distribution. When enabled, the aggregator will retain a bounded list of exemplars at each checkpoint, sampled from across the distribution of the data. Exemplars should be sampled in a statistically significant way.
6372

64-
Exemplars will always be retrieved from aggregations (by the exporter) as a list of Exemplar objects.
73+
#### MinMaxSumCount
74+
75+
Similar to Counter, MinMaxSumCount should retain a bounded list of exemplars that were sampled from across the input distribution in a statistically significant way.
76+
77+
#### Custom Aggregations
78+
Custom aggregations MAY support exemplars by maintaining a list of exemplars that can be retrieved by exporters. Custom aggregations should select exemplars based on their usage by the connected exporter (for example, exemplars recorded for Stackdriver should only be retained if they were recorded within a sampled trace).
79+
80+
Exemplars will always be retrieved from aggregations (by the exporter) as a list of RawValue objects. They will be passed to the collector through a
81+
```
82+
optional repeated RawValue exemplars = 6
83+
```
84+
attribute on the `metric_descriptor` object.
6585

6686
## Trade-offs and mitigations
6787

@@ -80,15 +100,3 @@ Exemplars are implemented in [OpenCensus](https://github.com/census-instrumentat
80100
- We don’t have a strong grasp on how the sketch aggregator works in terms of implementation - so we don’t have enough information to design how exemplars should work properly.
81101

82102
- The spec doesn't yet define a standard set of aggregations, just default aggregations for standard metric instruments. Since exemplars are always attached to particular aggregations, it's impossible to fully specify the behavior of exemplars.
83-
84-
### Which aggregations should include exemplars?
85-
86-
There are other aggregations that can benefit from exemplars, but they do not have well defined exemplar implementations and they are not supported by any known exporter. Should these be included in the OTEP or should they be left out?:
87-
88-
#### Counter
89-
90-
Exemplars give value to counter aggregations by tying metric and trace data together. When enabled, the aggregator will retain a small bounded list of exemplars at each checkpoint, containing at least the minimum and maximum value measurements whose trace context was sampled. Measurements SHOULD be retained only if there is a sampled trace context when the measurement was recorded.
91-
92-
#### MinMaxSumCount
93-
94-
The aggregator should maintain a list of at least two exemplars (when enabled), one near the maximum value and one near the minimum value. Preference SHOULD be given to exemplars with sampled traces, and if those are not available then the actual min and max values SHOULD be used.

0 commit comments

Comments
 (0)