# Source maps and debug symbols

> Upload source maps, dSYMs, ProGuard/R8 mappings and Breakpad symbols so stack traces show your original files, functions and lines.

Source: https://apphelm.dev/docs/source-maps

Production builds are minified, obfuscated or compiled to machine code, so a raw stack trace says `a.b(main.4f2a.js:1:20314)` or `0x1028f3a4c`. Upload the matching **source map** or **debug symbols** with each build and AppHelm shows the original file, function and line instead.

AppHelm maps frames **when you open an issue**, not when the error arrives. A map or symbol file uploaded after an error still applies the next time you look. Android and minidump stacks are the exceptions: they are also read on arrival (for grouping and unwinding), so upload those files before the build ships.

| Platform | What to upload | How |
| --- | --- | --- |
| Browser, React, Vue, Svelte, Next.js, Node | JavaScript source maps (`.map`) | A bundler plugin, `withApphelmConfig`, or `apphelm sourcemaps upload` |
| React Native | The bundle's source map, plus dSYMs and the R8 mapping | `apphelm react-native gradle` and `apphelm react-native xcode` print the build steps |
| iOS, macOS | dSYMs | `apphelm debug-files upload` |
| Android | ProGuard/R8 `mapping.txt`; Breakpad `.sym` for NDK libraries | `apphelm debug-files upload` or `POST /api/v1/symbols` |
| Native, desktop, Electron | Breakpad `.sym` files | `apphelm debug-files upload` |
| Flutter | Not supported for Dart code | See [Flutter](#flutter) |
| Python, Ruby, PHP, Go, .NET, Rust, Elixir, JVM | Nothing | These stacks already name your files and lines |

Every upload needs a **server key** with the `events:write` scope (`ahl_live_…`) for the product. Set it as `APPHELM_API_KEY` in CI; never put it in client code.

## JavaScript source maps

### Debug ids

A **debug id** is a UUID shared by a built file and its source map. AppHelm's plugins and `apphelm sourcemaps upload` add one to each `.js`, `.mjs` and `.cjs` file in the build output: a one-line snippet at the top that records the id at run time, a `//# debugId=<uuid>` comment at the end, and the same `debugId` in the map (the map's line mappings are shifted by one so positions still line up). The id is a hash of the code and its map, so the same build always gets the same id. A file that already has a debug id, from sentry-cli or a Sentry bundler plugin, keeps it.

When an error happens, the browser, Node and React Native SDKs send the debug ids of the files in its stack (up to 20). AppHelm finds each file's map in this order:

1. The map uploaded with that **debug id** (the newest, if there are several).
2. The map uploaded for the event's **release** at the same path.
3. The release's only map with that **file name**.

With debug ids you don't need to match releases or URLs at all. Without a debug id or a release, nothing is mapped.

Paths are normalised before matching: the origin, query string, fragment and a leading `~` are dropped. `https://cdn.example.com/assets/app.js?v=3`, `~/assets/app.js` and `/assets/app.js` are the same file.

### Set it up in your build

Pick your bundler. The plugins run after a production build, add debug ids, and upload each map to `POST /api/v1/sourcemaps`. They read `APPHELM_API_KEY`, `APPHELM_PRODUCT_ID` and `APPHELM_RELEASE` from the environment unless you pass them.

Next.js — next.config.mjs:
```js
import { withApphelmConfig } from "@sansavision/apphelm/next/config";

const nextConfig = { /* … */ };
export default withApphelmConfig(nextConfig, { productId: "prd_…", deleteAfterUpload: true });
```

React — vite.config.ts:
```ts
import { defineConfig } from "vite";
import { apphelmVite } from "@sansavision/apphelm/vite";

export default defineConfig({
  plugins: [apphelmVite({ productId: "prd_…", release: process.env.RELEASE, deleteAfterUpload: true })],
});
```

