Skip to content

πŸ› sourcemaps support is not workingΒ #151

Description

@gre-ledger

Describe the bug

Source maps do not resolve out of the box for an Electron app instrumented with
@datadog/electron-sdk. To get any unminification β€” for renderer (RUM) errors and main-process
errors β€” we had to add non-trivial, fragile runtime stack rewriting on our side.

Handling Electron's asar paths and the main-process V8 stack shape is exactly what we'd expect an
"Electron SDK" to do for us β€” having to hack it in application code defeats the purpose of using a
dedicated Electron SDK. This belongs in the SDK / Datadog ingestion, not in every consumer's codebase.

There are two distinct problems we had to work around:

1. asar paths don't match what Datadog will unminify.
Datadog only unminifies frames shaped as https://{domain}{file}. But an Electron app does not serve
over a domain:

  • the renderer loads from file:///…/app.asar/…
  • the main process reports raw filesystem paths (/Users/…/app.asar/…, often containing spaces)

Neither form is unminified. We had to rewrite both, at runtime in beforeSend, to a fake
https://app.asar/ origin so the frames line up with the uploaded source maps:

// renderer file:// URLs, and main-process raw V8 paths (anchored on "(" / "at " because paths
// can contain spaces). Both rewritten to a fake https://app.asar/ origin.
const ASAR_FILE_URL = /file:\/\/\/?[^\s'"()]*?app\.asar\//g;
const ASAR_RAW_PATH = /(\(|\bat )((?:\/|[A-Za-z]:[\\/])[^()\n]*?)app\.asar\//g;

function rewriteAsarUrls(text) {
  return text
    .replace(ASAR_FILE_URL, "https://app.asar/")
    .replace(ASAR_RAW_PATH, "$1https://app.asar/");
}

working in combination of:


```sh
 npx --yes @datadog/datadog-ci@3 sourcemaps upload "$WEBPACK_DIR" \
    --service "$SERVICE" \
    --release-version "$VERSION" \
    --minified-path-prefix "https://app.asar/.webpack"

**2. Main-process (Node/V8) stacks are templated differently and need an extra remapping.**
The Electron SDK forwards a raw V8 stack (`at {fn} ({url})`, or bare `at {url}`), but Datadog only
unminifies the **Browser-SDK** frame shape (`at {fn} @ {url}:{line}:{col}`). So, on top of the URL
rewrite, for the main process we also had to **reshape every stack frame** into the `@` form:

```js
// reshape each V8 frame "at fn (url)" -> "at fn @ url:line:col" so Datadog will unminify it
function toDatadogStackFrames(stack) {
  return stack.split("\n").map(reshapeStackFrame).join("\n");
}
// (full impl reshapes "at fn (loc)" / bare "at loc" into "at fn @ loc"; "@"-form lines left as-is)

Why this is a problem

  • It depends on undocumented internals (the exact frame shape Datadog unminifies, and the
    https://{domain}{file} matching rule). Any change on Datadog's side breaks remapping silently.
  • The https://app.asar/ origin is fake β€” invented only to satisfy a web-oriented matcher. It must
    be kept in sync between the source-map upload prefix and this runtime rewrite, in two processes.
  • Regex-rewriting V8 stack strings is brittle: paths with spaces, Windows vs POSIX paths, anonymous
    frames, etc.
  • The main process needs a second transformation that the renderer does not β€” clearly SDK-level
    concerns leaking into application code.

RUM side: there is no "Electron" source-map type

Image

On the RUM / Error Tracking side, the source-map / source type only offers "JavaScript", which is
web-oriented and requires a domain. Electron apps have no domain (local file:// / asar assets,
plus a Node/V8 main process), which is exactly why we had to introduce the fake https://app.asar
domain. We would expect a dedicated "Electron" source type that understands asar / file://
paths and main-process V8 stacks natively.

Expected behavior / what we wish for

  • The SDK (and Datadog ingestion) should unminify Electron renderer and main-process stacks out of
    the box β€” no rewriting URLs to a fake domain, no reshaping V8 frames in user code.
  • A first-class "Electron" source-map type (no fake domain required).
  • Parity with React Native, notably the ability to map by platform. Electron ships the same JS
    to macOS / Windows / Linux, where paths and stacks differ per OS; React Native already supports
    per-platform (iOS/Android) source-map mapping, and we'd want the equivalent for Electron. This is an
    Electron-app concept that does not exist for the web ("JavaScript").

Environment

  • @datadog/electron-sdk: 0.3.0 (also relevant on 0.4.0, latest)
  • dd-trace: 5.x
  • @datadog/browser-rum / browser-logs: 6.30.1
  • Electron: 40, macOS/Windows/Linux builds

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions