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

3 Sessions

A span cannot outlive the process being killed, so a session is not a span. It is an identifier stamped on every record, two events, and a summary.

  • MUST generate session.id as a random UUID (version 4 or 7), lowercase, with hyphens.
  • MUST set session.previous_id on the session.start event when a session follows another one on the same install.
  • MUST stamp session.id on records as section 2.4 says.
  • MUST start a new session when the app returns to the foreground after 30 minutes or more in the background.
  • MUST start a new session when the current one reaches 4 hours of total length, at the next foreground transition or record after that point.
  • MUST start a new session on every cold start of the process. A process launched in the background (a background fetch, a push notification) MAY defer starting a session until it first comes to the foreground.
  • Both durations are policy values (section 12).
  • MUST emit a session.start log record when a session begins, with session.id and, when there is one, session.previous_id.
  • SHOULD emit session.end when the SDK knows the session ended (rotation while the process lives).
  • A backend MUST NOT require session.end. It derives the end from the last record seen and the session summary.
  • Both events belong to the summary family (15.1), which is sent for every session unless a backend samples summaries (9.2).

Release health (crash-free sessions and users, adoption, session counts) needs every session, but sampling holds back detail (section 9). The session summary is a small record of the summary family, sent for every session, sampled or not, so these numbers are exact rather than reweighted, unless a backend samples summaries to keep within a usage limit (9.2).

A summary is a log record with event name apsio.session.summary and these attributes:

Attribute Type Required Value
session.id string MUST The session the summary describes
apsio.session.start_time int MUST When the session started, Unix nanoseconds
apsio.session.outcome string MUST active, exited, crashed or abnormal_exit
apsio.session.error_count int MUST Handled errors recorded so far in the session
apsio.session.foreground boolean SHOULD Whether the app was in the foreground when the summary was written
apsio.exit.reason, apsio.exit.source, apsio.exit.foreground, apsio.exit.platform_reason, apsio.exit.memory.footprint SHOULD on a final summary, when known How the session ended, per section 6.4
apsio.session.triggers string[] MUST when a trigger fired The triggers that fired in the session so far, as the policy names them (crash, event:checkout_failed), each once, in the order they fired, at most 20 (15.4)
apsio.session.capture_requests string[] MUST when a capture request releases the session The ids of the capture requests releasing the session, each once, in the order the SDK served them, at most 20, kept in every later summary of the session, per 15.5
apsio.memory.peak, apsio.memory.p90 int, bytes SHOULD The session’s highest memory footprint and its 90th percentile, per section 7.6
apsio.memory.warning_count int SHOULD Low-memory signals in the session, per section 7.6
apsio.device.thermal_state.worst string SHOULD The worst thermal state of the session, per section 7.8
apsio.device.low_power.seen boolean SHOULD Whether low power mode was on at any time in the session, per section 7.8
apsio.session.offline_ms (int), apsio.session.connection_types (string[]) SHOULD The milliseconds of the session spent offline, and the connection types seen in it, per section 7.10
apsio.session.device_state_dropped int MUST when any were dropped The device state, memory warning and connectivity records the SDK did not write over the per-session limit, summed, per section 7.8
apsio.session.log_bridge_dropped int MUST when any were dropped The bridged log entries the SDK did not write over the rate or the per-session limit, per section 13.7
apsio.session.log_bridge_incomplete boolean MUST when true A log bridge’s read stopped at its time bound, in this session or earlier in its process: some entries came late, or not at all once the bridge stopped, per section 13.7
apsio.app.launch.reason string SHOULD when known How the launch that started the session began, per section 8.1; absent for a session that starts on a return from the background
apsio.session.screen_path (string[]), apsio.session.rollup.requests, apsio.session.rollup.screen_loads, apsio.session.rollup.app_starts (string, JSON), apsio.session.rollup.truncated (boolean) SHOULD The session’s screens, requests, screen loads and starts, counted on the device from every record, held or not, per 3.5
apsio.policy.layers, apsio.policy.holdback string[] MUST when the policy has layers The ids of the layers the device applied when the session started, and of those it was held back from, per section 12.4
apsio.battery.drain (double), apsio.battery.drain_duration (int, ms) SHOULD with battery monitoring on Charge used in the foreground while not charging, per section 7.9
service.version, app.build_id string MUST when sent by another launch The release of the session, per section 2.5

