# Code links and source maps

Every frame of a stack trace that's your own code gets two buttons: **View on GitHub** (or GitLab, Bitbucket, or **View source** for another host), which opens the file at that line in your repository, at the commit that was live when the error happened, and **Open in VS Code**, which opens the same line on your computer. You'll find them on an issue's page and on any log line with an exception, once you open the line.

For minified browser JavaScript, upload your source maps and the frames show the original file, line and function, with a few lines of the code around it.

## Set up the links

Open the source's **Settings**, then **Code links**:

- **Link template**: an https URL with `{commit}`, `{path}` and `{line}` in it. Leave it empty if you've set a **GitHub repository** on the source's Issues tab: the links then go to `https://github.com/owner/name/blob/{commit}/{path}#L{line}`. For other hosts:

    ```
    https://gitlab.com/acme/shop/-/blob/{commit}/{path}#L{line}
    https://bitbucket.org/acme/shop/src/{commit}/{path}#lines-{line}
    https://github.com/acme/monorepo/blob/{commit}/apps/web/{path}#L{line}
    ```

    `{path}` must be in the template, and no placeholder may sit in the host name.

- **Path prefixes to remove**: the start of a path in your stack traces that isn't part of the repository, one per line, up to 10. If your app runs from `/home/forge/shop.com/`, add that, and `/home/forge/shop.com/app/Models/User.php` links to `app/Models/User.php`. The longest prefix that matches wins. Paths under the usual roots (`/var/www/html/`, `/var/www/`, `/app/`, `/srv/app/`, `/usr/src/app/`, `/opt/app/`, `/var/task/`, `/home/node/app/`, `/code/`, `/workspace/`) work without one, and a relative path is taken as the repository's own.

- **Commit when no deploy matches**: the branch, tag or commit to use when no deploy fits. Empty means `HEAD`, which GitHub, GitLab and Bitbucket read as the default branch.

The card shows a live example of a link while you type.

## Which commit a link opens

A link opens the file at the commit of the **last deploy recorded for the source at or before the error**, so a line number from last Tuesday's error points at last Tuesday's code. Record deploys from CI with their commit (see [Deploys](https://tailcove.dev/docs/api/deploys)):

```bash
curl -X POST https://tailcove.dev/api/v1/sources/$TAILCOVE_SOURCE_ID/deploys \
  -H "Authorization: Bearer $TAILCOVE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"version\": \"$GITHUB_REF_NAME\", \"commit_sha\": \"$GITHUB_SHA\"}"
```

With no deploy before the error, or none with a `commit_sha`, the links use the source's default ref. The line under the trace says which one you're looking at.

## Which frames get links

Only your own code: frames in `vendor/`, `node_modules/`, `site-packages/` and `dist-packages/`, the runtime's own frames (`node:internal/...`, PHP's `[internal function]`, `<frozen ...>`), frames an SDK marked as not in-app, and minified browser frames that no source map resolves get none. Library frames still fold behind a toggle, as before.

## Open in VS Code

The first time you press **Open in VS Code**, Tailcove asks where the repository is checked out on your computer, such as `/Users/you/code/shop` or `C:\code\shop`. Your browser keeps that folder for the source (it never reaches our servers), and the button then opens `vscode://file/<folder>/<path>:<line>`. To change it, use **Change** under the trace.

The same path settings decide where errors show up in [your editor](https://tailcove.dev/docs/editor).

## Source maps

A browser stack trace from a production build points at minified code, like `app-3f9a1c.js:1:23456`. Upload the build's `.map` files and Tailcove reads them when you look at the error: the frame shows the original file, line and column, the function's original name, and a few lines of the code when the map carries it (`sourcesContent`).

### Upload from CI

With the [`tailcove` CLI](https://tailcove.dev/docs/cli), after the build:

```bash
tailcove sourcemaps upload ./dist/assets --source web --url-prefix https://app.example.com/assets
```

It uploads every `*.js.map` under the folder, each named by the URL its minified file is served from. Or call the API with curl, once per file:

```bash
curl -X POST https://tailcove.dev/api/v1/sources/$TAILCOVE_SOURCE_ID/sourcemaps \
  -H "Authorization: Bearer $TAILCOVE_API_TOKEN" \
  -F url=https://app.example.com/assets/app-3f9a1c.js \
  -F file=@dist/assets/app-3f9a1c.js.map
```

The token needs the **Upload source maps (for CI)** ability (`sourcemaps:write`). The full reference is under [Sources](https://tailcove.dev/docs/api/sources#upload-a-source-map).

### How a frame finds its map

By the **path** of the minified file's URL: a map uploaded for `https://app.example.com/assets/app-3f9a1c.js` serves a frame from `/assets/app-3f9a1c.js` on any host. Vite and webpack put a content hash in each file name, so the path alone names the build and you don't need a release. If you do send `release` (say your files aren't hashed), a map uploaded for the event's release is preferred, and otherwise the newest one for the path is used. Uploading a map for a path (and release) that already has one replaces it.

### What a map needs

- Source map version 3: JSON with `"version": 3`, a `mappings` string and a `sources` list. Index maps (`"sections"`) aren't read; upload the map of each file.
- `names` gives frames their original function names; `sourcesContent` gives the lines of code shown under a frame. Both are optional.
- Paths in `sources` like `webpack://app/./src/cart.ts` or `../../src/cart.ts` become `src/cart.ts` for the link. If yours still carry a folder that isn't in the repository, add it under **Path prefixes to remove**.

### Limits and retention

- A map is at most 25 MB.
- A source holds up to 50 maps on Free, 2,000 on Pro and 10,000 on Business. Past that an upload is refused with `429` until room is made. A replacement doesn't count twice.
- Maps are deleted 90 days after they're uploaded. **Delete all** on the Code links card removes them sooner; deleting the source removes them too.
- Maps are only read when someone looks at an error, never while your logs come in, and each frame's answer is kept for a week, so a busy issue page doesn't read the same map twice.
