Skip to content

9. Session sampling

  • 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 integer
    keep = h < rate × 2^64

    A rate of 1 keeps every session; a rate of 0 keeps none.

  • MUST take the rate from the policy (section 12), or 1 when 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_rate from the policy (1 when it has none). The hash is the same, so a session with replay is always a kept session.

These records are sent from every session, kept or not:

  • session.start, session.end and apsio.session.summary (section 3);
  • app.crash, app.abnormal_exit and the hang records apsio.hang and device.anr (section 6);
  • log records at severity ERROR or 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.

  • 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 counts 1 / rate times.
  • 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.