Skip to Content
KubeSense

Source Maps for Browser Errors

Upload each release's JavaScript source maps from CI so browser error stacks show your original files, lines and function names instead of minified code.

Production JavaScript is bundled and minified, so the stack of a browser error points at a column of a one-line file:

RangeError: invalid quantity 0 for sku-2
  at t @ https://shop.example.com/assets/checkout.min.js:1:92
  at e @ https://shop.example.com/assets/checkout.min.js:1:36

Upload the source maps your bundler writes for each release, and KubeSense shows the same error in your source:

RangeError: invalid quantity 0 for sku-2
  at lineTotal @ ../src/pricing.ts:9:15
  at orderTotal @ ../src/pricing.ts:4:16

Your source maps never have to be public. You upload them from CI and can delete them before you deploy; KubeSense never fetches anything from your site.

Before you start

You need:

  • service and version set in the RUM SDK. A map is chosen by the error's service and version, so an error without a version can never be resolved. Set both in init() (see Browser Integration), and change version with every release.
  • An ingestion token. Create one in Settings → Ingestion Tokens. Do not use your RUM application's client token: it ships inside your public JavaScript, so KubeSense refuses it for uploads.
  • Your RUM intake URL: https:// followed by the host you set as kubesenseRumEndpoint, for example https://app.kubesense.ai.
  • Node.js 18.3 or later on the CI runner, for npx @kubesense/kubesense-ci.

1. Build hidden source maps

Have your bundler write .map files without the //# sourceMappingURL= comment, so browsers never ask for them:

BundlerSetting
Vitebuild: { sourcemap: 'hidden' }
webpackdevtool: 'hidden-source-map'
Rollupoutput: { sourcemap: 'hidden' }
esbuild--sourcemap=external
Next.jsproductionBrowserSourceMaps: true (delete the maps after uploading, below)

Each map must sit next to the file it maps: checkout.min.js.map beside checkout.min.js.

2. Upload them in CI

Run the KubeSense CLI after the build and before the deploy:

export KUBESENSE_API_KEY=<ingestion token>
export KUBESENSE_SOURCEMAP_INTAKE_URL=https://app.kubesense.ai

npx @kubesense/kubesense-ci sourcemaps upload ./dist \
  --service=web-shop \
  --release-version="$APP_VERSION" \
  --minified-path-prefix=/ \
  --delete-maps

Each file's URL is the prefix followed by its path below the uploaded directory. Vite writes dist/assets/index-abc.js, served at /assets/index-abc.js, so ./dist takes the prefix /. Run once with --dry-run to print the URLs, and check them against the .js URLs in your error stacks.

