Metrics
A Metric is a time-series aggregation projected exclusively from Events the Definition selects. This chapter defines how Events contribute, how Dimensions classify contributions, and how projection relates to the write that produced the Event.
Contributions
Section titled “Contributions”- A Metric selects Events with
addEventonMetricBuilder. Only selected Events contribute; Item state never contributes directly. - Each selected Event contributes one value. Without a calculation handler the value is 1. A calculation handler receives the Event and returns a number, or
nullto exclude that Event. - A contribution is attributed to the Event’s creation time.
- A contribution carries the Event, the Item the Event was published against, the Metric PRN and the Workspace.
- Each Event contributes at most once per Metric. Projecting an Event a second time adds nothing.
Dimensions
Section titled “Dimensions”- A Dimension is declared on an App with
addMetricDimensionand attached to a Metric withaddDimension(dimension, position, handler). Positions are 1 to 4, so a Metric holds at most four Dimensions. - A Dimension handler receives the Event, the Dimension instance and a read context. It returns an Item, an Identifier string or
undefined. - A Dimension value is an Item Identifier. A string result must be a valid Identifier (UUID). A handler that returns any other string, returns
undefinedor throws yields the null Identifier for that Dimension, and the contribution is still written. - A Dimension handler may read current Item data. Its result reflects the Items at projection time, not at the Event’s creation time.
Projection
Section titled “Projection”- Projection runs after the write that appended the Event commits. The projector performs it; the write execution does not.
- Completion of a Mutation,
publishorimmediatedoes not imply that the projection of its Events has completed. - Each Event is projected once. A projected Event is marked so it is not selected again. An Event whose projection fails is recorded as a projection error and is not projected again automatically.
- Projection runs under a
systemcontext in the Event’s Workspace.
Queries
Section titled “Queries”- A Metric is queried through
MetricQueryBuilderwith a Metric PRN, a focal Dimension, a period and an interval. - A query is opened with an aggregate function:
count,sum,average,maximumorminimum. It returns, for the interval, the contribution values aggregated by that function and the count of distinct focal Dimension values, grouped by the Dimensions the query names. - A Metric Grant governs who may query the Metric.
Related
Section titled “Related”- Metrics and projections explains why Metrics lag the write.
- Measure with metrics declares Metrics and Dimensions and drives the projector in tests.
- Persistence and projection describes each Runtime’s projector.
MetricBuilderdeclares Metrics.

