Skip to content
apsio/ specApsio Mobile Profile, homev0.1.0 · final
GitHub

9 Session sampling

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

    A rate of 1 keeps every session; a rate of 0 keeps 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. With replay at a lower rate than spans, a session that sends replay also sends its spans.

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).

  • 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 counts 1 / rate times.
  • A record with no rate counts with weight 1. A record of the summary or errors family (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_trigger or never mode, carries apsio.sampling.released (trigger, remote or live) 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 weight 1 and carries no apsio.sampling.released.
  • When summary is sampled, crash-free rates, adoption and session counts are estimates, and a backend SHOULD say so where it shows them.