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

13 SDK API

The same surface on every platform, so cross-platform layers (React Native, Flutter) can bridge it one to one. Each SDK documents its own idioms (names in the language’s style, builders, async variants); the behavior is this table.

Call Does
start(key, options) Starts the SDK. Crashes, launches, screens, network and lifecycle are on by default
setUser(idHash, attributes) / clearUser() Identifies the user with a hash the app provides (user.hash), at least 16 characters (section 11)
setAttribute(key, value) A global attribute added to every record
log(level, message, attributes, logger?) A log record (section 13.6)
recordError(error, attributes, fingerprint?) A handled error (section 6.2)
addBreadcrumb(message, attributes) A manual breadcrumb next to the automatic ones
startSpan(name) A custom span; children nest under the current span
trackScreen(name) / reportFullyDrawn() Manual screen names and TTFD (section 8.2)
setFeatureFlag(name, variant) A feature flag evaluation (feature_flag.key, feature_flag.result.variant), attached to the session and to crashes (section 13.4)
trigger(name, attributes) Fires the trigger event:<name>: families waiting for it send the minutes before it (15.4)
setConsent(granted) Pauses or resumes collection; withdrawing consent drops the queue and the store (section 13.5)
setLiveInspection(allowed) Optional: allows live inspection on this device for the app’s team, off by default and kept across launches (section 16)
flush() Sends what is queued

Every SDK accepts at least:

Option Default Section
endpoint Derived from the key 1.3
installationId On 2.3
firstPartyHosts Empty 8.4
replay.enabled Off, until the app turns replay on 10.2
replay.textMasking all (or inputs) 10.3
replay.touches show (or hide) 10.3
replay.maskClasses, replay.unmaskClasses, replay.hideClasses Empty 10.4
redact None 11.1
battery Off on iOS, on on Android 7.9
logBridge, logBridge.minLevel, logBridge.subsystems (Apple) Off; warn; the app’s subsystems 13.7

replayMask, replayUnmask and replayHide on a view instance, plus the apsio-mask, apsio-unmask and apsio-hide tokens as words of the accessibility identifier or view tag (section 10.4). Declarative UI frameworks expose them as modifiers (for example SwiftUI .apsioReplayMask() and the equivalent Jetpack Compose modifiers).

