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

6 Crashes and exits

A process cannot reliably send its own crash. The report is written to disk when the crash happens and sent by the next launch. Some terminations leave no report at all, so the profile uses three sources: the crash handler, the platform’s own exit records, and inference on the next launch.

  • MUST report a crash as a log record with event name app.crash, sent on the next launch.
  • MUST carry the crashed instance’s app.build_id, service.version, os.name, os.version and session.id as record attributes (section 2.5).
  • MUST set app.crash.id, the same on every attempt to report that crash (section 4.3).
  • MUST set the record’s timeUnixNano to the time of the crash, not the time of the report.
  • SHOULD set exception.type (the exception class, or the signal and Mach exception, for example EXC_BAD_ACCESS (SIGSEGV)) and exception.message.
  • MUST put the crashing thread’s raw stack in exception.stacktrace. Symbolication happens on the backend.
  • For a native crash, the stack has one frame per line, with the binary image name and the instruction address, and the SDK MUST include the binary images the stack refers to (name, UUID or build id, load address, architecture) in the attribute apsio.crash.images, a JSON string, so the backend can symbolicate. Each image SHOULD also say whether it belongs to the app, in in_app (section 6.5).
  • For an uncaught exception in a managed runtime (the JVM or ART), the stack is the runtime’s own stack text, with its causes, as the runtime prints it. There are no binary images, so apsio.crash.images MUST be []. The backend deobfuscates the stack with the R8 mapping that app.build_id names (section 2.1).
  • MAY attach the full native report (all threads, registers) as a separate upload referenced by apsio.attachment.id.
  • SHOULD record the termination category when the platform gives one, in apsio.crash.termination_category (for example badAccess, abnormal, watchdog, taskTimeout from MetricKit on iOS 27).
  • A handled, non-fatal error is a log record with exception.type, exception.message and, when available, exception.stacktrace, at severity ERROR.
  • MAY carry apsio.error.fingerprint, a string set by the app that replaces the backend’s default grouping for that error, scoped per app: two apps that send the same value get two groups. It does not apply to crashes.
  • An Android ANR is reported as the device.anr event of opentelemetry-android, or from ApplicationExitInfo on the next launch (6.4).
  • An iOS hang (the main thread blocked past the SDK’s threshold, or a MetricKit hang diagnostic) is a log record with event name apsio.hang, the main thread’s stack in exception.stacktrace and its duration in apsio.hang.duration (milliseconds).
  • An apsio.hang record MUST carry apsio.hang.source:
    • live: the SDK saw the hang while the app ran, in the session it belongs to. The record carries that session’s session.id, and its time is the moment the hang began.
    • metrickit: read from a MetricKit hang diagnostic, which arrives up to a day later and can describe a hang the SDK also saw live.
  • Android’s hangs are seen while the app runs, so they are live: an Android SDK that adds apsio.hang.source to device.anr or apsio.hang sets live.
  • A live detector on iOS SHOULD watch the main thread from another thread, only while the app is in the foreground and not under a debugger, with a threshold of 250 ms. It records one stack per hang, taken while the main thread is blocked, and the hang’s duration once the main thread runs again.
  • Unfinished hangs. The process can be killed during a hang (the system’s watchdog, a force quit), so the hang never ends. A live detector SHOULD write the hang to disk once its stack is taken, with the binary images it refers to, and update its duration while it lasts. The next launch sends it as apsio.hang with apsio.hang.source = live, apsio.hang.unfinished = true, apsio.hang.duration the time seen until the last update (a lower bound), the record’s time when the hang began, and the session and release of the process that hung as record attributes (2.5). It counts in hang rates like any live hang; a backend MUST NOT read its duration as exact.
  • Launch hangs. A live hang that begins before the process first becomes active is a launch hang: the main thread is still starting the app, which app.start measures (8.1). On iOS the first activation is the process’s first app-level UIApplication.didBecomeActiveNotification, which scene-based apps also post. A live apsio.hang record of a launch hang MUST carry apsio.hang.phase = launch; other hangs carry no apsio.hang.phase.
    • A hang’s phase is set by the time it begins, the record’s time. A live hang cannot span the first activation, since its notification is posted on the main thread that the hang blocks.
    • The detector reads the app’s state when it installs. If the app is already active (the SDK started after the first activation), no hang it sees is a launch hang. Otherwise the hangs that begin before the first activation are, the first activation of a prewarmed or background launch included. A cross-platform SDK started from its JavaScript runtime usually installs after the first activation, so it reports no launch hangs.
    • iOS tells whether it launched the process in the background (apsio.app.launch.reason = background, 8.1) only once the launch is done. A detector that watches until then MUST NOT send a hang from a launch that turns out to be in the background, and removes the unfinished hang it wrote for it. An unfinished hang from a process killed before the SDK knew is sent as a launch hang: the SDK cannot tell a user’s launch from a background one there.
    • Returns from the background, after the first activation, are not launch.
    • An unfinished launch hang keeps its phase: the detector writes the phase to disk with the hang, and the next launch sends it. A launch that the system’s watchdog ends is such a hang, and its termination is a watchdog exit (6.4).
    • metrickit records carry no phase: a MetricKit diagnostic has no time per hang to compare with the first activation.
    • device.anr carries no phase: an ANR at launch is still an ANR. An Android SDK that adds a sub-second live apsio.hang follows this rule, with the first resumed activity as the first activation.
    • The function hang.phase (B.2) pins the boundary.
  • A backend MUST compute hang rates and join hangs to their session’s screens from live records only, so that a hang seen both ways counts once, and MUST leave launch hangs (apsio.hang.phase = launch) out of both: app.start already measures a slow launch, and the first screen is not shown yet, so a join would put the hang on it wrongly. Launch hangs feed launch diagnostics, with their stacks. metrickit records feed duration distributions and stacks. A record without apsio.hang.source, from an SDK older than this rule, is metrickit when its os.name is iOS or iPadOS and live otherwise.

