15 Instrumentation
An SDK captures every signal family into a store on the device. The policy (section 12) decides, per family, which records are sent, when, and how long the rest stays on the device before it is deleted. A session that was not sampled can still send the minutes before its crash, and an app’s owner can ask one device for what it holds, or for its deletion.
15.1 Families
Section titled “15.1 Families”Every record belongs to one family:
| Family | Records |
|---|---|
summary |
session.start, session.end and apsio.session.summary (section 3) |
errors |
app.crash, app.abnormal_exit, apsio.hang and device.anr (section 6); log records at severity ERROR or above, handled errors included |
logs |
Every other log record: breadcrumbs, feature flag evaluations, screen views, the app’s own logs |
spans |
Spans, except network spans |
network |
Network spans (8.4) |
metrics |
Metric points, those of a session and those that belong to none (section 7) |
replay |
apsio.replay.segment records and their attachments (section 10) |
resources |
apsio.resource.snapshot and apsio.app.storage (7.7, 7.9) |
Two kinds of records belong to no family and are sent as soon as they are written, in every
mode: apsio.trigger (15.4) and apsio.remote_request
(15.5).
15.2 The store
Section titled “15.2 The store”- MUST write every record of every family to a store on disk when it is created, whatever
the family’s mode.
capturein the policy and the app’s start options still narrow what is created (12.2); this section decides only what is sent. - MUST write records already redacted and masked: unmasked text never touches the store (11, 10.3).
- MUST NOT write anything while consent is withdrawn (13.5).
- A record in the store is held until its family’s mode releases it. A released record joins the queue of section 4 and is sent as that section says. An SDK MAY keep held and released records in one store and mark them, or move a record when it is released.
- SHOULD seal held and released records into batches per family, session and
user.hash, so a release needs no re-batching and a request matched by auser.hash(15.5) reaches them whole. A sealed batch is released whole: an SDK MAY release a batch of which only some records fall in a trigger’s window (15.4). It MUST release every record in the window, and MUST NOT release a record of another session. - An SDK MAY re-encode a held batch when it releases it, to add
apsio.sampling.released(9.3); the batch gets itsApsio-Batch-Idthen (4.2), as it was never sent. - A released record is deleted after a
2xxresponse, as section 4 says.
15.3 Modes
Section titled “15.3 Modes”Each family has a mode in the policy’s instrumentation.families (12.2):
| Mode | The family’s records are |
|---|---|
always |
Released when they are written |
sampled |
Released when they are written if the session is in the family’s sample; held otherwise, until one of the family’s triggers fires, if it lists any (15.4) |
on_ |
Held until one of the family’s triggers fires (15.4) |
never |
Held until a remote send request (15.5), or until deleted |
- A family the policy does not name is in
alwaysmode, at rate1, exceptresources, which is then innevermode: its snapshots are many, and a backend turns them on. - The sample. In
sampledmode, a session is in a family’s sample when the decision of 9.1 holds for itssession.idat the family’srate. Every family uses the same hash, so a session in the sample at a lower rate is in it at every higher rate. MUST take each family’s mode and rate from the policy in force when the session starts: a policy fetched later applies to sessions that start after it. A session that starts on a return to the foreground starts under the policy the SDK holds at that moment, so a fetch made on that return applies from the next session. A session that starts with no policy at all, none fetched and none cached (a first launch), releases nothing until the first fetch ends or 10 seconds pass from the session’s start, then takes that policy as the one in force at its start, or the profile’s defaults if the fetch failed or has not ended; what it wrote in the meantime is decided by that policy like the rest. If the process ends before then (a crash, a kill), the next launch decides that session, its crash report included, by the policy it holds: the one the first launch fetched and cached if that fetch ended, else its own, after the same hold. The kill switch (12.3) and remote requests (15.5) are not held to the session: they apply once fetched. Only the modes and rates, here and in layers (12.4), and replay’smax_minutes_per_session(10.6) are held to the session; the rest of the policy (a family’s triggers, window, retention and cap, rules,capture, masking) applies once fetched. A metric point that belongs to no session is released inalwaysandsampledmodes. - A sampled-out summary is held like any other record, not dropped: a remote
sendrequest releases it (15.5); otherwise it is deleted when the retention ends (15.6). - The first error of an issue passes. In
sampledmode, anerrorsrecord of a session outside the sample is released anyway when its device fingerprint (15.7) is not among the fingerprints the device released this calendar month (UTC). The device MUST keep the fingerprints it released this month, across launches, and start the set again with each month. - The mode of the
summaryfamily isalwaysunless the backend samples summaries to keep an organization within a usage limit; the session’s crash-free state is then an estimate (9.3).
15.4 Triggers
Section titled “15.4 Triggers”A family in on_trigger mode lists its triggers in triggers, and the minutes before a
trigger to send in window_minutes. A family in sampled mode MAY list them too: the
rate decides what a session sends as it goes, and a trigger in a session outside the sample
releases the window before it, so a session that was not sampled and crashes sends the
minutes before the crash. always and never ignore triggers.
| Trigger | Fires when |
|---|---|
crash |
An app.crash or app.abnormal_exit record is written; for one found at the next launch, at the time of the crash or exit, in the session that ended |
error |
A log record at severity ERROR or above is written; for one found at the next launch (a crash or an exit), at the record’s time, in the session that ended, as crash |
anr |
A device.anr or apsio.hang record is written |
event:<name> |
The app calls trigger(name) with that name (section 13) |
rage_, dead_ |
An apsio.ui.rage_tap or apsio.ui.dead_tap record is written (8.7) |
rule:<id> |
A record the policy’s rule id matches is written (15.8) |
- An entry of
triggersis a trigger’s name, or an object that sets what that trigger releases for the family:trigger, the name;window_minutes, its own window (1 to 60), instead of the family’s; andafter,sessionorwindow. A name alone is the object with the family’swindow_minutesandafter=session. - When a trigger fires at time
tin a session, the SDK MUST release the records of each family that lists it whose time is fromt − window_minutestot, in that session, with the window that entry sets. - With
after=session, those families MUST then be released for the rest of the session, as inalwaysmode. Withafter=window, the family’s records aftertstay held, as before the trigger, until another trigger fires, so a trigger that fires often sends its windows and not whole sessions. When two entries of a family fire in a session,sessionwins. A record is released once: when windows overlap (the same trigger firing again a minute later), a record the first window released is not sent again. - In a session in a
sampledfamily’s sample, a trigger changes nothing for that family: its records are released already. - The SDK MUST record each trigger that fires in a session, once, by the name the policy
uses for it (
crash,event:checkout_failed). The session summary carries them asapsio.session.triggers(3.4), so a backend can list the sessions a trigger sent and show, on a session, what released it. A trigger counts there when it fires, whether or not a family lists it. trigger(name, attributes)writes anapsio.triggerlog record withapsio.trigger.nameand the app’s attributes, sent as soon as it is written. A name is 1 to 64 letters, digits,.,_or-; the SDK ignores a call with another name.- Records released by a trigger from a session outside a family’s sample carry
apsio.sampling.released=trigger(9.3).
15.5 Remote requests
Section titled “15.5 Remote requests”An app’s owner can ask one install, or one app user, for what its device holds (send), for
its deletion (delete), or for its next sessions in full (capture). The policy carries the open requests in requests
(12.2), at most 100, each until it expires.
- The policy is the same for every device of the app, so a request never names an install
or a user. Its
matchis the lowercase hex SHA-256 of the request’sid, a colon, and the install’sapp.installation.idor the app user’suser.hash. A device computes the same hash with its own installation id and with everyuser.hashits held records carry, and serves the requests that match. - A request matched by the installation id applies to every held record. A request matched by
a
user.hashapplies only to the held records that carry that hash. sendreleases the matching held records of the families the request lists (every family when it lists none), whatever their mode,neverincluded. They carryapsio.sampling.released=remote.deletedeletes the matching held records of the families the request lists (every family when it lists none,summaryincluded), and any of them still in the queue unsent.capturereleases every record of the families the request lists (every family when it lists none) insessionssessions (1 to 20) of the matching install, or of the matching app user while the app has set that hash, as inalwaysmode, until the request expires: the session in progress when the SDK serves it, and those after it. A whole session is released, whatever a family’s mode, triggers or trigger windows say (anafter: windowtrigger included). They carryapsio.sampling.released=remote. A family the app turned off in code, consent and the kill switch still win. A request releases a session when the SDK applies it to that session (the one in progress when served, or a later one counted againstsessions), whatever records the session holds. Every summary of such a session, from the first written after the request applies to it, lists the request’sidinapsio.session.capture_requests(3.4): each id once, in the order the SDK served them (requests served by one fetch, in their order inrequests), at most 20, the first ones kept, so a backend can count and list the sessions a request captured. Once listed, an id stays in every later summary of that session, the final one included, even after the request expires or the app clears or changes the user hash it matched. The SDK keeps those ids with the session in the store, so the final summary the next launch writes for a session that crashed or ended abnormally lists them too, as 3.5 keeps the rollups.- A capture ends when the policy stops listing it. On a policy fetched with
200that validates (12.1), the SDK MUST drop every capture it is serving that the newrequestsno longer lists (canceled, replaced or expired on the backend): it applies the request to no new session, even withsessionsleft or before itsexpires_at. A304, a failed fetch or a policy that does not validate changes nothing. A cancel takes effect from the next session: the session in progress when the policy drops it stays captured as a whole, records written after the drop included, and every session it already applied to keeps its records released and itsidinapsio.session.capture_requests. A dropped request never grants again on that install, even if a later policy lists it again (a new request always has a newid): its id stays among those served (above). The vectorspolicy/sdk-capture-canceledandpolicy/sdk-capture-kept-on-failed-fetchpin it. - MUST serve a request at most once: the SDK keeps the ids of the requests it served until they expire, across launches.
- MUST NOT serve a request while consent is withdrawn or the kill switch is on. A request never brings back what consent, an opt-out or the kill switch removed.
- After serving a request, the SDK writes an
apsio.remote_requestlog record, sent as soon as it is written:apsio.remote_request.id,apsio.remote_request.outcome(sent,deleted,capturing, ornothingwhen no held record matched) andapsio.remote_request.records, the number of records sent or deleted. It names the request, not the install or app user it matched. - A request whose
expires_athas passed is ignored. - Live inspection’s
raise_log_levelanddiagnosticscommands release records the same way, for a tester’s device (16.6); those carryapsio.sampling.released=live.
15.6 Retention and the cap
Section titled “15.6 Retention and the cap”- MUST delete a held record when its family’s retention has passed since the record’s
time (for a sealed batch, its newest record’s time). A family’s retention is its own
retention_hoursininstrumentation.familieswhen it sets one, andinstrumentation.retention_hoursotherwise. The default is 24 hours, and at most 168 (7 days). A released record that is still unsent is deleted at the same age. - MUST keep the store within
instrumentation.cap_bytes(20 MiB by default), and replay withininstrumentation.replay_cap_bytesof it (10 MiB by default). MUST keep a family that sets its owncap_bytesininstrumentation.familieswithin it, deleting that family’s oldest records first; for replay, the smaller of itscap_bytesandreplay_cap_bytesapplies. A family’s cap is a share of the store, never more: one larger thaninstrumentation.cap_bytesis the store’s. When the store is full, the SDK deletes the oldest records first: replay over its cap first, then the other families, andsummaryanderrorsrecords last. - MUST delete everything in the store at once when consent is withdrawn (13.5) or the kill switch is on (12.3).
- MUST check retention and the cap at launch, when it writes, and at least every 15 minutes while the app runs.
- A backend counts its own retention from the time it received a record, not from the record’s time.
15.7 The device fingerprint
Section titled “15.7 The device fingerprint”The device groups errors by a fingerprint, so the first error of an issue passes a sample (15.3). It is the lowercase hex SHA-256 of a text built from the record:
- with
apsio.error.fingerprintset by the app (6.2):f:followed by its value; - otherwise:
t:followed byexception.type, then, for each of the first three in-app frames of the stack (the first three frames when none is in-app), a line feed and the frame: its function, as the runtime prints it without the file and line, when the stack has one; otherwise its image name,+0xand the instruction’s offset from the image’s load address, in lowercase hex without leading zeros.
The backend groups issues on its own, with symbols the device does not have; the device
fingerprint only decides what passes a sample. The function error.device_fingerprint
(B.2) checks it.
15.8 Rules
Section titled “15.8 Rules”A rule is a trigger the policy defines, so what releases a session’s records changes without
an app release. instrumentation.rules lists them, at most 50
(12.2); a family lists a rule in its triggers as
rule:<id>, as it lists any trigger (15.4).
{ "id": "checkout_5xx", "on": "network", "where": [ { "attr": "url.template", "op": "eq", "value": "/checkout" }, { "attr": "http.response.status_code", "op": "status_class", "value": "5xx" } ]}idis 1 to 64 lowercase letters, digits,.,_or-, unique in the list.onnames the records the rule reads:log(every log record),log:<event name>(log records with that event name, for examplelog:app.screen.view),span(every span except network spans),span:<span name>(for examplespan:app.screen.load), ornetwork(network spans, 8.4).whereis 0 to 8 conditions, and the rule matches a record when all of them hold. Each has anattr, anopand, except forexists, avalue. Two rules express an “or”.attrnames a record attribute; when the record lacks it, the Resource’s, as forsession.id(2.4), so a rule can readservice.versionoros.name. Three names read the record itself:body, a log record’s body as a string;severity, its severity number; andduration_ms, a span’s duration in milliseconds.op:
op |
Holds when the value read is | value |
|---|---|---|
eq |
Equal to value: a string, a number or a boolean, of the same type |
One value |
in |
Equal to one of the values | 1 to 50 values |
prefix |
A string that starts with value |
A string |
gte, lte |
A number at least, or at most, value |
A number |
status_ |
An integer in the class: 5xx is 500 to 599 |
1xx to 5xx |
glob |
A string that value matches whole: * matches any run of characters, ? one character, every other character itself, with case |
A string of at most 128 characters |
exists |
Present when value is true, absent when it is false |
true or false |
- A condition on an attribute the record and the Resource both lack holds only for
exists=false. A value of another type than theoptakes (a number forprefix) does not hold. - The SDK matches as each record is written, on the record as stored: redacted and masked (15.2), with its attribute values bounded (1.6). It MUST take the rules from the policy it holds as each record is written (15.3): a rule a fetched policy adds or changes applies from the next record written, in the session in progress, and a record already written is not matched again. A rule a later policy removes fires no more.
- Matching is bounded. An SDK MUST match
globwithout backtracking over more than the last*(the greedy wildcard match), so a pattern costs at most the length of the text times the length of the pattern, and MUST NOT treat a pattern as a regular expression. An SDK MAY skip a rule’s conditions once the rule has fired in the session. - A rule fires at most once per session, at the time of the first record it matches; the
families that list it are released as 15.4 says, and the rest of the
session follows the entry’s
after. A rule that fired stays fired, by itsid, for the rest of the session, even when a later policy changes it; the SDK keeps the ids that fired with the session in the store, so a record found at the next launch does not fire it again. A rule fires like any trigger: the SDK writes anapsio.triggerrecord withapsio.trigger.name=rule:<id>, sent as soon as it is written, and the session summary listsrule:<id>inapsio.session.triggers. - A record found at the next launch (a crash report, an exit read then) fires a rule in the
session that ended, at the record’s time, as the
crashtrigger does. - A family that lists a rule the policy does not define ignores it. A rule the SDK cannot
read (an unknown
op, avalueof the wrong type) never fires, and the others still do. - Rules read what the SDK records and the app sends; they never add capture. A rule on
bodyreads only what the app’s logs already hold, after redaction.
The function instrumentation.rule_match (B.2) checks matching.