Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/landing/src/content/docs/errors/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The message is the span's status message, or the exception's own message when th

The environment is not part of the fingerprint, so the same bug in staging and production is one issue.

Minified browser code renames functions and files on every deploy. Upload [source maps](/docs/errors/source-maps) so stacks show your original code and browser errors group on it.

### Set the grouping yourself

When the automatic grouping splits one bug into several issues, or merges two, set a `maple.fingerprint` attribute on the error span or on its exception event. Every error in a service that carries the same value becomes one issue, whatever its stack or message. The type, message and stack still show on the issue as usual.
Expand Down Expand Up @@ -223,6 +225,7 @@ The [MCP server](/docs/reference/mcp) covers the whole workflow:
## Next steps

- [Traces](/docs/explore/traces): inspect the requests behind an occurrence.
- [Source maps](/docs/errors/source-maps): readable stacks for minified browser code.
- [Notification destinations](/docs/alerting/notification-destinations): set up Slack, email, and webhooks.
- [GitHub](/docs/integrations/github): attach pull requests and verify fixes.
- [MCP server](/docs/reference/mcp): let a coding agent triage and fix issues.
172 changes: 172 additions & 0 deletions apps/landing/src/content/docs/errors/source-maps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
---
title: "Source maps"
description: "Upload your JavaScript source maps so browser error stacks show your original files, functions and code, and so one bug stays one issue across deploys."
group: "Errors"
order: 2
---

<section class="docs-banner" aria-labelledby="why-source-maps">
<p class="docs-banner-eyebrow" id="why-source-maps">Why upload source maps</p>
<ul class="docs-banner-points">
<li><strong>Read the code that broke.</strong> Each frame shows your original file, function and line, with the code around it, instead of <code>Kc</code> at <code>index-Bx81.js:1:48213</code>.</li>
<li><strong>One bug stays one issue.</strong> Bundlers rename functions and hash file names on every deploy. With maps, Maple groups on your source, so a release does not reopen the same bug as a new issue.</li>
<li><strong>Less noise.</strong> Library frames fold away, so the frames you own come first.</li>
</ul>
<figure class="docs-banner-shot">
<figcaption>What the browser sends</figcaption>
<img src="/screenshots/docs/source-maps-01-raw.webp" alt="A raw browser stack trace: TypeError: Cannot read properties of undefined (reading 'plan'), at Kc, Object.renew, Ln, Pn, Hn and Wd in minified files index-Bx81.js and vendor-9d2c.js, at line 1 or 2 and five-digit columns." width="694" height="206" loading="lazy" />
</figure>
<figure class="docs-banner-shot">
<figcaption>What Maple shows with source maps</figcaption>
<img src="/screenshots/docs/source-maps-02-mapped.webp" alt="The same stack trace on a Maple issue page, marked Source mapped: resolvePlan in src/billing/plan.ts line 47 is open on its code with the failing line highlighted, followed by SubscriptionService.renew, 3 folded library frames and handleRenewal." width="692" height="423" loading="lazy" />
</figure>
</section>

A minified browser bundle reports errors from files like `assets/index-Bx81.js` at line 1, column 48213, inside a function called `Kc`. Upload the build's source maps and Maple maps each stack frame back to your original file, function, line and column, and shows the code around it on the issue page.

Maps are read when an issue is shown, never served to your users, and never applied to the stored error: the raw stack is kept as sent.

## How a frame finds its map

Maple matches each frame to an uploaded map in one of two ways:

- **By debug id** (recommended). `maple sourcemaps inject` writes a unique id into each built JS file and its map. When the file runs, it registers that id, and [`@maple-dev/browser`](/docs/frontend) 0.17.0 or later sends the ids of the scripts in an error's stack as `maple.exception.debug_ids` on the exception event. Maple then picks the map by id, whatever URL the file was served from. Ids written by Sentry's debug id tooling work too.
- **By release and path**. A map uploaded with a service and release is matched to frames from that `service.name` and `service.version` whose URL path ends with the map's file path. `assets/app.js` matches `https://cdn.example.com/static/assets/app.js`, but `app.js` does not match `assets/myapp.js`. Use this when your telemetry reports no debug ids.