Vue / Nuxt — vite.config.ts:
```ts
import { apphelmVite } from "@sansavision/apphelm/vite";

export default defineConfig({ plugins: [vue(), apphelmVite({ productId: "prd_…", deleteAfterUpload: true })] });
```

Svelte / SvelteKit — vite.config.ts:
```ts
import { sveltekit } from "@sveltejs/kit/vite";
import { apphelmVite } from "@sansavision/apphelm/vite";

export default defineConfig({ plugins: [sveltekit(), apphelmVite({ productId: "prd_…", deleteAfterUpload: true })] });
```

JavaScript (browser) — build.mjs (esbuild):
```js
import * as esbuild from "esbuild";
import { apphelmEsbuild } from "@sansavision/apphelm/esbuild";

await esbuild.build({
  entryPoints: ["src/app.js"], bundle: true, minify: true, outdir: "dist",
  sourcemap: "linked", // or true / "external"; not "inline"
  plugins: [apphelmEsbuild({ productId: "prd_…" })],
});
```

Node.js:
```bash
# After the build, before you deploy. Works for any bundler, and for Node services.
npx @sansavision/apphelm sourcemaps upload ./dist --product prd_… --release "$RELEASE"
```

For webpack 4 or 5, or Rspack:

webpack.config.js:
```js
const { ApphelmWebpackPlugin } = require("@sansavision/apphelm/webpack");

module.exports = {
  devtool: "hidden-source-map",
  plugins: [new ApphelmWebpackPlugin({ productId: "prd_…" })],
};
```

| Bundler | Import | Notes |
| --- | --- | --- |
| Vite, Rollup | `apphelmVite` (or `apphelmRollup`) from `@sansavision/apphelm/vite` | Build only. When `build.sourcemap` is off it sets it to `"hidden"` (`enableSourceMaps: false` stops that) |
| webpack 4/5, Rspack | `ApphelmWebpackPlugin` (or `apphelmWebpack()`) from `@sansavision/apphelm/webpack` | Use `devtool: "hidden-source-map"`. Warns when `devtool` is off |
| esbuild | `apphelmEsbuild` from `@sansavision/apphelm/esbuild` | Needs `sourcemap: true`, `"linked"` or `"external"` and `write` on. Skipped when the build has errors |
| Next.js | `withApphelmConfig` from `@sansavision/apphelm/next/config` | Turns on `productionBrowserSourceMaps`. Next.js 15.4+ (webpack or Turbopack) uploads `<distDir>/static` as `/_next/static`; older versions use the webpack plugin on the client build |

### Plugin options

| Option | Default | What it does |
| --- | --- | --- |
| `apiKey` | `APPHELM_API_KEY` | A server key with `events:write` |
| `productId` | `APPHELM_PRODUCT_ID` | The product the maps belong to |
| `release` | `APPHELM_RELEASE` | Also stores the maps under this release. Optional with debug ids |
| `baseUrl` | `APPHELM_BASE_URL`, else `https://apphelm.dev` | |
| `urlPrefix` | `/` (`/_next/static` or `/_next` in Next.js) | Where the build folder is served, so paths match the URLs in stacks |
| `deleteAfterUpload` | `false` | Deletes the `.map` files after uploading, so they aren't deployed publicly |
| `dryRun` | `false` | Adds debug ids and lists what would be uploaded, without uploading |
| `failOnError` | `false` | Fails the build when an upload fails |
| `silent` | `false` | No log output |

A plugin never fails your build unless you set `failOnError`. Without a key or product it warns and skips the upload; errors still arrive, but their stacks stay minified.

> **Don't serve source maps publicly by accident:** Use hidden source maps (`devtool: "hidden-source-map"`, Vite's `"hidden"`) or `deleteAfterUpload: true`. AppHelm only needs the uploaded copy, and a public map exposes your source.

### The CLI