iOS kills apps without a crash report for memory (jetsam), watchdog timeouts, background task expiry and thermal pressure. Android has low-memory kills and ANR exits. Other terminations are not failures: the user quit the app, an update replaced it, or the system evicted it while it was in the background. The profile names every reason with one closed list, so both platforms report the same values.

apsio.exit.reason is one of these values, and no other:

Value Kind Meaning
crash failure The platform says the app crashed, but there is no crash report: iOS’s bad access, illegal instruction and abnormal exits, or Android’s REASON_CRASH_NATIVE with no tombstone
memory failure Killed for memory while the user could see the app, or over the platform’s per-app memory limit: iOS’s memory resource limit (jetsam), or Android’s REASON_LOW_MEMORY with an importance of visible or higher
watchdog failure The system’s watchdog ended an app that did not respond in time (iOS)
background_task_timeout failure A background task outlived its allowance (iOS)
cpu failure Over the platform’s CPU limit (iOS)
locked_file failure Suspended while holding a file lock (iOS)
thermal failure Ended for thermal pressure
anr failure Ended after an ANR (Android’s REASON_ANR)
signal failure Killed by a signal not identified as a crash (Android’s REASON_SIGNALED)
unknown failure Any other termination without a crash report, including platform reasons not listed here (for example Android’s REASON_EXCESSIVE_RESOURCE_USAGE)
memory_pressure not a failure Evicted for memory while in the background: iOS’s memory pressure exits, or Android’s REASON_LOW_MEMORY below visible importance
user_quit not a failure The user ended the app: on Android every REASON_USER_REQUESTED (a force stop, a removal from Recents, a task killer the user installed) and REASON_USER_STOPPED; on iOS, inferred (below). A removal from Recents happens in the background, so its apsio.exit.foreground is false
app_update not a failure An update of the app replaced the process: Android’s REASON_PACKAGE_UPDATED, or inferred
os_update not a failure The device updated its operating system: inferred
normal not a failure The app exited normally, or the platform ended it for a reason that is not a failure: Android’s REASON_EXIT_SELF, REASON_PERMISSION_CHANGE, REASON_DEPENDENCY_DIED, REASON_FREEZER, REASON_PACKAGE_STATE_CHANGE and REASON_OTHER

