9. Session sampling
9.1 The decision
Section titled “9.1 The decision”-
MUST decide once per session, at session start, so every signal of a kept session is kept and a dropped session is dropped whole.
-
MUST make the decision 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 take the rate from the policy (section 12), or
1when there is none. A rate change applies to sessions that start after it. -
Replay (section 10) is kept for a session when the same decision holds with the rate
session_rate × replay_rate,replay_ratefrom the policy (1when it has none). The hash is the same, so a session with replay is always a kept session.
9.2 Always sent
Section titled “9.2 Always sent”These records are sent from every session, kept or not:
session.start,session.endandapsio.session.summary(section 3);app.crash,app.abnormal_exitand the hang recordsapsio.hanganddevice.anr(section 6);- log records at severity
ERRORor above, including handled errors; - MetricKit points (section 7), which belong to no session.
Sampling applies to the rest: spans, lower-severity logs, replay, and the metric points
that belong to a session, which carry its session.id (the frame counts of
8.5). A point is kept or dropped with its session, like a
span.
9.3 Reweighting
Section titled “9.3 Reweighting”- MUST put the rate on records of a kept session 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 from a kept session with weight
1 / rate; a sum point’s value counts1 / ratetimes. - Records in 9.2 count with weight
1, whatever the rate, because they are never sampled. - A record with no rate counts with weight
1.