# Crash reporting
Source: https://sovaria.in/docs/crash-reporting

See the errors your users hit, grouped into issues with readable stacks, the calls that led up to them and the release, plus crash-free sessions and users for every release.

Install the SDK's crash reporter once and every crash is reported to your project: uncaught errors in browsers and React Native, uncaught exceptions **and native crashes** on iOS and Android, and anything you `capture` yourself. Reports are grouped into **issues** (the same bug is one issue across releases, line changes and ids), each with how often it happened, how many users it hit, the first and latest release, the last 50 reports in full and a 24-hour trend.

JavaScript:
```js
import { createClient } from '@sovaria/sdk'

const sov = createClient('https://<ref>.sovarias.in', '<anon key>')
sov.crashes.install({ release: '2.4.1', environment: 'production' })   // also starts a release-health session

try {
  await checkout(cart)
} catch (e) {
  sov.crashes.capture(e, { tags: { step: 'pay' }, extra: { items: cart.length } })
}
sov.crashes.addBreadcrumb({ category: 'ui', message: 'tapped Pay' })
```

Swift:
```swift
// AppDelegate / @main init, as early as possible
sov.crashes.install(release: "2.4.1 (88)", environment: "production")
// Uncaught NSExceptions, fatal signals (SIGSEGV, SIGBUS, SIGABRT, SIGILL, SIGFPE, SIGTRAP: force-unwraps,
// array bounds, stack overflows), Mach exceptions and MetricKit crash/hang diagnostics. Written to disk while
// the app dies by an async-signal-safe handler, sent on the next launch.
sov.crashes.capture(error, tags: ["step": "pay"])
```

Kotlin:
```kotlin
// build.gradle.kts: implementation("in.sovaria:sovaria-android:1.0.0")   // NDK crash library
// Application.onCreate
sov.crashes.installAndroid(this, release = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})")
// Uncaught exceptions (even out of memory), NDK crashes (C/C++ signals, with library build ids), ANRs from a
// main-thread watchdog, plus ANRs, native crashes and low-memory kills Android 11+ recorded for earlier launches.
sov.crashes.capture(e, tags = mapOf("step" to "pay"))
```

Flutter:
```dart
// flutter pub add sovaria sovaria_flutter
await SovariaFlutter.installCrashReporting(sovaria, release: '2.4.1+88');
// FlutterError.onError, PlatformDispatcher.onError, the root isolate, and native iOS/Android crashes
// and ANRs, all in one call. Handlers you set before keep running.
```

React Native:
```js
// npm install @sovaria/sdk @sovaria/react-native && cd ios && pod install
import { installCrashReporting } from '@sovaria/react-native'

installCrashReporting(sov, { release: '2.4.1 (88)' })
// Fatal JS errors are written to disk synchronously (sent next launch); iOS signals, Mach exceptions and
// NSExceptions; Android NDK crashes, ANRs and exit records.
```

CLI:
```bash
sov crashes list --release 2.4.1 --platform ios   # open issues, newest first
sov crashes show <fingerprint>                     # stack, breadcrumbs, releases, daily counts
sov crashes releases                               # crash-free sessions and users per release
sov crashes resolve <fingerprint>
```

(Diagram: From a crash in the app to a readable issue — Symbolication happens when the report arrives, with the files you uploaded for that release.)

## What a report contains

| Field | Where it comes from |
|---|---|
| Error type, message and stack | The error. The top five frames (without line numbers, query strings, ids or addresses) group reports into issues; pass `fingerprint` to group your own way. |
| Kind | `exception`, `native` (a fatal signal or Mach exception on iOS, an NDK crash on Android, MetricKit), `anr` (Android: the watchdog or the system's record), `hang` (iOS), `oom` (low-memory kill). |
| Breadcrumbs | The last 50: every Sovaria call the SDK made (method, path, status; no bodies or tokens) and your own `addBreadcrumb`. |
| User | The signed-in app user, taken by the server from the request's token (an app can't claim another user). Anonymous otherwise. |
| Release, environment, platform, device | What you pass to `install`, plus OS and device details. iOS native reports carry the loaded binary images (name, UUID, load address, size); Android native frames carry each library's build id. Native crashes also record the signal, its code and the fault address, and the Mach exception on iOS. |
| Tags and extra | Whatever you pass to `capture`; fields named like passwords, tokens, keys or cookies are removed, and NUL characters are stripped before storage. |

## Readable stacks: source maps, R8 mappings, dSYMs, NDK symbols

Minified JavaScript, R8-obfuscated Android code and raw iOS addresses are turned back into your source when the report arrives, using the debug files uploaded **for that release** (use the same release string in the app and the upload). The stored issue shows the readable stack, with a switch to see the frames as the app sent them.