With the reason, the SDK sets:

  • apsio.exit.source: platform when read from the platform, inferred otherwise;
  • apsio.exit.foreground: whether the app was in the foreground;
  • apsio.exit.platform_reason SHOULD, when the source is platform: the platform’s own name for the reason, without free text: on Android the ApplicationExitInfo constant and, for a signal or an exit code, its status (REASON_SIGNALED/9); on iOS the MetricKit counter or case (cumulativeBadAccessExitCount). It keeps what the closed list folds together, for example Android’s low-memory kills that the platform reports as SIGKILL. An inferred exit has none;
  • apsio.exit.memory.footprint MAY: the last memory footprint the SDK or the platform recorded for the process before it ended, in bytes. It can be minutes old. An unknown footprint is omitted, never sent as 0.
  • SHOULD report a termination of kind failure as a log record with event name app.abnormal_exit, sent on the next launch, with the attributes of 6.1’s second bullet and those above. Its session’s final summary has outcome abnormal_exit (section 3.4).
  • MUST NOT send app.abnormal_exit for a reason of kind not a failure. The next launch instead sends the session’s final summary with outcome exited and the exit attributes above.
  • MUST NOT send app.abnormal_exit for a session that has an app.crash, whatever its reason or source (a late platform memory record included); the crash report wins. A backend that gets one anyway leaves it out of its counts and issues. That session’s final summary, outcome crashed, SHOULD carry apsio.exit.reason = crash and no other exit attribute.
  • Termination counts from MetricKit may carry any value (section 7.3).
  • SHOULD read the platform first:
    • on iOS 27 and later, MetricKit’s DiagnosticReport (a memoryException is a first-party out-of-memory record) and ForegroundTerminationMetric / BackgroundTerminationMetric;
    • on iOS 15 to 26, MXCrashDiagnostic, MXHangDiagnostic and MXAppExitMetric;
    • on Android 11 and later, ApplicationExitInfo (with ANR traces; native tombstones from Android 12).
  • MAY infer when the platform says nothing for the previous session, in this order:
    • app_update when the app’s build (app.build_id) changed since the session;
    • os_update when the operating system’s version or build changed and the device restarted since the session. On iOS a change of the operating system’s version or build implies the restart, so an SDK may infer os_update from that change alone, without reading the system boot time;
    • user_quit when the session ended in the background after the platform announced the app’s termination (iOS’s applicationWillTerminate). A process suspended in the background gets no such notice, so an inferred user_quit undercounts;
    • otherwise, when the session ended in the foreground with no crash, no normal termination and no debugger attached: memory if the platform’s low-memory signal was observed in the session (iOS’s memory warning or critical memory pressure; Android’s onTrimMemory at TRIM_MEMORY_RUNNING_LOW or above, or, from Android 14, which no longer delivers it, ActivityManager.MemoryInfo.lowMemory), else unknown.
  • A platform record takes precedence over an inference for the same session.
  • On iOS a platform record can arrive late: MetricKit delivers the diagnostic of an ended process (a MemoryExceptionDiagnostic, for example) on a later launch, possibly after that launch has already sent an inferred app.abnormal_exit and the session’s final summary. The SDK then:
    • MUST still send the platform record, an app.abnormal_exit of its own with source platform, carrying the session’s id and the ended instance’s attributes (6.1’s second bullet), unless the session has an app.crash (Records, above);
    • MUST send the session’s final summary again, with outcome abnormal_exit and the platform record’s exit attributes, when it still holds that session’s saved state (the previous process’s session, the usual case) and the session has no app.crash, whose report wins. For an older session it sends the platform record only;
    • MUST NOT hold back the inferred record or its summary to wait for a platform record.
  • MetricKit diagnostics join their session through their process id (environment.pid in the Swift API), matched with the process id the SDK recorded with the session. A diagnostic with no process id, or with one that matches no session, is sent without a session.
  • A backend joins the two records on session.id and app.installation.id within the app, so a record naming another install’s session never changes it; it matches a session’s summaries by session.id within the app (3.4). When it has both records, it MUST keep the platform record, leave the inferred one out of its counts, and take the session’s exit attributes from the platform summary when one comes: the session’s termination counts once, with the platform’s reason.

Example of a crash sent by the next launch (OTLP/JSON, trimmed):