The `apphelm` CLI comes with `@sansavision/apphelm` (Node 20.19 or later). It uses `APPHELM_API_KEY`, or the key saved by `apphelm login`; `--product` falls back to `APPHELM_PRODUCT_ID`.

```bash
# Add debug ids to every built script under ./dist, then upload the maps.
apphelm sourcemaps upload ./dist --product prd_… [--release 2.4.1] [--url-prefix /static] [--delete-after] [--dry-run]

# Only add the debug ids (edits files in place). Still needs a key.
apphelm sourcemaps inject ./dist

# One bundle that isn't a .js file (React Native's index.android.bundle or main.jsbundle):
apphelm sourcemaps upload --bundle index.android.bundle --sourcemap index.android.bundle.map --release "$RELEASE" --product prd_…

# Why an error's frames were or weren't mapped:
apphelm sourcemaps explain <event id> --product prd_…
```

- `upload <dir>` skips `node_modules` and files without a map. A file's map is the target of its `sourceMappingURL` comment, else `<file>.map`. It exits with an error when no map was uploaded.
- `--bundle` needs the map to be JSON with `"version": 3`. It uses the map's own `debugId` if it has one; otherwise it needs `--release`.
- The pre-0.8.0 form `apphelm sourcemaps <prd_…> <release> <dir> [url-prefix]` still works. It uploads every `*.js.map` by release and file name, without debug ids.

### Upload through the API

```bash
curl -X POST https://apphelm.dev/api/v1/sourcemaps \
  -H "Authorization: Bearer $APPHELM_API_KEY" -H "Content-Type: application/json" \
  --data "{\"productId\":\"prd_…\",\"release\":\"web@2.4.1\",\"file\":\"/assets/app.js\",\"sourceMap\":$(cat dist/assets/app.js.map)}"
```

The body takes `productId`, `file` (the served path, up to 500 characters), `release` (up to 120) and/or `debugId` (a UUID), and `sourceMap` (a version 3 map, as a string or an object). The map's own `debugId` is read when you don't send one. It answers `201` with the stored map's id, size and debug id.

## React Native

React Native bundles get no debug ids. Their maps match by **release and bundle name**, so the release you upload with must equal the `release` you pass to `createReactNativeSdk`. Upload the Hermes-composed map that React Native's release build writes.

The CLI prints the build steps for you:

```bash
npx apphelm react-native gradle --product prd_…   # a block for android/app/build.gradle
npx apphelm react-native xcode --product prd_…    # a Run Script phase for Xcode
```

- **Android:** after each release variant's `createBundle<Variant>JsAndAssets` task, it uploads `index.android.bundle` with its map; after `minify<Variant>WithR8`, it uploads `mapping.txt`.
- **iOS:** add the phase after **Bundle React Native code and images**, and add `export SOURCEMAP_FILE="$DERIVED_FILE_DIR/main.jsbundle.map"` to that bundle phase. It uploads the bundle's map and then the dSYMs. Debug builds upload nothing unless `APPHELM_UPLOAD_DEBUG` is set.
- Both read `APPHELM_API_KEY`, `APPHELM_PRODUCT_ID`, `APPHELM_RELEASE` and `APPHELM_CLI` (default `node_modules/.bin/apphelm`). Put the key in `ios/.xcode.env.local`, which isn't committed.
- The default release is `applicationId@versionName+versionCode` on Android and `bundleId@MARKETING_VERSION+CURRENT_PROJECT_VERSION` on iOS. Pass the same string to `createReactNativeSdk`, or set `APPHELM_RELEASE` for both.
- A failed upload prints the reason and never fails the build.

Hermes frames such as `address at index.android.bundle:1:1234` match the uploaded `/index.android.bundle`. Function names come from the map's `names`.

## iOS and macOS: dSYMs

Build Release with **Debug Information Format** set to **DWARF with dSYM File**, then upload the dSYMs:

