|
| 1 | +interface metrics { |
| 2 | + use wasi:clocks/wall-clock@0.2.0.{datetime}; |
| 3 | + use wasi:clocks/monotonic-clock@0.2.0.{duration}; |
| 4 | + use types.{key-value, instrumentation-scope}; |
| 5 | + use tracing.{span-id, trace-id}; |
| 6 | + |
| 7 | + /// Exports a resource's metric data. |
| 8 | + %export: func(metrics: resource-metrics) -> result<_, error>; |
| 9 | + |
| 10 | + /// An error resulting from `export` being called. |
| 11 | + type error = string; |
| 12 | + |
| 13 | + /// A collection of `scope-metrics` and the associated `resource` that created them. |
| 14 | + record resource-metrics { |
| 15 | + /// The entity that collected the metrics. |
| 16 | + %resource: %resource, |
| 17 | + /// The collection of metrics with unique `instrumentation-scope`s. |
| 18 | + scope-metrics: list<scope-metrics>, |
| 19 | + } |
| 20 | + |
| 21 | + /// An immutable representation of the entity producing telemetry as attributes. |
| 22 | + record %resource { |
| 23 | + /// Attributes that identify the resource. |
| 24 | + attributes: list<key-value>, |
| 25 | + /// The schema URL to be recorded in the emitted resource. |
| 26 | + schema-url: option<string>, |
| 27 | + } |
| 28 | + |
| 29 | + /// A collection of `metric`s produced by a meter. |
| 30 | + record scope-metrics { |
| 31 | + /// The instrumentation scope that the meter was created with. |
| 32 | + scope: instrumentation-scope, |
| 33 | + /// The list of aggregations created by the meter. |
| 34 | + metrics: list<metric>, |
| 35 | + } |
| 36 | + |
| 37 | + /// A collection of one or more aggregated time series from a metric. |
| 38 | + record metric { |
| 39 | + /// The name of the metric that created this data. |
| 40 | + name: string, |
| 41 | + /// The description of the metric, which can be used in documentation. |
| 42 | + description: string, |
| 43 | + /// The unit in which the metric reports. |
| 44 | + unit: string, |
| 45 | + /// The aggregated data from a metric. |
| 46 | + data: metric-data |
| 47 | + } |
| 48 | + |
| 49 | + /// Metric data for all types. |
| 50 | + variant metric-data { |
| 51 | + /// Metric data for an f64 gauge. |
| 52 | + f64-gauge(gauge), |
| 53 | + /// Metric data for an f64 sum. |
| 54 | + f64-sum(sum), |
| 55 | + /// Metric data for an f64 histogram. |
| 56 | + f64-histogram(histogram), |
| 57 | + /// Metric data for an f64 exponential-histogram. |
| 58 | + f64-exponential-histogram(exponential-histogram), |
| 59 | + /// Metric data for an u64 gauge. |
| 60 | + u64-gauge(gauge), |
| 61 | + /// Metric data for an u64 sum. |
| 62 | + u64-sum(sum), |
| 63 | + /// Metric data for an u64 histogram. |
| 64 | + u64-histogram(histogram), |
| 65 | + /// Metric data for an u64 exponential-histogram. |
| 66 | + u64-exponential-histogram(exponential-histogram), |
| 67 | + /// Metric data for an s64 gauge. |
| 68 | + s64-gauge(gauge), |
| 69 | + /// Metric data for an s64 sum. |
| 70 | + s64-sum(sum), |
| 71 | + /// Metric data for an s64 histogram. |
| 72 | + s64-histogram(histogram), |
| 73 | + /// Metric data for an s64 exponential-histogram. |
| 74 | + s64-exponential-histogram(exponential-histogram), |
| 75 | + } |
| 76 | + |
| 77 | + /// A measurement of the current value of an instrument. |
| 78 | + record gauge { |
| 79 | + /// Represents individual aggregated measurements with unique attributes. |
| 80 | + data-points: list<gauge-data-point>, |
| 81 | + /// The time when the time series was started. |
| 82 | + start-time: option<datetime>, |
| 83 | + /// The time when the time series was recorded. |
| 84 | + time: datetime, |
| 85 | + } |
| 86 | + |
| 87 | + /// A single data point in a time series to be associated with a `gauge`. |
| 88 | + record gauge-data-point { |
| 89 | + /// `attributes` is the set of key value pairs that uniquely identify the |
| 90 | + /// time series. |
| 91 | + attributes: list<key-value>, |
| 92 | + /// The value of this data point. |
| 93 | + value: metric-number, |
| 94 | + /// The sampled `exemplar`s collected during the time series. |
| 95 | + exemplars: list<exemplar>, |
| 96 | + } |
| 97 | + |
| 98 | + /// Represents the sum of all measurements of values from an instrument. |
| 99 | + record sum { |
| 100 | + /// Represents individual aggregated measurements with unique attributes. |
| 101 | + data-points: list<sum-data-point>, |
| 102 | + /// The time when the time series was started. |
| 103 | + start-time: datetime, |
| 104 | + /// The time when the time series was recorded. |
| 105 | + time: datetime, |
| 106 | + /// Describes if the aggregation is reported as the change from the last report |
| 107 | + /// time, or the cumulative changes since a fixed start time. |
| 108 | + temporality: temporality, |
| 109 | + /// Whether this aggregation only increases or decreases. |
| 110 | + is-monotonic: bool, |
| 111 | + } |
| 112 | + |
| 113 | + /// A single data point in a time series to be associated with a `sum`. |
| 114 | + record sum-data-point { |
| 115 | + /// `attributes` is the set of key value pairs that uniquely identify the |
| 116 | + /// time series. |
| 117 | + attributes: list<key-value>, |
| 118 | + /// The value of this data point. |
| 119 | + value: metric-number, |
| 120 | + /// The sampled `exemplar`s collected during the time series. |
| 121 | + exemplars: list<exemplar>, |
| 122 | + } |
| 123 | + |
| 124 | + /// Represents the histogram of all measurements of values from an instrument. |
| 125 | + record histogram { |
| 126 | + /// Individual aggregated measurements with unique attributes. |
| 127 | + data-points: list<histogram-data-point>, |
| 128 | + /// The time when the time series was started. |
| 129 | + start-time: datetime, |
| 130 | + /// The time when the time series was recorded. |
| 131 | + time: datetime, |
| 132 | + /// Describes if the aggregation is reported as the change from the last report |
| 133 | + /// time, or the cumulative changes since a fixed start time. |
| 134 | + temporality: temporality, |
| 135 | + } |
| 136 | + |
| 137 | + /// A single data point in a time series to be associated with a `histogram`. |
| 138 | + record histogram-data-point { |
| 139 | + /// The set of key value pairs that uniquely identify the time series. |
| 140 | + attributes: list<key-value>, |
| 141 | + /// The number of updates this histogram has been calculated with. |
| 142 | + count: u64, |
| 143 | + /// The upper bounds of the buckets of the histogram. |
| 144 | + bounds: list<f64>, |
| 145 | + /// The count of each of the buckets. |
| 146 | + bucket-counts: list<u64>, |
| 147 | + /// The minimum value recorded. |
| 148 | + min: option<metric-number>, |
| 149 | + /// The maximum value recorded. |
| 150 | + max: option<metric-number>, |
| 151 | + /// The sum of the values recorded |
| 152 | + sum: metric-number, |
| 153 | + /// The sampled `exemplar`s collected during the time series. |
| 154 | + exemplars: list<exemplar>, |
| 155 | + } |
| 156 | + |
| 157 | + /// The histogram of all measurements of values from an instrument. |
| 158 | + record exponential-histogram { |
| 159 | + /// The individual aggregated measurements with unique attributes. |
| 160 | + data-points: list<exponential-histogram-data-point>, |
| 161 | + /// When the time series was started. |
| 162 | + start-time: datetime, |
| 163 | + /// The time when the time series was recorded. |
| 164 | + time: datetime, |
| 165 | + /// Describes if the aggregation is reported as the change from the last report |
| 166 | + /// time, or the cumulative changes since a fixed start time. |
| 167 | + temporality: temporality, |
| 168 | + } |
| 169 | + |
| 170 | + /// A single data point in a time series to be associated with an `exponential-histogram `. |
| 171 | + record exponential-histogram-data-point { |
| 172 | + /// The set of key value pairs that uniquely identify the time series. |
| 173 | + attributes: list<key-value>, |
| 174 | + /// The number of updates this histogram has been calculated with. |
| 175 | + count: u64, |
| 176 | + /// The minimum value recorded. |
| 177 | + min: option<metric-number>, |
| 178 | + /// The maximum value recorded. |
| 179 | + max: option<metric-number>, |
| 180 | + /// The maximum value recorded. |
| 181 | + sum: metric-number, |
| 182 | + /// Describes the resolution of the histogram. |
| 183 | + /// |
| 184 | + /// Boundaries are located at powers of the base, where: |
| 185 | + /// |
| 186 | + /// base = 2 ^ (2 ^ -scale) |
| 187 | + scale: s8, |
| 188 | + /// The number of values whose absolute value is less than or equal to |
| 189 | + /// `zero_threshold`. |
| 190 | + /// |
| 191 | + /// When `zero_threshold` is `0`, this is the number of values that cannot be |
| 192 | + /// expressed using the standard exponential formula as well as values that have |
| 193 | + /// been rounded to zero. |
| 194 | + zero-count: u64, |
| 195 | + /// The range of positive value bucket counts. |
| 196 | + positive-bucket: exponential-bucket, |
| 197 | + /// The range of negative value bucket counts. |
| 198 | + negative-bucket: exponential-bucket, |
| 199 | + /// The width of the zero region. |
| 200 | + /// |
| 201 | + /// Where the zero region is defined as the closed interval |
| 202 | + /// [-zero_threshold, zero_threshold]. |
| 203 | + zero-threshold: f64, |
| 204 | + /// The sampled exemplars collected during the time series. |
| 205 | + exemplars: list<exemplar>, |
| 206 | + } |
| 207 | + |
| 208 | + /// A set of bucket counts, encoded in a contiguous array of counts. |
| 209 | + record exponential-bucket { |
| 210 | + /// The bucket index of the first entry in the `counts` list. |
| 211 | + offset: s32, |
| 212 | + /// A list where `counts[i]` carries the count of the bucket at index `offset + i`. |
| 213 | + /// |
| 214 | + /// `counts[i]` is the count of values greater than base^(offset+i) and less than |
| 215 | + /// or equal to base^(offset+i+1). |
| 216 | + counts: list<u64>, |
| 217 | + } |
| 218 | + |
| 219 | + /// A measurement sampled from a time series providing a typical example. |
| 220 | + record exemplar { |
| 221 | + /// The attributes recorded with the measurement but filtered out of the |
| 222 | + /// time series' aggregated data. |
| 223 | + filtered-attributes: list<key-value>, |
| 224 | + /// The time when the measurement was recorded. |
| 225 | + time: datetime, |
| 226 | + /// The measured value. |
| 227 | + value: metric-number, |
| 228 | + /// The ID of the span that was active during the measurement. |
| 229 | + /// |
| 230 | + /// If no span was active or the span was not sampled this will be empty. |
| 231 | + span-id: span-id, |
| 232 | + /// The ID of the trace the active span belonged to during the measurement. |
| 233 | + /// |
| 234 | + /// If no span was active or the span was not sampled this will be empty. |
| 235 | + trace-id: trace-id, |
| 236 | + } |
| 237 | + |
| 238 | + /// Defines the window that an aggregation was calculated over. |
| 239 | + enum temporality { |
| 240 | + /// A measurement interval that continues to expand forward in time from a |
| 241 | + /// starting point. |
| 242 | + /// |
| 243 | + /// New measurements are added to all previous measurements since a start time. |
| 244 | + /// |
| 245 | + /// This is the default temporality. |
| 246 | + cumulative, |
| 247 | + /// A measurement interval that resets each cycle. |
| 248 | + /// |
| 249 | + /// Measurements from one cycle are recorded independently, measurements from |
| 250 | + /// other cycles do not affect them. |
| 251 | + delta, |
| 252 | + /// Configures Synchronous Counter and Histogram instruments to use |
| 253 | + /// Delta aggregation temporality, which allows them to shed memory |
| 254 | + /// following a cardinality explosion, thus use less memory. |
| 255 | + low-memory, |
| 256 | + } |
| 257 | + |
| 258 | + /// The number types available for any given instrument. |
| 259 | + variant metric-number { |
| 260 | + %f64(f64), |
| 261 | + %s64(s64), |
| 262 | + %u64(u64), |
| 263 | + } |
| 264 | +} |
0 commit comments