A debug-only mask preview SHOULD show what replay records, the same way on every platform:

  • the call is showReplayMaskPreview(on): it turns an overlay on or off over the app’s windows (on Android, every window replay walks, following the resumed activity);
  • the overlay fills with 35% opacity and strokes 1 point (1 dp) each node’s area: red (#FF3B30) where replay.mask decides masked, containers included; grey (#555555) where it decides hidden, including web views, maps, video and the keyboard where the platform can see it; and a green outline over the areas whose touches are recorded (10.3);
  • it works whether or not the session records replay, or replay was started, with the app’s masking options and the policy’s tightening (10.5);
  • it is never drawn in a release app. On iOS it is compiled only in debug builds; on Android, whose library ships as one release artifact, the call exists and does nothing unless the app is debuggable (FLAG_DEBUGGABLE). The overlay itself is never captured.

A breadcrumb is a log record with event name apsio.breadcrumb and apsio.breadcrumb.category (navigation, network, user, lifecycle, manual). SDKs keep the last breadcrumbs of the session in memory and on disk, so a crash report on the next launch can reference them by session and time.

setFeatureFlag(name, variant) records the variant of a flag the app evaluated:

  • MUST send a log record with event name feature_flag.evaluation, carrying feature_flag.key (the name) and feature_flag.result.variant (the variant).
  • MUST from then on add feature_flag.<name> set to the variant to every record it sends, like a global attribute (setAttribute), so the session’s records carry the flag. A later call for the same name replaces the variant.
  • MUST keep those attributes with the context of a crash report, so the crash the next launch sends (section 6.1) carries the flags of the process that crashed.
  • A backend reads a session’s flags from its records: the evaluation records, or feature_flag.<name>. Names the OpenTelemetry and OpenFeature conventions use under feature_flag. are not flags: key, variant, version, provider and anything under result., provider., context., set. or evaluation.. An app SHOULD NOT give a flag one of those names.
  • The vector sessions/sdk-feature-flags checks it.

setConsent(granted) records the app user’s choice (section 11):

  • setConsent(false) MUST stop collection at once and drop everything not yet sent: the queue, the store with everything held in it (15.6), the batches on disk and the uploads handed to the operating system.
  • The choice MUST persist across launches: a launch after consent was withdrawn starts withdrawn, until the app calls setConsent(true). An app that asks for consent before it starts the SDK withdraws it from the first launch by calling setConsent(false) right after start.
  • While consent is withdrawn the SDK records nothing: no records, spans, metrics or session summaries. A crash, hang or exit of a run that ended with consent withdrawn is never reported, even once consent returns.
  • setConsent(true) MUST resume collection with a new session, whose session.start carries the session in progress as session.previous_id (section 3.1). The session during which consent was withdrawn reports nothing more: no summary and no end.
  • Withdrawing consent does not delete what was already sent. A backend offers erasure by user.hash for that.
  • The vectors privacy/sdk-consent-pause-resume and privacy/sdk-consent-persists check it.

A log record names where it came from and what was on screen:

  • The logger is the record’s InstrumentationScope name. log(level, message, attributes, logger) MUST put logger, when the app gives one, as the scope name of the record; without one, the SDK’s own scope. A bridge from a platform logger (13.7) MUST use that logger’s name as the scope name: the os_log / Logger category on Apple platforms, the Timber tag on Android (timber when the record has none), console for JavaScript’s console (section 14). No attribute repeats it.
  • The screen. Every log record the SDK writes MUST carry app.screen.name, the screen shown when the record is created (8.6), and none before the first screen of the process is shown. A record from the background carries the last screen shown.
  • A backend reads a record’s logger from its scope name, and its screen from app.screen.name, for filters and breakdowns.
  • The vector logs/sdk-logger-and-screen checks it, and logs/scope-kept that a backend keeps the scope name.

A log bridge forwards the app’s own platform logs as Apsio log records, so the logs a team already writes reach Apsio without a call to log(). Each platform has one:

Platform Bridge
Apple The current process’s Logger / os_log entries, read from OSLogStore(scope: .currentProcessIdentifier)
Android A Timber tree the app plants. Logcat is not read
React Native console.debug, console.log, console.info, console.warn and console.error, wrapped (section 14). The bridges of the native SDKs are their own options

Turning it on.

  • A bridge MUST be off by default: the start option logBridge turns it on (13.1).
  • It forwards the entries written after start, and only the app’s own process. It never forwards the history before start or another process’s entries. On Android, a tree planted before start forwards nothing until then, and buffers nothing. On React Native the JS bridge begins at the JS start, even when the native SDK started earlier.

The level floor.

  • logBridge.minLevel is the least severity forwarded, warn by default.
  • An entry under it is not bridged: it is neither written nor counted as dropped.
  • The floor MUST be checked before any other work, so an entry under it costs the app only that check. On Android the tree answers Timber’s isLoggable, and Timber formats nothing it refuses.

Severity. Each platform level maps to one severity number. severity_text is the platform’s own name for the level. The reference function log_bridge.severity (B.2) fixes it:

severity_number Apple (OSLogEntryLog.Level) Android (Log) JavaScript console
1 (TRACE) VERBOSE
5 (DEBUG) debug DEBUG debug
9 (INFO) info INFO log, info
10 (INFO2) notice (Logger.notice, .default)
13 (WARN) WARN warn
17 (ERROR) error ERROR error
21 (FATAL) fault ASSERT (wtf)

Apple’s undefined level is not bridged. Devices keep Apple’s debug entries in the store only when logging is configured to, so that level rarely reaches a bridge, and the warn floor leaves it out anyway.

What a record carries.

  • The body is the entry’s message, cut to 4 KiB as 1.6 cuts a string.
  • The scope name is the logger’s name (13.6).
  • On Apple platforms, the subsystem is in apsio.log.subsystem.
  • On Android, a Throwable that Timber passes becomes exception.type, exception.message and exception.stacktrace, as for log(). Timber appends the Throwable’s stack trace to the message (a newline, then the stack trace), so the body is the message without that suffix. When the call has no message (Timber.e(t)), the body is the Throwable’s toString(): Type: message, or Type when it has no message. The stack trace is never carried twice.
  • On React Native, the body is what the console prints, as the reference function log_bridge.format (B.2) fixes it, on the base of the WHATWG console’s Formatter. The vector defines it, not any platform’s console. It applies to the JS bridge only: OSLog and Timber hand the native bridges a finished string.
    • printf substitution in a first string argument (%s, %d, %i, %f, %o and %O; %c takes its argument and prints nothing);
    • then the other arguments, joined by single spaces;
    • an Error as Name: message followed by its stack;
    • other objects as JSON, with [Circular] and [Function name], and an Error inside an object as the string Name: message.
  • A record has no attributes beyond these and those every record carries.
  • The record’s time is the entry’s own time, under the clock rules of section 5.

Privacy. A bridged record MUST go through the same redaction as a record from log() (the start option redact, section 11), before it is written to the store (15.2). Apple’s private values stay <private>, as the store gives them: a bridge never turns them back into text.

Where it goes. A bridged record is in the logs family (15.1): the policy’s modes, capture and rules apply to it as to any log record. On React Native, a bridged console.error is a log record only, never an issue or a handled error (6.2).

Limits.

  • An SDK MUST NOT write more than 50 bridged records a second, with a bucket of 100, or more than 1,000 in a session.
  • Both are counted on the entries’ own times, not on when the SDK reads them. The bucket refills from the latest entry time seen, dropped entries included: an entry older than one before it refills nothing.
  • The 1,000 belong to the session the entry’s time falls in. Entries read on the move to the background belong to the session that was in front, even when the read ends after a new one started.
  • An entry stamped up to 1 second before the current session’s start, with no earlier session to take it, belongs to the current session: a clock the platform’s logger or a framework reads can trail the session’s by a few milliseconds (OSLog’s entry times, a JavaScript Date.now() taken before the native start). An older one is not bridged: neither written nor counted as dropped.
  • Entries over a limit are counted, not written. The session summary carries their number as apsio.session.log_bridge_dropped (3.4) when any were dropped.
  • On React Native, the JS bridge and a native bridge share the native SDK’s limits and its one dropped count: the limits apply where the record is written.
  • The reference function log_bridge.admit (B.2) fixes which are written.

No loops, no duplicates.

  • A bridge MUST NOT forward the SDK’s own logs: the Apple bridge skips the SDK’s subsystem, and the Timber tree skips the SDK’s tag. The React Native SDK writes its own messages to the original console, never through the wrapper.
  • A native bridge MUST skip the platform’s channel for JavaScript’s console: on iOS, the subsystem com.facebook.react.log with category javascript; on Android, the tag ReactNativeJS. JS lines then come from the JS bridge only.
  • A line the app sends both to log() and to a bridged logger arrives twice. An SDK’s docs say so.

Apple: what is read, and its cost.

  • MUST read only OSLogEntryLog entries of the app’s own subsystems. It skips subsystems starting with com.apple., the SDK’s own, and entries with no subsystem (NSLog, mostly framework output).
  • MAY take an allowlist, logBridge.subsystems, which replaces that default.
  • Entries the subsystem filter skips are never candidates: neither written nor dropped.
  • MUST read on from the last entry read, with a level and subsystem predicate, so no entry is forwarded twice: forward from OSLogStore.position(date:) at that entry’s time where the platform honors it, else forward from the store’s start, skipping the entries up to and including the last one read (iOS ignores the position). Entries at that time already read are skipped (times are not unique).
  • MUST bound each read by the wall clock: opening the store may take at most 3 seconds and the scan at most 2. A read past either is cut. A cut read forwards the entries it reached; the rest wait for the next read, which goes on from the last entry forwarded. The session summary then carries apsio.session.log_bridge_incomplete = true (3.4). apsio.session.log_bridge_dropped still counts only the entries over the limits.
  • The next read tries again: opening the store has a fixed cost of about a second, which a loaded device can stretch past the bound once. After 2 cut reads in a row the bridge MUST stop reading for the rest of the process, since a read from the store’s start would be cut at the same depth every time. Its unread entries are then not forwarded, and each later session of that process carries apsio.session.log_bridge_incomplete too.
  • MUST read off the main thread.
  • The store can be read only while the app is in the foreground, and opening it can take about a second, so the bridge MUST read in the foreground only: every 5 minutes, and when the app is about to leave the foreground (UIKit’s willResignActive, while the app is still active). It never reads in the background.
  • MUST NOT read more often than every 30 seconds, the read before leaving the foreground included: a Control Center pull followed by the move to the background reads once.
  • Entries written after the last read wait for the next read in the foreground. The store holds only the current process’s entries, so if the process ends in the background they are not forwarded.
  • Apple’s bridged records therefore arrive up to 5 minutes late, or at the next foreground, with their own times. A trigger or rule on one fires when it is read, and its window counts from the entry’s time (15.4), so the minutes before it are still released.

React Native: the wrapper.

  • MUST call the original console method first, with its arguments untouched (LogBox and RedBox read them).
  • MUST NOT throw: a failure in the bridge drops that record and nothing else.

The vectors logs/bridge-severity, logs/bridge-admit and logs/bridge-format check the three functions.