```bash
apphelm debug-files upload "$DWARF_DSYM_FOLDER_PATH" --product prd_…
# or one dSYM, or an archive's dSYMs folder:
apphelm debug-files upload MyApp.xcarchive/dSYMs --product prd_…
```

The path can be a `.dSYM` folder, the Mach-O file inside its `Contents/Resources/DWARF`, or a folder searched for dSYMs. Every architecture is read. AppHelm stores the symbol table and the DWARF line tables (with inlined calls), so frames show the function, file and line. Swift names are demangled on the server.

- **Matching** is by the image UUID the Swift SDK sends with each crash. `--release` is ignored for dSYMs.
- A `.zip` isn't accepted; unzip it first.
- A stripped binary is refused ("has no symbol table"): upload the dSYM, not the app binary.
- For an Xcode build phase, run the same command in a Run Script phase after the build, with `APPHELM_API_KEY` from a file that isn't committed.

`packages/ios/Scripts/apphelm-symbols.sh` is an older alternative that uploads function names without line tables. Prefer `debug-files upload`.

## Android

### ProGuard and R8 mappings

A minified build reports `a.b.c.a(SourceFile:4)`. Upload the build's `mapping.txt` for the release your app sends. With the Android SDK, the release defaults to `versionName+versionCode` (for example `2.4.1+87`).

```bash
apphelm debug-files upload app/build/outputs/mapping/release/mapping.txt --type proguard --release "2.4.1+87" --product prd_…
```

```bash
# The same with curl (release URL-encoded):
curl --fail -X POST --data-binary @app/build/outputs/mapping/release/mapping.txt \
  -H "Authorization: Bearer $APPHELM_API_KEY" -H "Content-Type: text/plain" \
  "https://apphelm.dev/api/v1/symbols?productId=prd_…&type=proguard&release=2.4.1%2B87"
```

- `--release` must be exactly the release the app sends. If two builds share a release, set the SDK's `build` (the version code by default) and upload each mapping with `--build <versionCode>` (`&build=` in the API); a mapping for the event's build wins over the release's general one.
- Apps on Sentry's Android SDK report a ProGuard UUID instead. Upload with `--uuid <uuid>`, or `--sentry-uuid` to compute the UUID sentry-cli would.
- Without `--release` or `--uuid` the upload is refused.
- **Upload before the build ships.** Android events are also retraced when they arrive (the first 12 frames), so they group on the original names. Events that arrive before the mapping group on obfuscated frames.
- Keep line numbers in the build (`-keepattributes SourceFile,LineNumberTable`) for exact frames.

There is no AppHelm Gradle plugin; run the command in CI, or use the block `apphelm react-native gradle` prints as a template.

### NDK libraries

AppHelm doesn't read ELF files directly. Run Breakpad's `dump_syms` on each **unstripped** `.so`, then upload the `.sym`:

```bash
dump_syms --inlines path/to/unstripped/arm64-v8a/libnative.so > libnative.so.sym
apphelm debug-files upload libnative.so.sym --product prd_…
```

`apphelm debug-files check libnative.so` prints the ELF build id and the Breakpad id it becomes, so you can confirm a crash and a symbol file match.

## Native, desktop and Electron: Breakpad symbols

Minidumps from Crashpad, Breakpad and Electron, and Android NDK crashes, are symbolicated with Breakpad `.sym` files. Upload one file or a folder (up to 500 `.sym` files):

```bash
apphelm debug-files upload ./symbols --product prd_…
```

Files are keyed by the `MODULE` line's debug id; `--release` is only a label. Each `.sym` is up to 64 MB. Upload symbols **with each build, before its crashes**: a minidump's threads are unwound on arrival using the `STACK CFI` records of the files already uploaded, and a dump that arrived first isn't unwound again. Function names and lines are added whenever you view the issue. See [Crashes, ANRs and app hangs](https://apphelm.dev/docs/mobile-crashes#desktop-and-electron-minidumps).

Windows PDBs and ELF binaries can't be uploaded directly; convert them with `dump_syms` first.