Release matching needs `service.version` on your telemetry to equal the release you upload under. The CLI defaults the release to the build's git commit, so either set `service.version` to that commit or pass the same value to both.

## Upload with the CLI

Use the [Maple CLI](/docs/reference/cli) 0.6.0 or later in your CI, after the build and before the deploy.

1. Build with source maps on. With Vite, set `build.sourcemap: "hidden"` so no public `sourceMappingURL` comment is written. Other bundlers have an equivalent setting.
2. Inject debug ids into the build output:

```bash
maple sourcemaps inject dist
```

Every JS file that has a map gets a debug id, derived from the file and its map, so re-running changes nothing. Add `--dry-run` to see what would change.

3. Upload the maps:

```bash
maple sourcemaps upload dist --service web
```

4. Deploy `dist` as usual. Delete the `.map` files from it first if you do not want them served.

`upload` needs a signed-in workspace: run `maple auth login`, or set `MAPLE_API_URL` and `MAPLE_API_TOKEN` in CI. The token is an API key with the **Source maps** write scope, created by an engineer or admin under **Settings → Keys**.

| Flag | What it does |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--service` | The `service.name` your app reports. Needed for maps without a debug id. |
| `--release` | The `service.version` your app reports. Defaults to `git rev-parse HEAD` in the build directory when `--service` is set. |
| `--url-prefix` | The path the files are served under, prepended to each file's path in the build directory. Set it when `dist/app.js` is served as `/static/app.js`. |

The command uploads one map per JS file, four at a time, and prints each one. It skips a map with a warning when it is over 10 MiB, when it is an index map (one with `sections`), when it lives outside the build directory, or when it has no debug id and no `--service` and `--release` were given. A run that uploads nothing, or where any upload fails, exits non-zero so CI stops.

## Upload with Alchemy

If you deploy with [Alchemy](/docs/iac/alchemy), `@maple-dev/alchemy` 0.8.0 or later does both steps for a Vite app. The Vite plugin turns on hidden source maps, injects debug ids, and moves the maps out of the deployed output into `.maple/sourcemaps/<name of the build's output folder>` beside your Vite config, so they are never served:

```ts
// vite.config.ts
import { mapleSourceMaps } from "@maple-dev/alchemy/vite"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
import { defineConfig } from "vite"

export default defineConfig({ plugins: [mapleSourceMaps()] })
```

The `Maple.SourceMaps` resource uploads them after the build:

```ts
// alchemy.run.ts
Effect.gen(function* () {
const web = yield* Cloudflare.Website.Vite("web")
yield* Maple.SourceMaps("web-sourcemaps", {
// This Website builds to dist/client. A plain Vite build uses .maple/sourcemaps/dist.
dir: ".maple/sourcemaps/client",
Comment thread
Makisuo marked this conversation as resolved.
Resolved
service: "web",
release: process.env.GITHUB_SHA,
after: web.hash,
})
})
```

| Prop | What it does |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `dir` | The plugin's maps directory, or any build output where each JS file has its map beside it. |
| `service` | The `service.name` your app reports. |
| `release` | The `service.version` your app reports. Required with `matchBy: "release"`. |
| `urlPrefix` | The path the files are served under, such as `static/`. |
| `after` | Any value from the build, such as the Website's `hash`. It orders the upload after the build and re-checks the maps when it changes. |
| `matchBy` | `"debugId"` (default) for `@maple-dev/browser`. `"release"` uploads without debug ids, for telemetry that reports none. |

The resource uploads again only when the maps or its props change. Deleting it deletes no maps, because earlier releases still need them.

The plugin options are `mapsDir`, where the maps go, and `environments`, the Vite environments to process (default `["client"]`, the browser bundle). The plugin runs in Node and needs `@effect/platform-node`.

