Definition
A canonical record is the single agreed form in which a system writes down one kind of event or result, such as one attempt of a measured operation. The form fixes the fields, the type and unit of each field, the allowed status values and how a missing value is shown, and it states what each field means. Every program that writes or reads such records follows this one form, so each record has exactly one interpretation. The form fixes meaning, not the exact stored bytes.
The idea
Canonical means chosen as the one standard form among several possible ones. The need for a single form appears as soon as two programs share data. One program writes duration=25, and another averages that field over many records. The 25 could be milliseconds, microseconds, a code meaning that the operation timed out, or a count of retries, and nothing in the record says which. Two analysts who read the file differently get two different results from the same data, and neither sees an error.
A canonical record removes the guessing: the meaning is written down once, before any record exists, and a program checks every record against it. A paper form is a fair picture, with a label, a unit and an instruction for every box. The picture stops being accurate in one respect. A person filling in a form can ask what a box means; a program cannot, so the rules must cover every case, failures and missing values included, exactly enough for a program to check them.
How it works
Designing a canonical record takes these steps.
Name the event: what one record stands for, such as one attempt of one operation. Every attempt gets exactly one record, whatever its outcome.
Define each field: its name, type (whole number, decimal number, text, or one value from a fixed list), unit, allowed range, and whether it is required.
Define the statuses: every possible outcome, such as
success,timeoutanderror, exactly one per record, and for each status the fields that must be present or absent. For example,duration_msis present exactly when the status issuccess.Define the measurement boundary: for a duration, the event that starts it, the event that ends it and the clock that times both.
Define how a value is missing: by leaving the field out or by a dedicated null value, never by an ordinary number. A number that stands for something other than a quantity, such as 999 written for a timeout §9.34, is a sentinel value, and a later program can add it into a sum without any warning.
Give the form a version, stored in every record. A change in what any field means needs a new version, so that old records keep their old meaning.
Check every record before any analysis with a validator, a program that rejects every record that breaks these rules. For records in JSON §12.26 (JavaScript Object Notation), a common text format, JSON Schema §12.27, a language for describing which JSON records are allowed, can express the types, ranges, required fields and status rules; the measurement boundary stays a written rule.
The form also sorts its fields into three classes.
Result fields hold the outcome studied: the status, a measured duration, a count.
Context fields hold what a reader needs to interpret the result or to decide whether the record belongs in an analysis: the unit, the clock, the time limit that decides a timeout, the software version, the configuration.
Bookkeeping fields change neither the result nor its meaning: the name of the file that stores the record, the time it was copied, a free-text comment.
Context fields are often called metadata, data about the data. They belong to the definition of the result all the same, and the validator checks them as strictly as the result fields.
When records are identified by a digest (a short value that a cryptographic hash function §5.1 computes from bytes) or protected by a digital signature §5.14, a second, separate choice is needed: a canonical serialization §4.28, one exact byte encoding per record. Otherwise the same record with its fields in another order has a different digest. The Canonical JSON §12.28 entry treats that choice.
Worked example
The form for one operation says that an attempt with no reply within 50 ms gets the status timeout. Three attempts produce three records.
Record 1:
statusissuccess,duration_msis 2.Record 2:
statusissuccess,duration_msis 4.Record 3:
statusistimeout,duration_msis absent,limit_msis 50.
Read by the form, the records give two separate results. The success rate is 2 successes out of 3 attempts, . The mean duration of the successful attempts is ms. The third record shows only that its attempt would have taken more than 50 ms: it is a censored observation §11.28, which gives a limit instead of a value. status and duration_ms are result fields; limit_ms is a context field, without which nobody can say what the timeout means.
Now suppose another program wrote the timeout as the sentinel value duration_ms = 999, and a reader averaged every duration_ms as an ordinary duration: ms. The arithmetic is right, but no attempt took 335 ms, and the third attempt did not take 999 ms. The canonical form blocks this error: its status rule forbids any duration_ms in a timeout record, so the validator rejects the record before anyone averages it.
Stated precisely
Let a record form list the fields . For each field , the form gives a domain , the set of allowed values in the stated unit, and a presence rule, a condition on the other fields (usually on the status) that says when must be present or absent. A record is valid when it contains every field its presence rules require, no field they forbid, and only values inside their domains. The contract: every program that follows the form computes the same values from the same valid record.
The classes of fields follow from one test. Let be the quantity an analysis reports, such as a mean duration. Change one field of one record and keep everything else fixed. If that change can alter , the eligibility of the record for the analysis, or the meaning of another field, the field belongs to the definition of the result. Otherwise it is bookkeeping.
Counting rules belong to the contract too. With one record per attempt and one status per record, attempts equal successes plus timeouts plus errors; in the example, . A mean over successes divides by 2, a success rate by 3.
Limits and common mistakes
A valid record is not a correct measurement. A record can satisfy every rule and still come from a faulty instrument, a wrong clock or a measurement boundary that does not match the question. The validator checks form, not truth.
A sentinel value in an ordinary numeric field joins every sum and mean computed over that field. Use a status field and an absent value instead.
Writing records only for successful attempts makes the success rate impossible to compute and hides every failure.
Changing what a field means without changing the version silently reinterprets every old record. Converting old records to a new version of the form is a schema migration §8.36, and the conversion program needs the same checking as any other program.
Questions answered
Which fields define the result, and which are only metadata?
The fields that define a result are the outcome fields, such as the status and the measured value, plus every context field without which the outcome cannot be interpreted or placed in the right analysis: the unit, the measurement boundary (the events that start and end a measured interval), the clock, the time limit that decides a timeout, the software version and the configuration. Only bookkeeping fields, such as the storage location or a free-text comment, are metadata in the sense of not being part of the result.
The test is to change one field of a record and keep the rest fixed. If the reported number, the eligibility of the record for the analysis, or the meaning of another field can change, the field defines the result and must be specified and checked. Whether a field is plotted is not the test: the unit is rarely plotted, yet it always defines the result.
Related entries: JSON Schema (§12.27), Canonical JSON (§12.28), Estimand and estimator (§11.2), Threshold and sentinel semantics (§15.37), Censoring (§11.28), Serialization (§4.28), Schema migration (§8.36).