## Flutter

AppHelm can't symbolicate Dart AOT frames, and there is no upload for `--split-debug-info` or `--obfuscate` symbol files. Don't obfuscate builds whose stacks you need to read. Native crashes captured by `apphelm_flutter_native` use the iOS and Android uploads above, but Dart frames inside a native stack stay as addresses in `App.framework` or `libapp.so`.

## Using sentry-cli

sentry-cli 3.x works against AppHelm for uploads and releases (tested with 3.8.2). Point it at AppHelm with an AppHelm server key:

```bash
export SENTRY_URL=https://apphelm.dev
export SENTRY_AUTH_TOKEN=ahl_live_…   # an AppHelm server key with events:write
export SENTRY_ORG=any-name            # the workspace comes from the key
export SENTRY_PROJECT=prd_…           # or the product's project number or slug

sentry-cli sourcemaps inject ./dist
sentry-cli sourcemaps upload --release 2.4.1 ./dist
sentry-cli debug-files upload MyApp.dSYM
sentry-cli upload-proguard app/build/outputs/mapping/release/mapping.txt
```

| Command | Works | Notes |
| --- | --- | --- |
| `sourcemaps inject`, `sourcemaps upload` | Yes | Artifact bundles up to 48 MiB. Maps without a debug id or a release are refused. `--dist` is accepted and ignored |
| `debug-files upload` | dSYMs, Breakpad `.sym`, ProGuard | ELF, PDB and source bundles are refused; convert with `dump_syms` |
| `upload-proguard` | Yes | Stored under the ProGuard UUID |
| `releases …`, `deploys new` | Yes | See [Releases and release health](https://apphelm.dev/docs/release-health) |
| `releases files …` (legacy release files) | No | Use `sourcemaps upload` |

Sentry's bundler plugins (`@sentry/vite-plugin` and others) inject debug ids that AppHelm honours. Their uploads go through the same endpoints as sentry-cli, but no plugin version is tested; prefer AppHelm's plugins.

## Check that symbols work

### Before you upload: `debug-files check`

```bash
apphelm debug-files check MyApp.dSYM mapping.txt libnative.so
```

It runs locally, needs no key, and prints what each file is, its debug ids (one per architecture) and whether AppHelm can use it:

```
MyApp.dSYM/Contents/Resources/DWARF/MyApp
  Type:     dSYM (Mach-O with DWARF)
  arm64:    5D1E…-…
  Usable:   yes. …
```

It exits with code 1 when a file isn't usable, and says what to do: upload the `.dSYM` instead of a Mach-O without debug info, or run `dump_syms` on an ELF or PDB. Add `--json` for scripts.

### After an error: `sourcemaps explain`

```bash
apphelm sourcemaps explain 8c1f… --product prd_…
```

Give it the event id (AppHelm's or the one the SDK returned; events up to 90 days old). It needs a key with `issues:read`. For each file in the stack (up to 10) it prints whether a map matched, by debug id or by release and path, how many frames were mapped, and what to fix. The same answer is at `GET /api/v1/sourcemaps/explain?eventId=…&productId=…`.

| Reason | What to do |
| --- | --- |
| `no_release_or_debug_id` | Set `release` in the SDK, or upload with debug ids |
| `debug_id_not_uploaded` | The built file has a debug id but its map wasn't uploaded. Upload the output of the build you deployed |
| `release_has_no_maps` | Nothing was uploaded for this release. Check the `--release` value matches the SDK's |
| `file_not_uploaded` | The path in the stack doesn't match an uploaded path. Fix `--url-prefix` |
| `ambiguous_file_name` | Several maps share the file name and no path matched. Fix `--url-prefix`, or use debug ids |
| `map_too_large`, `map_invalid` | The map is over 8 MB or isn't a version 3 map. Split the bundle, or rebuild the map |
| `position_not_in_map` | The map doesn't cover the frame's position. It's from a different build: upload the deployed build's maps |
| `view_limit` | Only the first 5 files of a stack are mapped. The rest show as sent |

For JVM, Apple and native stacks it names the file type to upload instead.

### In the issue

Open the issue: each frame is marked mapped, missing or unchanged, and a missing native frame names the image and UUID (or the release, for Android) that needs symbols.

## Manage uploaded files

| Method | Path | Scope | Does |
| --- | --- | --- | --- |
| `POST` | `/api/v1/sourcemaps` | `events:write` | Upload one source map |
| `GET` | `/api/v1/sourcemaps/explain` | `issues:read` | Explain an event's mapping |
| `POST` | `/api/v1/symbols?productId=&type=proguard\|apple\|breakpad&release=&build=` | `events:write` | Upload a symbol file as the request body |
| `GET` | `/api/v1/symbols?productId=` | `events:write` | List symbol files and usage |
| `DELETE` | `/api/v1/symbols/{id}` | `events:write` | Delete one symbol file |

Source maps can't be listed or deleted through the API; they expire on their own. Uploading a map again for the same release and path replaces it.

## Limits and retention

| | Source maps | Symbol files (dSYM, ProGuard, Breakpad) |
| --- | --- | --- |
| Per file | 8 MB | ProGuard 32 MB, Breakpad 64 MB, Apple symbol table 16 MB |
| Count | 500 per release, 2,000 per product | 200 per product |
| Total size | 250 MB per product | 1 GB per product |
| Uploads | 600 an hour per product | 60 an hour per product |
| Kept for | 90 days from upload | 365 days from upload |

- Retention counts from the upload. Using a file doesn't extend it; uploading it again does.
- Over a limit, the upload is refused: `409 release_file_limit`, `product_file_limit` or `product_byte_limit`, or `429 upload_rate_limited`. Delete old symbol files, or wait an hour.
- sentry-cli chunks are kept for one day, with up to 5,000 chunks or 8 GiB per workspace a day.

## Best practices

- **Upload in CI for every production build**, from the exact output you deploy. A map from another build maps to the wrong lines.
- **Prefer debug ids.** They match even when the release is missing or wrong, and survive CDN paths.
- **Set the same release in the SDK and the upload**, especially for React Native and Android, which match by release.
- **Keep maps off your public site** with hidden source maps or `deleteAfterUpload`.
- **Check files before uploading** with `apphelm debug-files check`, and keep `apphelm sourcemaps explain` for the first error from a new pipeline.

## Troubleshooting

| Symptom | Likely cause | What to do |
| --- | --- | --- |
| Frames stay minified | No map for that build, or a path mismatch | Run `apphelm sourcemaps explain <event id>` and follow its reason |
| `[apphelm] warning: … skipped` in the build log | No key or product in the build environment | Set `APPHELM_API_KEY` and `APPHELM_PRODUCT_ID` in CI |
| Upload answers 401 | The key is wrong or revoked | Create a new server key |
| Upload answers 403 | The key lacks `events:write` or this product | Use a server key with `events:write` scoped to the product |
| Upload answers 429 | Over 600 map uploads (60 symbol uploads) an hour | Wait an hour, or upload fewer files per build |
| React Native frames aren't mapped | The upload's release differs from `createReactNativeSdk`'s | Use one `APPHELM_RELEASE` for both |
| iOS frames show `image + offset` | The dSYM for that build's UUID wasn't uploaded | Upload the archive's dSYMs; check UUIDs with `apphelm debug-files check` |
| "has no symbol table" | You uploaded the stripped app binary | Upload the `.dSYM` |
| Android stacks stay obfuscated | The mapping's release doesn't match | Upload with the exact release the app sends (`versionName+versionCode` by default) |
| Native crash frames show `module 0x… + offset` | No `.sym` for that module, or it arrived after the dump | Upload `dump_syms` output of the unstripped build before the next release |
