<!-- Crash Reporting — Heystack docs. Rendered: https://heystack.dev/docs/crash-reporting · Index: https://heystack.dev/llms.txt -->
# Crash Reporting

Heystack automatically groups, symbolicates, and surfaces native crashes from your iOS app. When your app crashes, the next launch captures the crash report and sends it to Heystack — no manual collection or on-device symbolication required.

## How it works

1. **Capture** — the Heystack iOS SDK (via its crash reporter) captures the crash on the next launch and sends it as a structured event to Heystack's ingest endpoint.
2. **Group** — Heystack groups crashes by a stable signature derived from the crashing stack frame addresses relative to each binary image's load address. The same crash on different devices, across app versions and ASLR-randomised loads, lands in the same group.
3. **Symbolicate** — if you have uploaded a dSYM symbol map for the build that crashed, the crashed thread's frames are resolved to function names, file paths, and line numbers. Without a dSYM, crashes still appear but frames show raw addresses.
4. **Read** — open your app in the [console](https://console.heystack.dev) and go to **Issues** and filter by **Crash**. Each row is a crash group with its occurrence count, affected devices, and the date it was last seen. Click a group to see individual instances with the symbolicated stack trace.

## Sending crashes

Add the Heystack Swift package (`https://github.com/heystack-hq/heystack-swift`; in Xcode, **File › Add Package Dependencies**) and link both the `Heystack` and `HeystackCrash` libraries. Start the SDK once at launch, inside your analytics-consent path, then install the crash reporter:

```swift
import Heystack
import HeystackCrash

// AppDelegate or @main, on the main thread. Both calls are safe to repeat.
Heystack.start(token: "hs_ios_…", service: "my-ios-app")
HeystackCrash.install()
```

Use your **mobile (iOS) key** (`hs_ios_…`) here — not a server key. Mobile keys are write-only and safe to ship inside a binary. Mint one under **Settings › App › Connection & keys** in the console via **"Mobile (iOS) key"**.

On the next launch after a crash, the SDK sends the report automatically. No extra code is needed.

The crash's stack and the devices it hit also appear on its issue page, under **Technical detail** (see [Console](https://heystack.dev/docs/console)).

## Uploading dSYM symbol maps

Without a dSYM, crash stack frames show raw memory addresses that are hard to read. Uploading your dSYM lets Heystack translate those addresses into function names, file paths, and line numbers.

**Upload during your release build**, before you distribute the binary, using the `heystack-dsym` CLI that ships with the iOS SDK:

```bash
heystack-dsym upload "$ARCHIVE_PATH/dSYMs" --api-key "$HEYSTACK_SERVER_KEY"
```

The path can be a single `.dSYM` bundle or a folder of them (such as an archive's `dSYMs/`). The key can also come from the `HEYSTACK_DSYM_KEY` environment variable. If the tool isn't on your `PATH`, run it from a checkout of the package with `swift run -c release heystack-dsym upload …`.

Key points:

- Use a **server key** (`sk_live_…`) for dSYM uploads — not the mobile (`hs_ios_`) key. Server keys carry elevated privileges and must never be embedded in a binary or committed to source control. Store them in your CI environment's secret vault.
- There is no app id to pass: the server key already identifies the app.
- Uploads may be at most **5 MB compressed** and **30 MB after decompression**. The CLI checks the compressed limit before sending; the service enforces both limits.
- Re-uploading a dSYM for the same build UUID is safe — it overwrites the previous copy.
- Crashes that arrive before a dSYM is uploaded are retroactively symbolicated when you view them.

## Key types at a glance

| Key type | Prefix | Used for | Safe in binary? |
|---|---|---|---|
| Mobile (iOS) key | `hs_ios_…` | Sending crash reports + telemetry from the app | Yes |
| Mobile (Android) key | `hs_android_…` | Sending OTLP telemetry from an Android app; not used by the iOS crash SDK | Yes |
| Browser key | `hs_web_…` | Browser telemetry from `@heystack/otel/web`; cannot upload dSYMs | Yes (client bundle) |
| Server key | `sk_live_…` | Uploading dSYM maps (CLI / CI only) | **No** |

## What you see in the console

- **Issues, filtered to Crashes** — the list of crash groups, sorted by most recently seen. Each group shows the exception type, a short message, how many times it has occurred, and how many distinct devices were affected.
- **Group detail** — click a group to see individual crash instances. Each instance shows the device model, OS version, app version, and the symbolicated (or address-only) stack trace of the crashed thread.

## Troubleshooting

**Crashes appear but frames show addresses, not function names.**
Upload the dSYM for the build that produced those crashes (see above). The UUID embedded in the crash report must match the UUID of the dSYM.

**No crashes appearing at all.**
Check that `Heystack.start(token:service:)` and then `HeystackCrash.install()` run at launch, before any other setup that might crash. The report is sent on the *next* launch — so if the app is force-quit rather than crashing, no report is generated.

**"forbidden: a server key (sk_live_…) is required to upload dSYMs" error from the CLI.**
You passed a mobile or browser key (`hs_ios_…`, `hs_android_…` or `hs_web_…`) to `heystack-dsym upload`. Switch to a server key (`sk_live_…`).