Everything at once:
```bash
# Finds dSYMs, unstripped NDK libraries, R8 mappings and JS / Hermes bundle maps under the paths
sov crashes upload-symbols ios/build/MyApp.xcarchive android/app/build/outputs/mapping \
  android/app/build/intermediates/merged_native_libs dist --release "2.4.1 (88)" --dry-run   # then without --dry-run
```

Web / React Native:
```bash
npm run build                                   # with sourcemap: true
sov crashes sourcemaps upload ./dist --release 2.4.1
# each dist/assets/index-4f2a.js.map is stored as ~/assets/index-4f2a.js; use --url-prefix if the app isn't at the root
```

Android (R8 / ProGuard):
```bash
./gradlew assembleRelease
sov crashes mapping upload app/build/outputs/mapping/release/mapping.txt --release "2.4.1 (88)"
```

iOS (dSYM):
```bash
# After archiving (Xcode build phase or CI): every dSYM in the archive
sov crashes dsym upload ./build/MyApp.xcarchive/dSYMs
```

- **Source maps** map each frame to the original file, line, column and function name (index maps with sections too). Frames of a minified bundle **without** a map keep their line:column when grouping, so two different bugs in one bundle stay two issues.
- **R8 / ProGuard** mappings restore class, method, file and line, including methods R8 inlined (they come back as separate frames).
- **dSYMs**: only the function symbol table leaves your machine (the CLI reads it from the DWARF file); frames get the function and offset. Limits: no file:line yet, and Swift names stay mangled (`swift demangle` reads them). Symbols are matched by image UUID, so no release is needed.
- **Android NDK libraries**: `upload-symbols` reads the unstripped `.so` files (`app/build/intermediates/merged_native_libs`; in a Flutter project `build/app/intermediates/merged_native_libs`), uploads only their function symbols keyed by GNU build id (the stripped copy of the same library is skipped), and native frames get the function and offset, also for libraries loaded straight from the APK. No release is needed.
- **React Native (Hermes)**: frames like `at onPress (address at index.android.bundle:1:9174)` use the bundle's composed source map (`index.android.bundle.map`, uploaded as `~/index.android.bundle`).
- Obfuscated Flutter builds (`--split-debug-info`) aren't symbolicated on the server yet: reports are tagged `dart_obfuscated` with the build id; run `flutter symbolize` on the stack.
- The console's **Debug files** tab lists what is uploaded and the storage used; uploads are gzip chunks, so large mappings work. `upload-symbols` skips dSYM and NDK symbols already uploaded unchanged, so running it on every build only sends what changed.

## Release health

`install` starts a **session** per page load or app launch, and marks it crashed (uncaught or fatal) or errored (first handled error) once. **Release health** shows, per release: sessions, crash-free sessions, users, crash-free users and adoption, plus a daily crash-free line. Users are counted by the signed-in user or an anonymous id kept on the device (stored hashed). Turn it off with `trackSessions: false`.

## Working with issues

- In the console, **Crashes** shows a trend chart and the issues with a 24-hour sparkline; filter by status, release, app environment, platform or text. Open one for the stack, the calls before it, which releases and environments it hits, and its daily counts.
- **Resolve** an issue when the fix ships: if it happens again it reopens and is marked **Regressed** (with the release it came back in). **Ignore** hides one you won't fix.
- **Alerts**: Observability › Alerts can email the team or call a signed webhook on a **new issue**, a **regression**, or a **spike** of crash events (for the whole app, one issue, or `release:<version>`). Example: `sov alerts create --metric crash_new_issues --threshold 0 --window 15`.
- Sovariq can explain a crash ("why does checkout crash?"): its `explain_crash` tool gathers the error, the first frames in your own code, the failing calls before it, the releases it hits, and what is missing to read the stack, then proposes a fix.

## Plans and limits

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| App crash reports per month (per project) | 5,000 | 100,000 | 500,000 | 2,000,000 | 10,000,000 |
| Days app crash reports are kept | 7 days | 30 days | 90 days | 90 days | 365 days |
| App sessions counted for release health per month (per project) | 50,000 | 1,000,000 | 5,000,000 | 20,000,000 | 100,000,000 |
| MB of source maps, ProGuard mappings and dSYM symbols per project | 100 MB | 1.953125 GB | 9.765625 GB | 48.828125 GB | 195.3125 GB |
| MB per debug file (uncompressed) | 20 MB | 100 MB | 100 MB | 200 MB | 200 MB |

Past a monthly limit reports (or sessions) are dropped and counted; the Crashes page shows how many. The SDKs drop duplicates within a second and send at most 30 reports a minute, and the gateway allows a limited number of reports per minute from one address and one device (Control Center › Platform › Limits), so a crash loop can't use up the month.