On the first deploy with the plugin, a chunk whose hashed name did not change gets new contents, because the debug id goes in after Rollup names the file. A browser or CDN that cached that chunk may serve the old copy for that one release. Later builds are deterministic.

## Upload with the API

`POST /v2/source_maps` takes one map as the raw request body (`application/json` or `application/octet-stream`). Identify it with query parameters:

| Parameter | Required | Meaning |
| --------------- | --------------------------------------- | -------------------------------------------------- |
| `minified_path` | Yes | The JS file's path relative to the deploy root. |
| `debug_id` | Either this, or `service` and `version` | The debug id written into the JS file and its map. |
| `service` | | The `service.name`. |
| `version` | | The `service.version`. |

```bash
curl -X POST "https://api.maple.dev/v2/source_maps?minified_path=assets/index-Bx81.js&service=web&version=1.4.2" \
-H "Authorization: Bearer $MAPLE_API_TOKEN" \
-H "Content-Type: application/json" \
--data-binary @dist/assets/index-Bx81.js.map
```

- A map must be a version 3 source map with a non-empty `sources` array. Index maps (`sections`) are refused with a 400; emit a regular map.
- Maps over 10 MiB are refused with a 413, the largest map Maple can symbolicate with.
- Uploading a map with the same debug id replaces it. Uploading a map without a debug id for the same service, version and path replaces it too.

`GET /v2/source_maps` lists your maps, filtered by `service`, `version` or `debug_id`. `DELETE /v2/source_maps/{id}` deletes one. Any member can list; uploading and deleting take an engineer or admin and the `source_maps:write` scope. See the [API reference](/docs/reference/api).

## On the issue page

The **Stack trace** on an issue's **Overview** shows the mapped frames, top of the stack first, under a **Source mapped** marker, or **Partly source mapped** when only some frames found a map. Your own frames open on the code around the line when the map embeds `sourcesContent`. Runs of library frames fold into one row. **Raw** switches to the stack exactly as it was sent.

Frames count as library code when their original path is under `node_modules/`, is webpack runtime code, a browser extension or `<anonymous>`, or when the map's `ignoreList` marks their source.

## Grouping on mapped frames

When an organization has source maps, a browser error that groups on its stack frames uses the mapped frames: each in-app frame's original file and function, never a line or column, so a fix elsewhere in the file does not split the issue. A frame with no recovered function name uses its file plus the text of its original source line. A stack that maps nothing groups as before, and [`maple.fingerprint`](/docs/errors/overview#set-the-grouping-yourself) and your organization's grouping rules still come first.

- The first map your organization uploads re-groups its browser errors once, as they recur. Issues that deploys had split can then join one issue.
- An error whose stack carries a debug id waits up to 1 hour from its first sighting for its map before it is grouped. Upload maps in the same pipeline step as the deploy, so they arrive before the first error.
- A map uploaded later than that does not re-group errors already grouped on the raw stack.

## Retention and limits

| Limit | Value |
| ---------------------- | --------------------------------------------------------- |
| Largest map | 10 MiB |
| Map formats | Version 3 regular maps. Index maps are not supported. |
| Retention | A map not used to resolve a stack for 90 days is deleted. |
| Uploading and deleting | Engineers and admins |

The API returns when each map last resolved a stack, to the day, as `last_used_at`.

## Troubleshooting

- **Stacks still show minified code.** Check that the maps uploaded (`GET /v2/source_maps`). With debug ids, check that `inject` ran on the same files you deployed, after any step that rewrites them, and that your app uses `@maple-dev/browser` 0.17.0 or later. Without debug ids, check that `service.version` on the errors equals the uploaded release, and that the uploaded path is the end of the URL path (set `--url-prefix`).
- **Frames map but show no code.** The map has no `sourcesContent`. Turn on embedding the sources in your bundler.
- **`upload` skips every file with "no debug id".** Run `maple sourcemaps inject` first, or pass `--service` and `--release`.
- **An error opened a new issue after a deploy.** Its map arrived more than an hour after the first occurrence. Upload before or with the deploy.