{
"eventName": "app.crash",
"timeUnixNano": "1759500000431000000",
"severityNumber": 21,
"attributes": [
{ "key": "exception.type", "value": { "stringValue": "EXC_BAD_ACCESS (SIGSEGV)" } },
{ "key": "app.crash.id", "value": { "stringValue": "4c1e8a52-0d2f-4f0b-9a8e-7f6d1c2b3a49" } },
{ "key": "app.build_id", "value": { "stringValue": "8124C1A2-6E0B-3F51-9D57-1B2E7C4A9B07" } },
{ "key": "service.version", "value": { "stringValue": "4.12.0" } },
{ "key": "session.id", "value": { "stringValue": "7f3c9b02-5d1e-4a8b-9c0f-2e6a1d4be19a" } },
{ "key": "log.record.uid", "value": { "stringValue": "01J9ZQ3W1V8M6K2T4R7N5C0B3D" } }
]
}

An image is in-app when it ships inside the app: the app’s own code, and the frameworks and libraries bundled with it, whoever wrote them. A backend groups crashes by their in-app frames (section 6.1) and asks for symbols for in-app images, so the difference matters before any symbols are uploaded.

  • Each entry of apsio.crash.images SHOULD carry in_app, a boolean, decided on the device from the path the image was loaded from. Paths are compared by whole path components (Shop.app2/Shop is not inside Shop.app).
  • On Apple platforms, in_app is true for an image inside the app’s bundle: the main executable, Xcode’s <App>.debug.dylib and __preview.dylib in debug builds, and the frameworks and libraries under the bundle. The bundle is the main bundle’s path up to and including its first component that ends in .app, so an app extension (Shop.app/PlugIns/Widget.appex, Shop.app/Extensions/Share.appex) uses its containing app, which it loads frameworks from, and macOS and Mac Catalyst bundles (Shop.app/Contents/Frameworks) work the same way. The executable’s path gives the same root (Shop.app/Contents/MacOS/Shop). Without a .app component (a test bundle run by xctest, a command-line tool), the root is the bundle’s path itself, or the executable’s directory when only the executable’s path is known.
  • The bundle is that of the process the images were loaded in (for a crash, recorded with the crash), not the reporting launch’s: an update or a reinstall moves the bundle to a new container. Paths are compared as text, not resolved (the crashed install may be gone, and resolving does I/O), after removing a leading /private followed by /var/ or /tmp/ on both sides, since the loader and the bundle APIs can report the same directory with or without it.
  • On Android the decision uses the app’s package name, not the directories of the launch that reports the crash: an update moves the install directory, and the crashed process’s paths cannot be resolved afterwards. A trailing (deleted) (a file replaced while the process ran) is removed first. in_app is true for:
    • a shared library (.so) or an APK (.apk) in the package’s install directory: under /data/app/ or /mnt/expand/<volume>/app/, optionally inside one ~~<random>== directory, a directory whose name starts with <package>- (/data/app/~~Qm9x==/com.example.shop-Zk4p==/lib/arm64/libshop.so);
    • a shared library loaded straight from one of those APKs, when native libraries are not extracted (AGP’s default). Its image is the library, not the APK: its path is <apk path>!<library>, as a tombstone’s frames show it (/data/app/~~Qm9x==/com.example.shop-Zk4p==/base.apk!libshop.so, or a split APK’s split_config.arm64_v8a.apk!libshop.so), and its name is the library’s file name, its build id and load address the library’s own. It is in-app when that APK is the package’s and the part after the ! is a shared library;
    • a shared library under one of the package’s data directories: /data/data/<package>, /data/user/<user>/<package>, /data/user_de/<user>/<package>, and the same two under /mnt/expand/<volume>/ (libraries extracted at run time).
  • Every other image is false: on Android the runtime’s compiled code (.odex, .vdex, .oat, .art), anonymous and memory-file mappings ([anon:…], /memfd:…), the system’s partitions (/system, /system_ext, /vendor, /product, /apex) and other packages, such as WebView’s.
  • On Apple platforms the path is used on the device only, and the SDK MUST NOT add it to the image: the bundle’s location holds a per-install identifier.
  • A backend MUST use in_app as sent when it is present, whether or not symbols were uploaded for the image. When it is absent, from an SDK older than this rule, the backend decides its own way; this profile does not define how.
  • The vector crashes/image-in-app checks the decision (appendix B.2).