The record’s timeUnixNano is the last time the session was seen alive.

  • MUST send a summary with outcome active when the session starts.
  • MUST send a final summary when the outcome is known:
    • exited when the session rotates or the app terminates normally, or when the next launch reads or infers a termination of a kind that is not a failure (a user quit, an update, a background eviction; section 6.4), with its exit attributes;
    • crashed when the next launch finds a crash report for the session (section 6);
    • abnormal_exit when the next launch infers or reads a termination without a crash report.
  • MAY send more active summaries during the session, for example on each move to the background, so the last-seen time stays current if the process is killed.
  • A backend MUST keep, per session, the summary with the latest timeUnixNano, except that crashed and abnormal_exit are final: a later active or exited summary for the same session does not replace them. A final summary sent by the next launch keeps the session’s last-seen time, so at an equal timeUnixNano an exited summary replaces an active one. Between two final summaries of a session, an abnormal_exit summary whose apsio.exit.source is platform replaces an exited or abnormal_exit one whose source is inferred, whatever their timeUnixNano: a platform exit record can arrive after the inference (6.4). A crashed summary is never replaced.
  • A session whose last summary is still active after the rotation timeouts have passed is counted as exited.

The policy can hold a family’s detail on the device (section 15), and a backend then has no record of each request or screen load to count. The summary carries the numbers instead: the SDK counts them from every record it writes, held or released, so they stay exact while the detail stays on the device.

  • apsio.session.screen_path: the app.screen.name of each app.screen.view of the session (8.6), in order, a name repeated right after itself written once. At most 50 entries: past that, the 50th entry is … (U+2026) and the rest is left out.
  • apsio.session.rollup.requests: a JSON array with one object per group of the session’s network spans (8.4): method (http.request.method), host (server.address, or the host of url.full when it is absent, lower-cased in ASCII, or none when the record has neither), template (url.template, or the template 8.4 derives from url.full when it is absent, derived on the device by the same rules), status (the class of http.response.status_code, 1xx to 5xx, or none when the request got no response), count, p50_ms and p90_ms.
  • apsio.session.rollup.screen_loads: a JSON array with one object per app.screen.name of the session’s app.screen.load spans (8.1): screen, count, p50_ms and p90_ms of their durations (time to initial display).
  • apsio.session.rollup.app_starts: a JSON array with one object per app.start span of the session, in order: type (app.start.type) and ms, its duration. At most 20.
  • Percentiles. Durations are whole milliseconds, rounded down, counted in buckets whose upper bounds are 50, 100, 150, 200, 300, 400, 500, 750, 1000, 1500, 2000, 3000, 4000, 6000, 8000, 10000, 15000, 20000 and 30000, and a last bucket above 30000. p50_ms and p90_ms are the upper bound of the bucket that holds the value of rank ⌈0.5 × count⌉ and ⌈0.9 × count⌉ in ascending order, and the longest duration of the group when that bucket is the last. A device keeps only the counts per bucket and the longest duration, whatever the number of records.
  • Groups. The objects of requests and screen_loads are ordered by count, highest first, then by their other keys in code point order (method, host, template, status). At most 50: past that, the first 49 are kept and the others become one object, with method, host, template and status (or screen) set to *, the sum of their counts and the percentiles of all their durations.
  • Size. Each rollup is at most 16 KiB of UTF-8 (1.6). Past that, the SDK leaves out whole objects from the end, never a part of one, and sets apsio.session.rollup.truncated to true.
  • MUST count a record that is held, sent or still queued alike, and MUST NOT count a record it did not write: consent withdrawn, or capture turned off (12.2). Every summary after the one sent when the session starts carries the rollups of the session so far, so the last one a backend keeps (3.4) has them all; that first active summary MAY omit them.
  • MUST keep a session’s rollup counts in the store, written as they change or at least on each move to the background, so the final summary the next launch writes for a session that crashed or ended abnormally (3.4) carries the counts kept last. Without them, the sessions that end worst would be the ones that lose their numbers.
  • A backend that has a session’s rollups SHOULD take the session’s numbers of requests, screen loads and starts from them rather than from its released records, which can be a sample or a trigger’s window, and MUST NOT add the two. The released records stay the detail behind the numbers.

The function session.rollup (B.2) fixes the groups, their order and the percentiles.