## Next steps

- [Errors and issues](/docs/errors/overview): how issues are grouped and worked.
- [Frontend](/docs/frontend): set up `@maple-dev/browser`.
- [CLI reference](/docs/reference/cli#maple-sourcemaps-inject-dir): every `maple sourcemaps` flag.
15 changes: 15 additions & 0 deletions apps/landing/src/content/docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ New here? Start with the [Maple Local](/docs/local-mode) walkthrough, or [use th
| [`maple services`](#maple-services) · [`diagnose`](#maple-diagnose-service-name) · [`service-map`](#maple-service-map) · [`top-ops`](#maple-top-ops-service-name) | Services, their health, dependencies and hottest operations |
| [`maple traces`](#maple-traces) · [`trace`](#maple-trace-trace-id) · [`slow-traces`](#maple-slow-traces) | Search spans, inspect one trace, find the slowest |
| [`maple errors`](#maple-errors) · [`error`](#maple-error-fingerprint-hash) | Error groups by fingerprint, and one group in detail |
| [`maple sourcemaps inject`](#maple-sourcemaps-inject-dir) · [`upload`](#maple-sourcemaps-upload-dir) | Add debug ids to a build, upload its source maps |
| [`maple logs`](#maple-logs) · [`log-patterns`](#maple-log-patterns) · [`log-diff`](#maple-log-diff) | Search logs, or cluster them into templates |
| [`maple attributes keys`](#maple-attributes-keys) · [`values`](#maple-attributes-values-key) | Discover attribute keys and their values |
| [`maple metrics`](#maple-metrics) · [`metrics show`](#maple-metrics-show-metric-name) · [`query`](#maple-query-sql) | List metrics, read one over time, run read-only SQL |
Expand Down Expand Up @@ -276,6 +277,20 @@ One error group in detail: sample traces and a timeseries.
- **`<fingerprint-hash>`**: the fingerprint from `maple errors`
- Flags: `--since` / `--start` / `--end`, `--service`, `--limit`

### `maple sourcemaps inject <dir>`

Gives every built JS file under `<dir>` that has a source map a debug id, and writes it into the map. Run it after the build, before deploying and uploading; re-running changes nothing. Maps outside `<dir>` are never touched.

- Flags: `--dry-run` reports what would change without writing

### `maple sourcemaps upload <dir>`

Uploads every source map under `<dir>` whose JS file is there too, so error stacks show original source. Needs a signed-in workspace (remote mode). Skips maps over 10 MiB and index maps; exits non-zero when nothing uploads or an upload fails. See [Source maps](/docs/errors/source-maps).

- `--service`: the `service.name` the maps belong to
- `--release`: the `service.version`; defaults to the directory's git commit when `--service` is set
- `--url-prefix`: the path the files are served under, prepended to each file path, e.g. `assets/`

## Logs

### `maple logs`
Expand Down
30 changes: 30 additions & 0 deletions apps/landing/src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,36 @@
@apply mb-0;
}

/* A page-opening panel: why the feature matters, with product shots under it. */
.docs-content .docs-banner {
@apply border border-border rounded-xl p-5 my-6;
background: color-mix(in oklab, var(--bg-elevated) 55%, transparent);
}

.docs-content .docs-banner-eyebrow {
@apply mt-0 mb-3 text-sm font-medium text-primary;
}

.docs-content .docs-banner-points {
@apply my-0 pl-5 text-sm;
}

.docs-content .docs-banner-points li {
@apply my-1.5;
}

.docs-content figure.docs-banner-shot {
@apply mt-5 mb-0;
}

.docs-content figure.docs-banner-shot figcaption {
@apply mb-2 text-xs text-fg-muted;
}

.docs-content figure.docs-banner-shot img {
@apply w-full h-auto aspect-auto object-contain border border-border rounded-lg my-0 bg-bg-deep;
}

.docs-content hr {
@apply border-border my-8;
}
Expand Down