OptionWhat it is
--serviceThe service your RUM SDK reports
--release-versionThe version your RUM SDK reports for this build
--minified-path-prefixWhere the uploaded directory is served from: a path (/, /static/) or a URL (https://cdn.example.com/). Only the path is compared, so the same bundle served from a CDN and from your own domain both match.
--delete-mapsDelete each .map once it is uploaded, so it is never deployed. A map that is not uploaded (its upload failed, or no .js file sits beside it) is kept and fails the run, so the deploy after it does not ship it. Stylesheet maps (.css.map) are neither uploaded nor deleted.
--dry-runList the maps that would be uploaded, upload nothing. With --delete-maps it fails, as the real run would, when a map could not be uploaded.
--repository-url, --commit-shaRead from git by default. --disable-git stops reading git; values you pass are still sent.
--intake-urlThe RUM intake URL, instead of KUBESENSE_SOURCEMAP_INTAKE_URL
--max-concurrencyUploads at once (default 4)
--quietPrint only failures and the summary

--service and --release-version must equal what the SDK reports, or no error will ever match a map. The command exits non-zero if any map failed to upload, or if it found none.

If the collector's certificate comes from a private CA, set NODE_EXTRA_CA_CERTS to the CA file.

A GitHub Actions step:

- name: Upload source maps
  env:
    KUBESENSE_API_KEY: ${{ secrets.KUBESENSE_INGESTION_TOKEN }}
    KUBESENSE_SOURCEMAP_INTAKE_URL: https://app.kubesense.ai
  run: >
    npx @kubesense/kubesense-ci sourcemaps upload ./dist
    --service=web-shop
    --release-version=${{ github.sha }}
    --minified-path-prefix=/
    --delete-maps

Upload before you deploy. An error is resolved as it arrives, with the maps uploaded by then. One that arrived before its map is stored minified, and is resolved when you open it in the error drawer or an issue's samples, if the map has been uploaded since. Lists, search and alerts show the stack as it was stored.

Already using datadog-ci?

KubeSense also accepts uploads from datadog-ci sourcemaps upload. Point it at your intake and set DATADOG_SITE to a host that cannot resolve:

export DATADOG_API_KEY=<ingestion token>
export DATADOG_SOURCEMAP_INTAKE_URL=https://app.kubesense.ai   # base URL only
export DATADOG_SITE=kubesense.invalid

datadog-ci sends its own usage metrics, with the API key, to api.<DATADOG_SITE> on every run. With DATADOG_SITE=kubesense.invalid that request cannot leave your CI, and it only prints a warning; without it, your KubeSense token is sent to Datadog.

3. See the resolved stack

Open an error in RUM → Sessions Explorer, or an issue's stack trace. The stack is shown source-mapped; Minified switches to the stack exactly as the browser sent it.

When a stack stays minified, a note under it says why:

NoteWhat to do
No source map was uploaded for this service and versionCheck --service and --release-version match the SDK, and that the upload ran for this build
The source maps uploaded for this version do not match this bundleThe maps came from a different build than the one deployed. Upload from the same build output you deploy
The error has no versionSet version in the RUM SDK
The source maps could not be read when this error arrivedTemporary; open the error again
Some frames have no source mapThose frames come from a file you did not upload, often a third-party script

Microfrontends: each build's service and version

When one page loads code from several builds -- a shell app and microfrontends, each deployed with its own service and version -- every event would otherwise carry the service and version the RUM SDK was initialised with. An error thrown in the checkout microfrontend would then be looked up against the shell's source maps, and stay minified.

Give each build's files their own service and version in CI, after building it and before uploading its source maps:

npx @kubesense/kubesense-ci source-context inject ./dist \
  --service=checkout-mfe \
  --release-version="$APP_VERSION"

npx @kubesense/kubesense-ci sourcemaps upload ./dist \
  --service=checkout-mfe \
  --release-version="$APP_VERSION" \
  --minified-path-prefix=/checkout/ \
  --delete-maps

Errors, long animation frames, fetches and XHRs, custom actions, views and vitals whose stack starts in that build's code then report its service and version, and its source maps resolve their stacks. Run the same two steps for each build, with its own values.

OptionWhat it is
--serviceThe service for this build's code: the one its source maps are uploaded with
--release-versionThe version for this build's code
--dry-runList the files that would change, change nothing
--quietPrint only the summary, and the files whose source map could not be shifted

How it works:

  • It adds a first line to every .js, .mjs and .cjs file under the directory (after a #! line). The line runs before the file's own code, so an error the file throws while it starts is attributed too. A file whose directive prologue holds "use strict" stays strict.
  • Each file's source map gains the same empty first line, so its mappings stay valid: a map beside the file, one its sourceMappingURL comment names, or an inline one. Inject before uploading the maps, so KubeSense stores the shifted ones.
  • A file whose map cannot be shifted -- the map is not on disk, cannot be read, or belongs to another file too -- gets the line at its end instead, and the run lists it. That file is attributed once it has run, but not for an error it throws while it starts.
  • Running it again updates the line instead of adding another, and never shifts a map twice. A shifted map records the file it was shifted for, in x_kubesense_source_code_context.
  • It changes every JavaScript file under the directory, so point it at what you deploy. Run it before computing subresource integrity hashes, which the change would invalidate. node_modules directories and symbolic links are skipped.
  • Code that a microfrontend framework evaluates in a sandbox with its own window (qiankun and similar) is not attributed.
  • Apps built with Datadog's build plugins (@datadog/webpack-plugin and similar) need no extra step: the RUM SDK reads the context they inject too.

This needs browser SDK 2.0 or later, and a @kubesense/kubesense-ci release with the source-context inject command.

Good to know

  • Each map is kept for 365 days after its last upload. Uploading the same file again for the same version replaces it.
  • A map can be up to 100 MB. If a proxy or ingress sits in front of the RUM intake, it must pass /rum/api/v1/sourcemaps (and /api/v2/srcmap for datadog-ci) and allow request bodies that large; nginx allows 1 MB by default.
  • Maps are stored as uploaded, including sourcesContent (your original source). Your KubeSense administrator can have sourcesContent removed on upload; stacks still resolve.
  • Stacks from Android and iOS apps are not resolved yet.

On this page