9 Session sampling
9.1 The decision
Section titled “9.1 The decision”A family in sampled mode (15.3) sends a session’s records
when the session is in its sample. The decision:
-
MUST be made once per session and family, at session start, so a family’s records of a session in the sample are sent and those of a session outside it are held whole.
-
MUST be deterministic from
session.id, so any component can recompute it:h = the first 8 bytes of SHA-256(session.id as UTF-8), as an unsigned big-endian integerkeep = h < rate × 2^64A rate of
1keeps every session; a rate of0keeps none. -
MUST use the rate of the family in the policy in force when the session starts (section 12): a policy fetched later applies to sessions that start after it.
-
Every family uses the same
h, so a session in the sample at a lower rate is in it at every higher rate. Withreplayat a lower rate thanspans, a session that sends replay also sends its spans.
9.2 Not sampled by default
Section titled “9.2 Not sampled by default”A family the policy does not set is in always mode
(15.3), so with no policy every record is sent. A backend
SHOULD keep summary and errors in always mode, so release health and crash counts
are exact, and sample them only to keep within a usage limit. In sampled mode, the first
error of each issue on a device still passes (15.3).
9.3 Reweighting
Section titled “9.3 Reweighting”- MUST put the family’s rate on each record a sample released, as
apsio.sampling.session.rate, on the record or on the Resource of its group (section 2.4); on a metric point of a session, as an attribute of the point. - A backend counts a record with a rate with weight
1 / rate; a sum point’s value counts1 / ratetimes. - A record with no rate counts with weight
1. A record of thesummaryorerrorsfamily (15.1) takes only a rate set on the record itself: a rate on the Resource does not apply to it. An SDK that samples those families puts the rate on each of their records. - A record released by a trigger, a remote request or a live inspection command from a session
outside the family’s sample, or from a family in
on_triggerornevermode, carriesapsio.sampling.released(trigger,remoteorlive) and no rate, on the record or on its Resource (section 15, 16.6). A backend stores and shows it, and MUST NOT count it in estimates of totals: those come from the sample. The first error of an issue released past the sample counts with weight1and carries noapsio.sampling.released. - When
summaryis sampled, crash-free rates, adoption and session counts are estimates, and a backend SHOULD say so where it shows them.